Repository: stretchr/testify (go)

Issue:
formatUnequalValues with %v instead of %#v?
Is there a way to get the default format when assert.Equal fails? Specifically, I am comparing time.Duration values, and getting an int64 of microseconds is not as friendly as Duration.String. ([example](https://play.golang.org/p/vA3xeX5-OEr))

I understand that the current behavior is generally more useful. Rather than changing the default, I am hoping there is some option I can invoke to make my own test output more readable.

Sample output:
```
        assertions.go:256:
                        Error Trace:    integration_test.go:125
                        Error:          Not equal:
                                        expected: 180000000000
                                        actual  : 0
                        Test:           TestDurationFormat
```

Preferred output:
```
        assertions.go:256:
                        Error Trace:    integration_test.go:125
                        Error:          Not equal:
                                        expected: 3m0s
                                        actual  : 0s
                        Test:           TestDurationFormat
```




Pull request description:
Time duration diff format
Time Duration mismatch from nanoseconds (int64) to readable format.

Fixes #626.

Patch:
diff --git a/assert/assertions.go b/assert/assertions.go
index 2ca22eb..2e48602 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -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


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index b851116..7c74a7c 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -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{}