aboutsummaryrefslogtreecommitdiff
path: root/core/testing
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-09-16 17:36:46 +0100
committerGitHub <noreply@github.com>2024-09-16 17:36:46 +0100
commita16d3b6c9aa162652e2648e8f77424bf977c6ee5 (patch)
tree30c77f09592bfbcd07925938eaef8d5a089b08ef /core/testing
parent68619f299e0a632f634682baabcdc025b240b132 (diff)
parent603efa860a5631f1708f6761d753146b6d47b4ba (diff)
Merge pull request #4242 from laytan/caller-expression
add '#caller_expression'
Diffstat (limited to 'core/testing')
-rw-r--r--core/testing/testing.odin12
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
}