Add testing.set_fail_timeout

This commit is contained in:
gingerBill
2021-10-11 15:28:25 +01:00
parent 129a62d4f1
commit e64eb631df
3 changed files with 51 additions and 8 deletions
+19 -4
View File
@@ -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)
}