diff --git a/mapstest/assertion_messages_test.go b/mapstest/assertion_messages_test.go index ccf57a1..8b91cf0 100644 --- a/mapstest/assertion_messages_test.go +++ b/mapstest/assertion_messages_test.go @@ -17,7 +17,7 @@ func TestAssertContains_message(t *testing.T) { require.False(t, b) assert.Equal(t, ` - Error Trace: assertions.go:51 + Error Trace: assertions.go:54 assertion_messages_test.go:16 Error: v1 does not contain v2: values are not equal @@ -42,7 +42,7 @@ func TestAssertNotContains_message(t *testing.T) { require.False(t, b) assert.Equal(t, ` - Error Trace: assertions.go:75 + Error Trace: assertions.go:81 assertion_messages_test.go:41 Error: v1 should not contain v2: v1: red @@ -58,7 +58,7 @@ func TestAssertEquivalent_message(t *testing.T) { require.False(t, b) assert.Equal(t, ` - Error Trace: assertions.go:111 + Error Trace: assertions.go:120 assertion_messages_test.go:57 Error: v1 !≈ v2: values are not equal @@ -83,7 +83,7 @@ func TestAssertNotEquivalent_message(t *testing.T) { require.False(t, b) assert.Equal(t, ` - Error Trace: assertions.go:135 + Error Trace: assertions.go:147 assertion_messages_test.go:82 Error: v1 should not ≈ v2: v1: red diff --git a/mapstest/assertions.go b/mapstest/assertions.go index 4fe2c62..d35afef 100644 --- a/mapstest/assertions.go +++ b/mapstest/assertions.go @@ -37,6 +37,9 @@ func AssertContains(t TestingT, v1, v2 interface{}, optsMsgAndArgs ...interface{ } opts, optsMsgAndArgs := splitOptions(optsMsgAndArgs) match := maps.ContainsMatch(v1, v2, opts...) + if !assert.NoError(t, match.Error, match.Message) { + return false + } if !match.Matches { nv1, err := maps.Normalize(v1) @@ -44,7 +47,7 @@ func AssertContains(t TestingT, v1, v2 interface{}, optsMsgAndArgs ...interface{ v1 = nv1 } nv2, err := maps.Normalize(v2) - if !assert.NoError(t, err, "error normalizing v2") { + if assert.NoError(t, err, "error normalizing v2") { v2 = nv2 } diff := containsDiff(v1, v2) @@ -62,6 +65,9 @@ func AssertNotContains(t TestingT, v1, v2 interface{}, optsMsgAndArgs ...interfa } opts, optsMsgAndArgs := splitOptions(optsMsgAndArgs) match := maps.ContainsMatch(v1, v2, opts...) + if !assert.NoError(t, match.Error, match.Message) { + return false + } if match.Matches { nv1, err := maps.Normalize(v1) @@ -98,6 +104,9 @@ func AssertEquivalent(t TestingT, v1, v2 interface{}, optsMsgAndArgs ...interfac } opts, optsMsgAndArgs := splitOptions(optsMsgAndArgs) match := maps.EquivalentMatch(v1, v2, opts...) + if !assert.NoError(t, match.Error, match.Message) { + return false + } if !match.Matches { nv1, err := maps.Normalize(v1) @@ -122,6 +131,9 @@ func AssertNotEquivalent(t TestingT, v1, v2 interface{}, optsMsgAndArgs ...inter } opts, optsMsgAndArgs := splitOptions(optsMsgAndArgs) match := maps.EquivalentMatch(v1, v2, opts...) + if !assert.NoError(t, match.Error, match.Message) { + return false + } if match.Matches { nv1, err := maps.Normalize(v1) diff --git a/mapstest/assertions_test.go b/mapstest/assertions_test.go index 26392f6..3d0b1e7 100644 --- a/mapstest/assertions_test.go +++ b/mapstest/assertions_test.go @@ -34,6 +34,7 @@ func TestAssertionsContains(t *testing.T) { v1, v2 interface{} contains bool equiv bool + err bool opts []interface{} }{ { @@ -74,6 +75,11 @@ func TestAssertionsContains(t *testing.T) { contains: true, equiv: false, }, + { + v1: "string", + v2: make(chan bool), + err: true, + }, } for _, test := range tests { @@ -87,6 +93,7 @@ func TestAssertionsContains(t *testing.T) { af := func(fn assertFunc, expectSuccess bool) { mt := mockTestingT{} b := fn(&mt, test.v1, test.v2, test.opts...) + t.Logf("msg: " + mt.msg) assert.Equal(t, expectSuccess, b) if expectSuccess { assert.False(t, mt.failed) @@ -100,6 +107,7 @@ func TestAssertionsContains(t *testing.T) { rf := func(fn requireFunc, expectSuccess bool) { mt := mockTestingT{} fn(&mt, test.v1, test.v2, test.opts...) + t.Logf("msg: " + mt.msg) if expectSuccess { assert.False(t, mt.failed) assert.False(t, mt.failedNow) @@ -109,15 +117,15 @@ func TestAssertionsContains(t *testing.T) { } } - af(AssertContains, test.contains) - af(AssertNotContains, !test.contains) - rf(RequireContains, test.contains) - rf(RequireNotContains, !test.contains) + af(AssertContains, test.contains && !test.err) + af(AssertNotContains, !test.contains && !test.err) + rf(RequireContains, test.contains && !test.err) + rf(RequireNotContains, !test.contains && !test.err) - af(AssertEquivalent, test.equiv) - af(AssertNotEquivalent, !test.equiv) - rf(RequireEquivalent, test.equiv) - rf(RequireNotEquivalent, !test.equiv) + af(AssertEquivalent, test.equiv && !test.err) + af(AssertNotEquivalent, !test.equiv && !test.err) + rf(RequireEquivalent, test.equiv && !test.err) + rf(RequireNotEquivalent, !test.equiv && !test.err) }) }