From b67e0002c19e60e3cfe8c67b22191be179bc4979 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 11 Oct 2021 20:05:13 +0100 Subject: Add `testing.expect_value`; Improve `testing.set_fail_timeout` --- core/testing/testing.odin | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'core/testing/testing.odin') diff --git a/core/testing/testing.odin b/core/testing/testing.odin index 0f91c7020..63df26c1f 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -3,6 +3,7 @@ package testing import "core:fmt" import "core:io" import "core:time" +import "core:intrinsics" // IMPORTANT NOTE: Compiler requires this layout Test_Signature :: proc(^T) @@ -28,8 +29,6 @@ T :: struct { cleanups: [dynamic]Internal_Cleanup, _fail_now: proc() -> !, - _is_done: bool, - _fail_timeout_set: bool, } @@ -89,10 +88,17 @@ expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bo } return ok } +expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) { + ok := value == expected + if !ok { + errorf(t=t, format="expected %v, got %v", args={expected, value}, loc=loc) + } + 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 + assert(global_fail_timeout_thread == nil, "set_fail_timeout previously called", loc) _fail_timeout(t, duration, loc) } \ No newline at end of file -- cgit v1.2.3