mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Add terminal color detection to logging in core:testing
This commit is contained in:
@@ -24,6 +24,7 @@ import "core:os"
|
|||||||
import "core:slice"
|
import "core:slice"
|
||||||
@require import "core:strings"
|
@require import "core:strings"
|
||||||
import "core:sync/chan"
|
import "core:sync/chan"
|
||||||
|
import "core:terminal"
|
||||||
import "core:terminal/ansi"
|
import "core:terminal/ansi"
|
||||||
import "core:thread"
|
import "core:thread"
|
||||||
import "core:time"
|
import "core:time"
|
||||||
@@ -70,6 +71,8 @@ get_log_level :: #force_inline proc() -> runtime.Logger_Level {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(private) global_log_colors_disabled: bool
|
||||||
|
|
||||||
JSON :: struct {
|
JSON :: struct {
|
||||||
total: int,
|
total: int,
|
||||||
success: int,
|
success: int,
|
||||||
@@ -129,11 +132,16 @@ run_test_task :: proc(task: thread.Task) {
|
|||||||
|
|
||||||
context.assertion_failure_proc = test_assertion_failure_proc
|
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 = {
|
context.logger = {
|
||||||
procedure = test_logger_proc,
|
procedure = test_logger_proc,
|
||||||
data = &data.t,
|
data = &data.t,
|
||||||
lowest_level = get_log_level(),
|
lowest_level = get_log_level(),
|
||||||
options = Default_Test_Logger_Opts,
|
options = logger_options,
|
||||||
}
|
}
|
||||||
|
|
||||||
random_generator_state: runtime.Default_Random_State
|
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))
|
stdout := io.to_writer(os.stream_from_handle(os.stdout))
|
||||||
stderr := io.to_writer(os.stream_from_handle(os.stderr))
|
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.
|
// -- Prepare test data.
|
||||||
|
|
||||||
alloc_error: mem.Allocator_Error
|
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.
|
// digging through the source to divine everywhere it is used for that.
|
||||||
shared_log_allocator := context.allocator
|
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 = {
|
context.logger = {
|
||||||
procedure = runner_logger_proc,
|
procedure = runner_logger_proc,
|
||||||
data = &log_messages,
|
data = &log_messages,
|
||||||
lowest_level = get_log_level(),
|
lowest_level = get_log_level(),
|
||||||
options = Default_Test_Logger_Opts - {.Short_File_Path, .Line, .Procedure},
|
options = logger_options,
|
||||||
}
|
}
|
||||||
|
|
||||||
run_index: int
|
run_index: int
|
||||||
|
|||||||
Reference in New Issue
Block a user