diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2025-01-13 20:33:49 +0100 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2025-01-13 20:33:49 +0100 |
| commit | 9d4fa39daa55d0fe775068c123cba8ce5f2950e9 (patch) | |
| tree | 79b8875f37ff39754711b1126b1e836256923711 /core/fmt | |
| parent | 48a7ed01f8cb6bc3c5bd1ec5ba3d16b072ce8c50 (diff) | |
add ensure and ensuref to fmt and log, fix some inconsistencies
Diffstat (limited to 'core/fmt')
| -rw-r--r-- | core/fmt/fmt.odin | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 49e9f2e6d..da3b419d5 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -314,7 +314,29 @@ assertf :: proc(condition: bool, fmt: string, args: ..any, loc := #caller_locati p = runtime.default_assertion_failure_proc } message := tprintf(fmt, ..args) - p("Runtime assertion", message, loc) + p("runtime assertion", message, loc) + } + internal(loc, fmt, ..args) + } +} +// Runtime ensure with a formatted message +// +// Inputs: +// - condition: The boolean condition to be asserted +// - fmt: A format string with placeholders for the provided arguments +// - args: A variadic list of arguments to be formatted +// - loc: The location of the caller +// +ensuref :: proc(condition: bool, fmt: string, args: ..any, loc := #caller_location) { + if !condition { + @(cold) + internal :: proc(loc: runtime.Source_Code_Location, fmt: string, args: ..any) { + p := context.assertion_failure_proc + if p == nil { + p = runtime.default_assertion_failure_proc + } + message := tprintf(fmt, ..args) + p("unsatisfied ensure", message, loc) } internal(loc, fmt, ..args) } @@ -332,7 +354,7 @@ panicf :: proc(fmt: string, args: ..any, loc := #caller_location) -> ! { p = runtime.default_assertion_failure_proc } message := tprintf(fmt, ..args) - p("Panic", message, loc) + p("panic", message, loc) } // Creates a formatted C string |