From 52d38ae42b15311102719d25b6f285c43af701bb Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 1 May 2021 22:54:27 +0100 Subject: Make the core:testing runner on windows run in a separate thread to handle crashes in more safe manner --- core/testing/testing.odin | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'core/testing/testing.odin') diff --git a/core/testing/testing.odin b/core/testing/testing.odin index a431d8575..8a32ce7c8 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -29,12 +29,15 @@ T :: struct { error :: proc(t: ^T, args: ..any, loc := #caller_location) { - log(t=t, args=args, loc=loc); + fmt.wprintf(t.w, "%v: ", loc); + fmt.wprintln(t.w, ..args); t.error_count += 1; } errorf :: proc(t: ^T, format: string, args: ..any, loc := #caller_location) { - logf(t=t, format=format, args=args, loc=loc); + fmt.wprintf(t.w, "%v: ", loc); + fmt.wprintf(t.w, format, ..args); + fmt.wprintln(t.w); t.error_count += 1; } -- cgit v1.2.3 From cf0bf1a7cb395cb334cc456d30af3224fa607ca0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 1 May 2021 23:06:14 +0100 Subject: Add `testing.fail_now` --- core/testing/runner_windows.odin | 6 +++++- core/testing/testing.odin | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'core/testing/testing.odin') diff --git a/core/testing/runner_windows.odin b/core/testing/runner_windows.odin index 4ab24f39c..4b600218a 100644 --- a/core/testing/runner_windows.odin +++ b/core/testing/runner_windows.odin @@ -156,7 +156,7 @@ run_internal_test :: proc(t: ^T, it: Internal_Test) { context.assertion_failure_proc = proc(prefix, message: string, loc: runtime.Source_Code_Location) { errorf(t=global_current_t, format="%s %s", args={prefix, message}, loc=loc); - intrinsics.debug_trap(); + intrinsics.trap(); }; thread.it.p(thread.t); @@ -168,6 +168,10 @@ run_internal_test :: proc(t: ^T, it: Internal_Test) { sema_reset(&global_threaded_runner_semaphore); global_current_t = t; + t._fail_now = proc() -> ! { + intrinsics.trap(); + }; + thread.t = t; thread.it = it; thread.success = false; diff --git a/core/testing/testing.odin b/core/testing/testing.odin index 8a32ce7c8..ec47ca4d4 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -25,6 +25,8 @@ T :: struct { w: io.Writer, cleanups: [dynamic]Internal_Cleanup, + + _fail_now: proc() -> !, } @@ -46,6 +48,13 @@ fail :: proc(t: ^T) { t.error_count += 1; } +fail_now :: proc(t: ^T) { + fail(t); + if t._fail_now != nil { + t._fail_now(); + } +} + failed :: proc(t: ^T) -> bool { return t.error_count != 0; } -- cgit v1.2.3