mirror of https://github.com/stretchr/testify.git
Merge pull request #264 from stretchr/issue-263
Fix Backwards Incompatible change to TestingTpull/265/head v1.1.2
commit
4adf44fc7a
|
@ -21,6 +21,9 @@ import (
|
|||
// TestingT is an interface wrapper around *testing.T
|
||||
type TestingT interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
type FailNower interface {
|
||||
FailNow()
|
||||
}
|
||||
|
||||
|
@ -185,7 +188,18 @@ func indentMessageLines(message string, tabs int) string {
|
|||
// FailNow fails test
|
||||
func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool {
|
||||
Fail(t, failureMessage, msgAndArgs...)
|
||||
t.FailNow()
|
||||
|
||||
// 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 {
|
||||
panic("test failed and t is missing `FailNow()`")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -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