Add tests for workaround solution to #263

pull/264/head
Ernesto Jiménez 2016-01-09 02:56:16 +01:00
parent 52f8b5b531
commit 3dad6b7b59
2 changed files with 35 additions and 0 deletions

View File

@ -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 {

View File

@ -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")
}