From 6ea7bdbbe588a935e731f96f7d75e1c91c3238a3 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sat, 1 Nov 2025 16:11:43 +0100 Subject: [PATCH] Add ODIN_TEST_GO_TO_ERROR to print test fail locations in a manner friendly to go-to error in editors --- core/testing/logging.odin | 28 ++++++++++++++++++++++++++-- core/testing/runner.odin | 3 +++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/testing/logging.odin b/core/testing/logging.odin index 041489dab..85f28e564 100644 --- a/core/testing/logging.odin +++ b/core/testing/logging.odin @@ -83,7 +83,31 @@ format_log_text :: proc(level: runtime.Logger_Level, text: string, options: runt log.do_level_header(options, &buf, level) log.do_time_header(options, &buf, at_time) - log.do_location_header(options, &buf, location) - + when GO_TO_ERROR { + do_go_to_error_friendly_location(options, &buf, location) + } else { + log.do_location_header(options, &buf, location) + } return fmt.aprintf("%s%s", strings.to_string(buf), text, allocator = allocator) } + +do_go_to_error_friendly_location :: proc(opts: log.Options, buf: ^strings.Builder, location := #caller_location) { + if log.Location_Header_Opts & opts == nil { + return + } + fmt.sbprint(buf, "\n") + + file := location.file_path + fmt.sbprint(buf, file) + + fmt.sbprint(buf, "(") + fmt.sbprint(buf, location.line) + fmt.sbprint(buf, ":") + fmt.sbprint(buf, location.column) + fmt.sbprint(buf, ")") + + if .Procedure in opts { + fmt.sbprintf(buf, ":%s()", location.procedure) + } + fmt.sbprint(buf, " ") +} \ No newline at end of file diff --git a/core/testing/runner.odin b/core/testing/runner.odin index d79b0fd7e..f913e20fd 100644 --- a/core/testing/runner.odin +++ b/core/testing/runner.odin @@ -63,6 +63,9 @@ LOG_STATE_CHANGES : bool : #config(ODIN_TEST_LOG_STATE_CHANGES, false) USING_SHORT_LOGS : bool : #config(ODIN_TEST_SHORT_LOGS, false) // Output a report of the tests to the given path. JSON_REPORT : string : #config(ODIN_TEST_JSON_REPORT, "") +// Print the full file path for failed test cases on a new line +// in a way that's friendly to regex capture for an editor's "go to error". +GO_TO_ERROR : bool : #config(ODIN_TEST_GO_TO_ERROR, false) get_log_level :: #force_inline proc() -> runtime.Logger_Level { when LOG_LEVEL == "debug" { return .Debug } else