mirror of https://github.com/stretchr/testify.git
changing time.Duration equality mismatch output from int64 to readable format. Fixes #626
(cherry picked from commit 637cd144ddae7a3792bcb5c74a3bf3a071c0a250)pull/869/head
parent
3c60a0e014
commit
8c465a0c8e
|
@ -432,9 +432,11 @@ func formatUnequalValues(expected, actual interface{}) (e string, a string) {
|
|||
return fmt.Sprintf("%T(%#v)", expected, expected),
|
||||
fmt.Sprintf("%T(%#v)", actual, actual)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%#v", expected),
|
||||
fmt.Sprintf("%#v", actual)
|
||||
switch expected.(type) {
|
||||
case time.Duration:
|
||||
return fmt.Sprintf("%v", expected), fmt.Sprintf("%v", actual)
|
||||
}
|
||||
return fmt.Sprintf("%#v", expected), fmt.Sprintf("%#v", actual)
|
||||
}
|
||||
|
||||
// EqualValues asserts that two objects are equal or convertable to the same types
|
||||
|
|
|
@ -1831,6 +1831,15 @@ Diff:
|
|||
Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestTimeEqualityErrorFormatting(t *testing.T) {
|
||||
mockT := new(mockTestingT)
|
||||
|
||||
Equal(mockT, time.Second*2, time.Millisecond)
|
||||
|
||||
expectedErr := "\\s+Error Trace:\\s+Error:\\s+Not equal:\\s+\n\\s+expected: 2s\n\\s+actual\\s+: 1ms\n"
|
||||
Regexp(t, regexp.MustCompile(expectedErr), mockT.errorString())
|
||||
}
|
||||
|
||||
func TestDiffEmptyCases(t *testing.T) {
|
||||
Equal(t, "", diff(nil, nil))
|
||||
Equal(t, "", diff(struct{ foo string }{}, nil))
|
||||
|
@ -1875,9 +1884,18 @@ func TestDiffRace(t *testing.T) {
|
|||
}
|
||||
|
||||
type mockTestingT struct {
|
||||
errorFmt string
|
||||
args []interface{}
|
||||
}
|
||||
|
||||
func (m *mockTestingT) Errorf(format string, args ...interface{}) {}
|
||||
func (m *mockTestingT) errorString() string {
|
||||
return fmt.Sprintf(m.errorFmt, m.args...)
|
||||
}
|
||||
|
||||
func (m *mockTestingT) Errorf(format string, args ...interface{}) {
|
||||
m.errorFmt = format
|
||||
m.args = args
|
||||
}
|
||||
|
||||
func TestFailNowWithPlainTestingT(t *testing.T) {
|
||||
mockT := &mockTestingT{}
|
||||
|
|
Loading…
Reference in New Issue