Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
.idea
14 changes: 14 additions & 0 deletions checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type OuterJSON struct {
}

type boolean bool
type myString string

var checkerTests = []struct {
about string
Expand Down Expand Up @@ -179,6 +180,19 @@ got:
want:
"42"
`,
}, {
about: "Equals: string and named string type with same value",
checker: qt.Equals,
got: "hello",
args: []interface{}{myString("hello")},
expectedCheckFailure: `
error:
values are not equal
got:
"hello"
want:
quicktest_test.myString("hello")
`,
}, {
about: "Equals: nil and nil",
checker: qt.Equals,
Expand Down
8 changes: 8 additions & 0 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func Format(v interface{}) string {
// (json.RawMessage for example).
return fmt.Sprintf("%T(%s)", v, quoteString(string(bytes)))
}
// Handle named string types (e.g. type myString string) explicitly so that
// the type name is included in the output. Without this they fall through to
// pretty.Formatter which renders them as a plain quoted string, identical to
// a plain string value, causing the deduplication in the reporter to
// incorrectly print "<same as got>" when the types differ.
if rv := reflect.ValueOf(v); rv.IsValid() && rv.Kind() == reflect.String {
return fmt.Sprintf("%T(%s)", v, quoteString(rv.String()))
}
// The pretty.Sprint equivalent does not quote string values.
return fmt.Sprintf("%# v", pretty.Formatter(v))
}
Expand Down