Make NotSubset actually fail the test on nil subset

The assertion function was simply returning false, which doesn't actually fail a test.
An example test that should have failed but doesn't:

  func TestNotSubset(t *testing.T) {
      assert.NotSubset(t, []string{"x"}, nil)
  }
pull/532/head
Emil Stanchev 2017-08-23 21:41:48 +02:00 committed by Ernesto Jiménez
parent 8ccf48a064
commit 9fb9de17de
2 changed files with 9 additions and 1 deletions

View File

@ -693,7 +693,7 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
// Returns whether the assertion was successful (true) or not (false).
func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
if subset == nil {
return false // we consider nil to be equal to the nil set
return Fail(t, fmt.Sprintf("nil is the empty set which is a subset of every set"), msgAndArgs...)
}
subsetValue := reflect.ValueOf(subset)

View File

@ -553,6 +553,14 @@ func TestNotSubset(t *testing.T) {
}
}
func TestNotSubsetNil(t *testing.T) {
mockT := new(testing.T)
NotSubset(mockT, []string{"foo"}, nil)
if !mockT.Failed() {
t.Error("NotSubset on nil set should have failed the test")
}
}
func Test_includeElement(t *testing.T) {
list1 := []string{"Foo", "Bar"}