mirror of https://github.com/stretchr/testify.git
Add tests for workaround solution to #263
parent
52f8b5b531
commit
3dad6b7b59
|
@ -188,6 +188,13 @@ func indentMessageLines(message string, tabs int) string {
|
|||
// FailNow fails test
|
||||
func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool {
|
||||
Fail(t, failureMessage, msgAndArgs...)
|
||||
|
||||
// We cannot extend TestingT with FailNow() and
|
||||
// maintain backwards compatibility, so we fallback
|
||||
// to panicking when FailNow is not available in
|
||||
// TestingT.
|
||||
// See issue #263
|
||||
|
||||
if t, ok := t.(FailNower); ok {
|
||||
t.FailNow()
|
||||
} else {
|
||||
|
|
|
@ -1090,3 +1090,31 @@ func TestDiffEmptyCases(t *testing.T) {
|
|||
Equal(t, "", diff(1, 2))
|
||||
Equal(t, "", diff([]int{1}, []bool{true}))
|
||||
}
|
||||
|
||||
type mockTestingT struct {
|
||||
}
|
||||
|
||||
func (m *mockTestingT) Errorf(format string, args ...interface{}) {}
|
||||
|
||||
func TestFailNowWithPlainTestingT(t *testing.T) {
|
||||
mockT := &mockTestingT{}
|
||||
|
||||
Panics(t, func() {
|
||||
FailNow(mockT, "failed")
|
||||
}, "should panic since mockT is missing FailNow()")
|
||||
}
|
||||
|
||||
type mockFailNowTestingT struct {
|
||||
}
|
||||
|
||||
func (m *mockFailNowTestingT) Errorf(format string, args ...interface{}) {}
|
||||
|
||||
func (m *mockFailNowTestingT) FailNow() {}
|
||||
|
||||
func TestFailNowWithFullTestingT(t *testing.T) {
|
||||
mockT := &mockFailNowTestingT{}
|
||||
|
||||
NotPanics(t, func() {
|
||||
FailNow(mockT, "failed")
|
||||
}, "should call mockT.FailNow() rather than panicking")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue