Move error message tests from helper test to separate test.

This commit is contained in:
Arseny Balobanov 2020-03-22 06:35:22 +03:00
parent 2b49e0ea2f
commit 4423e722a9
3 changed files with 18 additions and 11 deletions

View file

@ -82,14 +82,27 @@ func TestNotEqual(t *testing.T) {
}
}
type mockT struct{}
type mockT struct {
errMsg string
}
func (m *mockT) Errorf(format string, args ...interface{}) {}
func (m *mockT) Errorf(format string, args ...interface{}) {
m.errMsg = fmt.Sprintf(format, args...)
}
func (m *mockT) FailNow() {}
func (m *mockT) Helper() {}
func TestErrorMessage(t *testing.T) {
mockT := &mockT{}
RequireNotEqual(mockT, 1, 1, "1 != 1")
require.Contains(t, mockT.errMsg, "1 != 1")
RequireEqual(mockT, 1, 2, "%d must be equal to %d", 1, 2)
require.Contains(t, mockT.errMsg, "1 must be equal to 2")
}
func BenchmarkRequireEqualInt64(b *testing.B) {
t := &mockT{}
b.ResetTimer()

View file

@ -13,7 +13,7 @@ func TestHelper(t *testing.T) {
if os.Getenv("FAIL_ASSERTIONS") == "1" {
AssertEqual(t, 1, 2, "%d must be equal to %d", 1, 2)
AssertNotEqual(t, 1, 1, "1 != 1")
RequireEqual(t, 1, 2, errMsgLog{Exp: 1, Act: 2})
RequireEqual(t, 1, 2)
return
}
@ -25,16 +25,9 @@ func TestHelper(t *testing.T) {
err := cmd.Run()
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
require.Contains(t, buf.String(), "helper_test.go:14")
require.Contains(t, buf.String(), "1 must be equal to 2")
require.Contains(t, buf.String(), "helper_test.go:15")
require.Contains(t, buf.String(), "1 != 1")
require.Contains(t, buf.String(), "helper_test.go:16")
return
}
t.Fatalf("process ran with err %v, want exit status 1", err)
}
type errMsgLog struct {
Exp int
Act int
}

View file

@ -2,7 +2,8 @@
package testequal
// T is an interface wrapper around *testing.T.
// T is an interface wrapper for *testing.T
// that contains only a small subset of methods.
type T interface {
Errorf(format string, args ...interface{})
Helper()