diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-06-15 10:25:58 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-06-15 10:46:47 -0400 |
| commit | 784408358d39346b410df65b9f657007c467a010 (patch) | |
| tree | f3b39a7fa1e68ce0a2689804849a56c9131b2623 /core/testing | |
| parent | 94ec647923e2ba0d89351a55f80b8711c3b68a13 (diff) | |
Call `cleanups` after test signal
Diffstat (limited to 'core/testing')
| -rw-r--r-- | core/testing/runner.odin | 11 | ||||
| -rw-r--r-- | core/testing/testing.odin | 12 |
2 files changed, 20 insertions, 3 deletions
diff --git a/core/testing/runner.odin b/core/testing/runner.odin index 328186c35..147c6d094 100644 --- a/core/testing/runner.odin +++ b/core/testing/runner.odin @@ -604,10 +604,10 @@ runner :: proc(internal_tests: []Internal_Test) -> bool { }) fmt.assertf(alloc_error == nil, "Error appending to log messages: %v", alloc_error) - find_task_data: for &data in task_data_slots { + find_task_data_for_timeout: for &data in task_data_slots { if data.it.pkg == it.pkg && data.it.name == it.name { end_t(&data.t) - break find_task_data + break find_task_data_for_timeout } } } @@ -655,6 +655,13 @@ runner :: proc(internal_tests: []Internal_Test) -> bool { } + find_task_data_for_stop_signal: for &data in task_data_slots { + if data.it.pkg == it.pkg && data.it.name == it.name { + end_t(&data.t) + break find_task_data_for_stop_signal + } + } + when FANCY_OUTPUT { bypass_progress_overwrite = true signals_were_raised = true diff --git a/core/testing/testing.odin b/core/testing/testing.odin index 92b4d391d..07e2063ca 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -94,7 +94,17 @@ logf :: proc(t: ^T, format: string, args: ..any, loc := #caller_location) { // cleanup registers a procedure and user_data, which will be called when the test, and all its subtests, complete. // Cleanup procedures will be called in LIFO (last added, first called) order. -// Each procedure will use a copy of the context at the time of registering. +// +// Each procedure will use a copy of the context at the time of registering, +// and if the test failed due to a timeout, failed assertion, panic, bounds-checking error, +// memory access violation, or any other signal-based fault, this procedure will +// run with greater privilege in the test runner's main thread. +// +// That means that any cleanup procedure absolutely must not fail in the same way, +// or it will take down the entire test runner with it. This is for when you +// need something to run no matter what, if a test failed. +// +// For almost every usual case, `defer` should be preferable and sufficient. cleanup :: proc(t: ^T, procedure: proc(rawptr), user_data: rawptr) { append(&t.cleanups, Internal_Cleanup{procedure, user_data, context}) } |