diff options
| author | gingerBill <bill@gingerbill.org> | 2021-10-11 15:28:25 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-10-11 15:28:25 +0100 |
| commit | e64eb631dffd244c81d37b7294f1d4b5c36eb4d5 (patch) | |
| tree | 8273e83514ab3a488d17ee9dfb633470622f1eeb /core/testing/testing.odin | |
| parent | 129a62d4f120d5c16c357f11a44d204c58982913 (diff) | |
Add `testing.set_fail_timeout`
Diffstat (limited to 'core/testing/testing.odin')
| -rw-r--r-- | core/testing/testing.odin | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/core/testing/testing.odin b/core/testing/testing.odin index 0d3c1dd43..0f91c7020 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -2,6 +2,7 @@ package testing import "core:fmt" import "core:io" +import "core:time" // IMPORTANT NOTE: Compiler requires this layout Test_Signature :: proc(^T) @@ -27,6 +28,8 @@ T :: struct { cleanups: [dynamic]Internal_Cleanup, _fail_now: proc() -> !, + _is_done: bool, + _fail_timeout_set: bool, } @@ -43,13 +46,18 @@ errorf :: proc(t: ^T, format: string, args: ..any, loc := #caller_location) { t.error_count += 1 } -fail :: proc(t: ^T) { - error(t, "FAIL") +fail :: proc(t: ^T, loc := #caller_location) { + error(t=t, args={"FAIL"}, loc=loc) t.error_count += 1 } -fail_now :: proc(t: ^T) { - fail(t) +fail_now :: proc(t: ^T, msg := "", loc := #caller_location) { + if msg != "" { + error(t=t, args={"FAIL:", msg}, loc=loc) + } else { + error(t=t, args={"FAIL"}, loc=loc) + } + t.error_count += 1 if t._fail_now != nil { t._fail_now() } @@ -81,3 +89,10 @@ expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bo } return ok } + + +set_fail_timeout :: proc(t: ^T, duration: time.Duration, loc := #caller_location) { + assert(t._fail_timeout_set == false, "set_fail_timeout previously called", loc) + t._fail_timeout_set = true + _fail_timeout(t, duration, loc) +}
\ No newline at end of file |