diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2024-09-16 17:36:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-16 17:36:46 +0100 |
| commit | a16d3b6c9aa162652e2648e8f77424bf977c6ee5 (patch) | |
| tree | 30c77f09592bfbcd07925938eaef8d5a089b08ef /core/testing | |
| parent | 68619f299e0a632f634682baabcdc025b240b132 (diff) | |
| parent | 603efa860a5631f1708f6761d753146b6d47b4ba (diff) | |
Merge pull request #4242 from laytan/caller-expression
add '#caller_expression'
Diffstat (limited to 'core/testing')
| -rw-r--r-- | core/testing/testing.odin | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/core/testing/testing.odin b/core/testing/testing.odin index d5e7c6830..09bf6dc0e 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -105,9 +105,13 @@ cleanup :: proc(t: ^T, procedure: proc(rawptr), user_data: rawptr) { append(&t.cleanups, Internal_Cleanup{procedure, user_data, context}) } -expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bool { +expect :: proc(t: ^T, ok: bool, msg := "", expr := #caller_expression(ok), loc := #caller_location) -> bool { if !ok { - log.error(msg, location=loc) + if msg == "" { + log.errorf("expected %v to be true", expr, location=loc) + } else { + log.error(msg, location=loc) + } } return ok } @@ -119,10 +123,10 @@ expectf :: proc(t: ^T, ok: bool, format: string, args: ..any, loc := #caller_loc return ok } -expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) { +expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location, value_expr := #caller_expression(value)) -> bool where intrinsics.type_is_comparable(T) { ok := value == expected || reflect.is_nil(value) && reflect.is_nil(expected) if !ok { - log.errorf("expected %v, got %v", expected, value, location=loc) + log.errorf("expected %v to be %v, got %v", value_expr, expected, value, location=loc) } return ok } |