Actually fail tests

pull/487/head^2
Emil Stanchev 2017-08-23 23:50:28 +02:00 committed by Ernesto Jiménez
parent ae87ba6d08
commit 76de30ed82
1 changed files with 10 additions and 4 deletions

View File

@ -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...)
}
}