We were writing some unit tests, and I was surprised that they passed. Here is a re-creation:
func TestSubsetSlices(t *testing.T) {
a := []string{`a`}
ab := []string{`a`, `b`}
assert.Subset(t, ab, a)
assert.NotSubset(t, a, ab)
// The following asserts should fail this test
assert.Subset(t, a, ab)
assert.NotSubset(t, ab, a)
}
func TestSubsetMapsWithValues(t *testing.T) {
a := map[string]int{
`a`: 1,
}
ab := map[string]int{
`a`: 1,
`b`: 2,
}
assert.Subset(t, ab, a)
assert.NotSubset(t, a, ab)
// The following asserts should fail this test
assert.Subset(t, a, ab)
assert.NotSubset(t, ab, a)
}
func TestSubsetMapsWithEmptyStructs(t *testing.T) {
a := map[string]struct{}{
`a`: {},
}
ab := map[string]struct{}{
`a`: {},
`b`: {},
}
assert.Subset(t, ab, a)
assert.NotSubset(t, a, ab)
// The following asserts should fail this test
assert.Subset(t, a, ab)
assert.NotSubset(t, ab, a)
}
Story
We were writing some unit tests, and I was surprised that they passed. Here is a re-creation:
Problem
I think the problem is here:
https://github.com/stretchr/testify/blob/181cea6eab8b2de7071383eca4be32a424db38dd/assert/assertions.go#L821-L825
https://github.com/stretchr/testify/blob/181cea6eab8b2de7071383eca4be32a424db38dd/assert/assertions.go#L882-L886
It returns a false value, but it doesn't fail the
*testing.T
.