Skip to content

Commit

Permalink
Add -define:ODIN_TEST_LOG_LEVEL to set lowest log level
Browse files Browse the repository at this point in the history
  • Loading branch information
Feoramund committed Jun 2, 2024
1 parent 6a92033 commit 5e3e958
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/testing/runner.odin
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,23 @@ PROGRESS_WIDTH : int : #config(ODIN_TEST_PROGRESS_WIDTH, 24)
// This is the random seed that will be sent to each test.
// If it is unspecified, it will be set to the system cycle counter at startup.
SHARED_RANDOM_SEED : u64 : #config(ODIN_TEST_RANDOM_SEED, 0)
// Set the lowest log level for this test run.
LOG_LEVEL : string : #config(ODIN_TEST_LOG_LEVEL, "info")


get_log_level :: #force_inline proc() -> runtime.Logger_Level {
when ODIN_DEBUG {
// Always use .Debug in `-debug` mode.
return .Debug
} else {
when LOG_LEVEL == "debug" { return .Debug }
else when LOG_LEVEL == "info" { return .Info }
else when LOG_LEVEL == "warning" { return .Warning }
else when LOG_LEVEL == "error" { return .Error }
else when LOG_LEVEL == "fatal" { return .Fatal }
}
}

end_t :: proc(t: ^T) {
for i := len(t.cleanups)-1; i >= 0; i -= 1 {
#no_bounds_check c := t.cleanups[i]
Expand Down Expand Up @@ -82,7 +97,7 @@ run_test_task :: proc(task: thread.Task) {
context.logger = {
procedure = test_logger_proc,
data = &data.t,
lowest_level = .Debug if ODIN_DEBUG else .Info,
lowest_level = get_log_level(),
options = Default_Test_Logger_Opts,
}

Expand Down Expand Up @@ -355,7 +370,7 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
context.logger = {
procedure = runner_logger_proc,
data = &log_messages,
lowest_level = .Debug if ODIN_DEBUG else .Info,
lowest_level = get_log_level(),
options = Default_Test_Logger_Opts - {.Short_File_Path, .Line, .Procedure},
}

Expand Down

0 comments on commit 5e3e958

Please sign in to comment.