mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
Make sure time.Time comparison produces a helpful diff. closes #989
This commit is contained in:
parent
6990a05d54
commit
dc5c261377
@ -1609,12 +1609,17 @@ func diff(expected interface{}, actual interface{}) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var e, a string
|
var e, a string
|
||||||
if et != reflect.TypeOf("") {
|
|
||||||
e = spewConfig.Sdump(expected)
|
switch et {
|
||||||
a = spewConfig.Sdump(actual)
|
case reflect.TypeOf(""):
|
||||||
} else {
|
|
||||||
e = reflect.ValueOf(expected).String()
|
e = reflect.ValueOf(expected).String()
|
||||||
a = reflect.ValueOf(actual).String()
|
a = reflect.ValueOf(actual).String()
|
||||||
|
case reflect.TypeOf(time.Time{}):
|
||||||
|
e = spewConfigStringerEnabled.Sdump(expected)
|
||||||
|
a = spewConfigStringerEnabled.Sdump(actual)
|
||||||
|
default:
|
||||||
|
e = spewConfig.Sdump(expected)
|
||||||
|
a = spewConfig.Sdump(actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
|
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
|
||||||
@ -1646,6 +1651,14 @@ var spewConfig = spew.ConfigState{
|
|||||||
MaxDepth: 10,
|
MaxDepth: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var spewConfigStringerEnabled = spew.ConfigState{
|
||||||
|
Indent: " ",
|
||||||
|
DisablePointerAddresses: true,
|
||||||
|
DisableCapacities: true,
|
||||||
|
SortKeys: true,
|
||||||
|
MaxDepth: 10,
|
||||||
|
}
|
||||||
|
|
||||||
type tHelper interface {
|
type tHelper interface {
|
||||||
Helper()
|
Helper()
|
||||||
}
|
}
|
||||||
|
@ -1991,6 +1991,23 @@ Diff:
|
|||||||
diffTestingStruct{A: "some string", B: 15},
|
diffTestingStruct{A: "some string", B: 15},
|
||||||
)
|
)
|
||||||
Equal(t, expected, actual)
|
Equal(t, expected, actual)
|
||||||
|
|
||||||
|
expected = `
|
||||||
|
|
||||||
|
Diff:
|
||||||
|
--- Expected
|
||||||
|
+++ Actual
|
||||||
|
@@ -1,2 +1,2 @@
|
||||||
|
-(time.Time) 2020-09-24 00:00:00 +0000 UTC
|
||||||
|
+(time.Time) 2020-09-25 00:00:00 +0000 UTC
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
actual = diff(
|
||||||
|
time.Date(2020, 9, 24, 0, 0, 0, 0, time.UTC),
|
||||||
|
time.Date(2020, 9, 25, 0, 0, 0, 0, time.UTC),
|
||||||
|
)
|
||||||
|
Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimeEqualityErrorFormatting(t *testing.T) {
|
func TestTimeEqualityErrorFormatting(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user