aboutsummaryrefslogtreecommitdiff
path: root/core/testing
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-20 15:43:47 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-20 19:28:06 -0400
commit3c40a54dcd9ff8e1b608fac5c91ed0f1d0ed7d00 (patch)
treea03f67bc9a2a2204dbfc0bc3b873beb8efe121c2 /core/testing
parenta9df1b1cde1037d030f4e823ce576dfd9bcf9c97 (diff)
Add terminal color detection to logging in `core:testing`
Diffstat (limited to 'core/testing')
-rw-r--r--core/testing/runner.odin19
1 files changed, 17 insertions, 2 deletions
diff --git a/core/testing/runner.odin b/core/testing/runner.odin
index c81d07109..ff8ca00b9 100644
--- a/core/testing/runner.odin
+++ b/core/testing/runner.odin
@@ -24,6 +24,7 @@ import "core:os"
import "core:slice"
@require import "core:strings"
import "core:sync/chan"
+import "core:terminal"
import "core:terminal/ansi"
import "core:thread"
import "core:time"
@@ -70,6 +71,8 @@ get_log_level :: #force_inline proc() -> runtime.Logger_Level {
}
}
+@(private) global_log_colors_disabled: bool
+
JSON :: struct {
total: int,
success: int,
@@ -129,11 +132,16 @@ run_test_task :: proc(task: thread.Task) {
context.assertion_failure_proc = test_assertion_failure_proc
+ logger_options := Default_Test_Logger_Opts
+ if global_log_colors_disabled {
+ logger_options -= {.Terminal_Color}
+ }
+
context.logger = {
procedure = test_logger_proc,
data = &data.t,
lowest_level = get_log_level(),
- options = Default_Test_Logger_Opts,
+ options = logger_options,
}
random_generator_state: runtime.Default_Random_State
@@ -211,6 +219,8 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
stdout := io.to_writer(os.stream_from_handle(os.stdout))
stderr := io.to_writer(os.stream_from_handle(os.stderr))
+ global_log_colors_disabled = !terminal.color_enabled || !terminal.is_terminal(os.stderr)
+
// -- Prepare test data.
alloc_error: mem.Allocator_Error
@@ -442,11 +452,16 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
// digging through the source to divine everywhere it is used for that.
shared_log_allocator := context.allocator
+ logger_options := Default_Test_Logger_Opts - {.Short_File_Path, .Line, .Procedure}
+ if global_log_colors_disabled {
+ logger_options -= {.Terminal_Color}
+ }
+
context.logger = {
procedure = runner_logger_proc,
data = &log_messages,
lowest_level = get_log_level(),
- options = Default_Test_Logger_Opts - {.Short_File_Path, .Line, .Procedure},
+ options = logger_options,
}
run_index: int