mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
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) }
This commit is contained in:
parent
8ccf48a064
commit
9fb9de17de
@ -693,7 +693,7 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
|
|||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
|
func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
|
||||||
if subset == nil {
|
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)
|
subsetValue := reflect.ValueOf(subset)
|
||||||
|
@ -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) {
|
func Test_includeElement(t *testing.T) {
|
||||||
|
|
||||||
list1 := []string{"Foo", "Bar"}
|
list1 := []string{"Foo", "Bar"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user