From 76de30ed823122a4e5be705882f90e68febb7468 Mon Sep 17 00:00:00 2001 From: Emil Stanchev Date: Wed, 23 Aug 2017 23:50:28 +0200 Subject: [PATCH] Actually fail tests --- assert/assertions.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 95032c9..dc3db36 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -737,7 +737,10 @@ func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) // Returns whether the assertion was successful (true) or not (false). func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool) { if listA == nil || listB == nil { - return listA == listB + if listA != listB { + return Fail(t, fmt.Sprintf("only one value is nil"), msgAndArgs...) + } + return true } aKind := reflect.TypeOf(listA).Kind() @@ -754,8 +757,11 @@ func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface aValue := reflect.ValueOf(listA) bValue := reflect.ValueOf(listB) - if aValue.Len() != bValue.Len() { - return false + aLen := aValue.Len() + bLen := bValue.Len() + + if aLen != bLen { + return Fail(t, fmt.Sprintf("lengths don't match: %d != %d", aLen, bLen), msgAndArgs...) } // Mark indexes in bValue that we already used @@ -774,7 +780,7 @@ func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface } } if !found { - return false + return Fail(t, fmt.Sprintf("element %s appears more times in %s than in %s", element, aValue, bValue), msgAndArgs...) } }