mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Merge pull request #2638 from ramn/handle_nils_in_expect_value
Fix #2637
This commit is contained in:
@@ -4,6 +4,9 @@ import "core:fmt"
|
|||||||
import "core:io"
|
import "core:io"
|
||||||
import "core:time"
|
import "core:time"
|
||||||
import "core:intrinsics"
|
import "core:intrinsics"
|
||||||
|
import "core:reflect"
|
||||||
|
|
||||||
|
_ :: reflect // alias reflect to nothing to force visibility for -vet
|
||||||
|
|
||||||
// IMPORTANT NOTE: Compiler requires this layout
|
// IMPORTANT NOTE: Compiler requires this layout
|
||||||
Test_Signature :: proc(^T)
|
Test_Signature :: proc(^T)
|
||||||
@@ -89,7 +92,7 @@ expect :: proc(t: ^T, ok: bool, msg: string = "", loc := #caller_location) -> bo
|
|||||||
return ok
|
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) -> bool where intrinsics.type_is_comparable(T) {
|
||||||
ok := value == expected
|
ok := value == expected || reflect.is_nil(value) && reflect.is_nil(expected)
|
||||||
if !ok {
|
if !ok {
|
||||||
errorf(t, "expected %v, got %v", expected, value, loc=loc)
|
errorf(t, "expected %v, got %v", expected, value, loc=loc)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ set COMMON=-collection:tests=..\..
|
|||||||
..\..\..\odin build ..\test_issue_2113.odin %COMMON% -file -debug || exit /b
|
..\..\..\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_2466.odin %COMMON% -file || exit /b
|
||||||
..\..\..\odin test ..\test_issue_2615.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
|
@echo off
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ $ODIN test ../test_issue_2087.odin $COMMON -file
|
|||||||
$ODIN build ../test_issue_2113.odin $COMMON -file -debug
|
$ODIN build ../test_issue_2113.odin $COMMON -file -debug
|
||||||
$ODIN test ../test_issue_2466.odin $COMMON -file
|
$ODIN test ../test_issue_2466.odin $COMMON -file
|
||||||
$ODIN test ../test_issue_2615.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
|
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"
|
echo "SUCCESSFUL 1/1"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user