From 9b54b99bf696a65bc5c8358b2a5ace1f6dc4fdcc Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 21 Jun 2023 01:17:05 +0100 Subject: Use positional and named arguments within the core library --- core/testing/runner_windows.odin | 2 +- core/testing/testing.odin | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'core/testing') diff --git a/core/testing/runner_windows.odin b/core/testing/runner_windows.odin index 525eae685..17bcfce26 100644 --- a/core/testing/runner_windows.odin +++ b/core/testing/runner_windows.odin @@ -191,7 +191,7 @@ run_internal_test :: proc(t: ^T, it: Internal_Test) { global_exception_handler = win32.AddVectoredExceptionHandler(0, exception_handler_proc) context.assertion_failure_proc = proc(prefix, message: string, loc: runtime.Source_Code_Location) -> ! { - errorf(t=global_current_t, format="%s %s", args={prefix, message}, loc=loc) + errorf(global_current_t, "%s %s", prefix, message, loc=loc) intrinsics.trap() } diff --git a/core/testing/testing.odin b/core/testing/testing.odin index 37f9fe4d9..0ceb58e33 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -46,15 +46,15 @@ errorf :: proc(t: ^T, format: string, args: ..any, loc := #caller_location) { } fail :: proc(t: ^T, loc := #caller_location) { - error(t=t, args={"FAIL"}, loc=loc) + error(t, "FAIL", loc=loc) t.error_count += 1 } fail_now :: proc(t: ^T, msg := "", loc := #caller_location) { if msg != "" { - error(t=t, args={"FAIL:", msg}, loc=loc) + error(t, "FAIL:", msg, loc=loc) } else { - error(t=t, args={"FAIL"}, loc=loc) + error(t, "FAIL", loc=loc) } t.error_count += 1 if t._fail_now != nil { @@ -84,14 +84,14 @@ cleanup :: proc(t: ^T, procedure: proc(rawptr), user_data: rawptr) { expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bool { if !ok { - error(t=t, args={msg}, loc=loc) + error(t, msg, loc=loc) } return ok } expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) { ok := value == expected if !ok { - errorf(t=t, format="expected %v, got %v", args={expected, value}, loc=loc) + errorf(t, "expected %v, got %v", expected, value, loc=loc) } return ok } -- cgit v1.2.3 From 7b89f258189f817bcc177bbc4426c48f3ccd9127 Mon Sep 17 00:00:00 2001 From: ramn Date: Sat, 8 Jul 2023 23:46:51 +0200 Subject: Fix #2637 where testing.expect_value can't compare nils --- core/testing/testing.odin | 5 +++-- tests/issues/run.bat | 1 + tests/issues/run.sh | 1 + tests/issues/test_issue_2637.odin | 13 +++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/issues/test_issue_2637.odin (limited to 'core/testing') diff --git a/core/testing/testing.odin b/core/testing/testing.odin index 0ceb58e33..1d738bbd1 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -4,6 +4,7 @@ import "core:fmt" import "core:io" import "core:time" import "core:intrinsics" +import "core:reflect" // IMPORTANT NOTE: Compiler requires this layout Test_Signature :: proc(^T) @@ -89,7 +90,7 @@ expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bo return ok } expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) { - ok := value == expected + ok := value == expected || reflect.is_nil(value) && reflect.is_nil(expected) if !ok { errorf(t, "expected %v, got %v", expected, value, loc=loc) } @@ -100,4 +101,4 @@ expect_value :: proc(t: ^T, value, expected: $T, loc := #caller_location) -> boo set_fail_timeout :: proc(t: ^T, duration: time.Duration, loc := #caller_location) { _fail_timeout(t, duration, loc) -} \ No newline at end of file +} diff --git a/tests/issues/run.bat b/tests/issues/run.bat index 105d474e3..63d722e09 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -14,6 +14,7 @@ set COMMON=-collection:tests=..\.. ..\..\..\odin build ..\test_issue_2113.odin %COMMON% -file -debug || exit /b ..\..\..\odin test ..\test_issue_2466.odin %COMMON% -file || exit /b ..\..\..\odin test ..\test_issue_2615.odin %COMMON% -file || exit /b +..\..\..\odin test ..\test_issue_2637.odin %COMMON% -file || exit /b @echo off diff --git a/tests/issues/run.sh b/tests/issues/run.sh index c4c53e7e1..7d2101dc6 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -17,6 +17,7 @@ $ODIN test ../test_issue_2087.odin $COMMON -file $ODIN build ../test_issue_2113.odin $COMMON -file -debug $ODIN test ../test_issue_2466.odin $COMMON -file $ODIN test ../test_issue_2615.odin $COMMON -file +$ODIN test ../test_issue_2637.odin $COMMON -file if [[ $($ODIN build ../test_issue_2395.odin $COMMON -file 2>&1 >/dev/null | grep -c "$NO_NIL_ERR") -eq 2 ]] ; then echo "SUCCESSFUL 1/1" else diff --git a/tests/issues/test_issue_2637.odin b/tests/issues/test_issue_2637.odin new file mode 100644 index 000000000..c170fc444 --- /dev/null +++ b/tests/issues/test_issue_2637.odin @@ -0,0 +1,13 @@ +// Tests issue #2637 https://github.com/odin-lang/Odin/issues/2637 +package test_issues + +import "core:testing" + +Foo :: Maybe(string) + +@(test) +test_expect_value_succeeds_with_nil :: proc(t: ^testing.T) { + x: Foo + testing.expect(t, x == nil) // Succeeds + testing.expect_value(t, x, nil) // Fails, "expected nil, got nil" +} -- cgit v1.2.3 From 5f53d815d113e06bf4612592506db8564d3dc88b Mon Sep 17 00:00:00 2001 From: ramn Date: Sun, 9 Jul 2023 00:15:01 +0200 Subject: fix: make -vet not complain --- core/testing/testing.odin | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/testing') diff --git a/core/testing/testing.odin b/core/testing/testing.odin index 1d738bbd1..1ba05315c 100644 --- a/core/testing/testing.odin +++ b/core/testing/testing.odin @@ -6,6 +6,8 @@ import "core:time" import "core:intrinsics" import "core:reflect" +_ :: reflect // alias reflect to nothing to force visibility for -vet + // IMPORTANT NOTE: Compiler requires this layout Test_Signature :: proc(^T) -- cgit v1.2.3