mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 01:21:38 -07:00
Merge branch 'master' into file-tags-without-comments
This commit is contained in:
@@ -204,6 +204,10 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
console_ansi_init()
|
||||
}
|
||||
|
||||
stdout := io.to_writer(os.stream_from_handle(os.stdout))
|
||||
stderr := io.to_writer(os.stream_from_handle(os.stderr))
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
//+private
|
||||
package testing
|
||||
|
||||
import win32 "core:sys/windows"
|
||||
|
||||
console_ansi_init :: proc() {
|
||||
stdout := win32.GetStdHandle(win32.STD_OUTPUT_HANDLE)
|
||||
if stdout != win32.INVALID_HANDLE && stdout != nil {
|
||||
old_console_mode: u32
|
||||
if win32.GetConsoleMode(stdout, &old_console_mode) {
|
||||
win32.SetConsoleMode(stdout, old_console_mode | win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
||||
}
|
||||
}
|
||||
|
||||
stderr := win32.GetStdHandle(win32.STD_ERROR_HANDLE)
|
||||
if stderr != win32.INVALID_HANDLE && stderr != nil {
|
||||
old_console_mode: u32
|
||||
if win32.GetConsoleMode(stderr, &old_console_mode) {
|
||||
win32.SetConsoleMode(stderr, old_console_mode | win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ import "core:os"
|
||||
|
||||
@(private="file", thread_local)
|
||||
local_test_index: libc.sig_atomic_t
|
||||
@(private="file", thread_local)
|
||||
local_test_index_set: bool
|
||||
|
||||
// Windows does not appear to have a SIGTRAP, so this is defined here, instead
|
||||
// of in the libc package, just so there's no confusion about it being
|
||||
@@ -45,6 +47,13 @@ stop_runner_callback :: proc "c" (sig: libc.int) {
|
||||
|
||||
@(private="file")
|
||||
stop_test_callback :: proc "c" (sig: libc.int) {
|
||||
if !local_test_index_set {
|
||||
// We're a thread created by a test thread.
|
||||
//
|
||||
// There's nothing we can do to inform the test runner about who
|
||||
// signalled, so hopefully the test will handle their own sub-threads.
|
||||
return
|
||||
}
|
||||
if local_test_index == -1 {
|
||||
// We're the test runner, and we ourselves have caught a signal from
|
||||
// which there is no recovery.
|
||||
@@ -114,6 +123,7 @@ This is a dire bug and should be reported to the Odin developers.
|
||||
|
||||
_setup_signal_handler :: proc() {
|
||||
local_test_index = -1
|
||||
local_test_index_set = true
|
||||
|
||||
// Catch user interrupt / CTRL-C.
|
||||
libc.signal(libc.SIGINT, stop_runner_callback)
|
||||
@@ -135,6 +145,7 @@ _setup_signal_handler :: proc() {
|
||||
|
||||
_setup_task_signal_handler :: proc(test_index: int) {
|
||||
local_test_index = cast(libc.sig_atomic_t)test_index
|
||||
local_test_index_set = true
|
||||
}
|
||||
|
||||
_should_stop_runner :: proc() -> bool {
|
||||
|
||||
@@ -105,9 +105,13 @@ cleanup :: proc(t: ^T, procedure: proc(rawptr), user_data: rawptr) {
|
||||
append(&t.cleanups, Internal_Cleanup{procedure, user_data, context})
|
||||
}
|
||||
|
||||
expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bool {
|
||||
expect :: proc(t: ^T, ok: bool, msg := "", expr := #caller_expression(ok), loc := #caller_location) -> bool {
|
||||
if !ok {
|
||||
log.error(msg, location=loc)
|
||||
if msg == "" {
|
||||
log.errorf("expected %v to be true", expr, location=loc)
|
||||
} else {
|
||||
log.error(msg, location=loc)
|
||||
}
|
||||
}
|
||||
return ok
|
||||
}
|
||||
@@ -119,10 +123,10 @@ expectf :: proc(t: ^T, ok: bool, format: string, args: ..any, loc := #caller_loc
|
||||
return ok
|
||||
}
|
||||
|
||||
expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) {
|
||||
expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location, value_expr := #caller_expression(value)) -> bool where intrinsics.type_is_comparable(T) {
|
||||
ok := value == expected || reflect.is_nil(value) && reflect.is_nil(expected)
|
||||
if !ok {
|
||||
log.errorf("expected %v, got %v", expected, value, location=loc)
|
||||
log.errorf("expected %v to be %v, got %v", value_expr, expected, value, location=loc)
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user