Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak the grammar of DiffErrStrings outputs #140

Merged
merged 1 commit into from
Jun 15, 2023
Merged
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
6 changes: 3 additions & 3 deletions testutil/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func DiffErrString(got error, want string) string {
if got == nil {
return ""
}
return fmt.Sprintf("expected error %q to be <nil>", got.Error())
return fmt.Sprintf("got error %q but want <nil>", got.Error())
}
if got == nil {
return fmt.Sprintf("expected error <nil> to contain %q", want)
return fmt.Sprintf("got error <nil> but want an error containing %q", want)
}
if msg := got.Error(); !strings.Contains(msg, want) {
return fmt.Sprintf("expected error %q to contain %q", msg, want)
return fmt.Sprintf("got error %q but want an error containing %q", msg, want)
}
return ""
}
6 changes: 3 additions & 3 deletions testutil/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ func TestDiffErrString(t *testing.T) {
{
name: "empty_string_err",
err: fmt.Errorf("some err"),
wantDiff: `expected error "some err" to be <nil>`,
wantDiff: `got error "some err" but want <nil>`,
},
{
name: "non_empty_string_nil_err",
msg: "some err",
wantDiff: `expected error <nil> to contain "some err"`,
wantDiff: `got error <nil> but want an error containing "some err"`,
},
{
name: "err_mismatch",
msg: "some err",
err: fmt.Errorf("other err"),
wantDiff: `expected error "other err" to contain "some err"`,
wantDiff: `got error "other err" but want an error containing "some err"`,
},
{
name: "err_match",
Expand Down