[go] regexp: standardize error message format in find_test.go

3 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Dec 26, 2025, 11:56:13 AM (2 days ago) Dec 26
to goph...@pubsubhelper.golang.org, Jorge Pinto, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

regexp: standardize error message format in find_test.go

This change updates the test error messages in find_test.go to follow
the Go standard 'got, want' format.
It also replaces 'expected/should be' terminology with the project's preferred style
and improves the clarity of failure logs by using %q to quote string values.
Change-Id: I17bfc60a06a879ce5e2c64d624c636e2c24135e9
GitHub-Last-Rev: e9613ac28cdce2fc16672b4aa42636b01ae0a80c
GitHub-Pull-Request: golang/go#77005

Change diff

diff --git a/src/regexp/find_test.go b/src/regexp/find_test.go
index 49e9619..5b446c2 100644
--- a/src/regexp/find_test.go
+++ b/src/regexp/find_test.go
@@ -159,23 +159,23 @@
for _, test := range findTests {
re := MustCompile(test.pat)
if re.String() != test.pat {
- t.Errorf("String() = `%s`; should be `%s`", re.String(), test.pat)
+ t.Errorf("re.String() = %q, want %q", re.String(), test.pat)
}
result := re.Find([]byte(test.text))
switch {
case len(test.matches) == 0 && len(result) == 0:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
- expect := test.text[test.matches[0][0]:test.matches[0][1]]
+ want := test.text[test.matches[0][0]:test.matches[0][1]]
if len(result) != cap(result) {
- t.Errorf("expected capacity %d got %d: %s", len(result), cap(result), test)
+ t.Errorf("got capacity %d, want %d: %s", cap(result), len(result), test)
}
- if expect != string(result) {
- t.Errorf("expected %q got %q: %s", expect, result, test)
+ if want != string(result) {
+ t.Errorf("got %q, want %q: %s", result, want, test)
}
}
}
@@ -188,16 +188,16 @@
case len(test.matches) == 0 && len(result) == 0:
// ok
case test.matches == nil && result != "":
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == "":
// Tricky because an empty result has two meanings: no match or empty match.
if test.matches[0][0] != test.matches[0][1] {
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
}
case test.matches != nil && result != "":
- expect := test.text[test.matches[0][0]:test.matches[0][1]]
- if expect != result {
- t.Errorf("expected %q got %q: %s", expect, result, test)
+ want := test.text[test.matches[0][0]:test.matches[0][1]]
+ if want != result {
+ t.Errorf("got %q, want %q: %s", result, want, test)
}
}
}
@@ -208,13 +208,13 @@
case len(test.matches) == 0 && len(result) == 0:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %v, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
- expect := test.matches[0]
- if expect[0] != result[0] || expect[1] != result[1] {
- t.Errorf("expected %v got %v: %s", expect, result, test)
+ want := test.matches[0]
+ if want[0] != result[0] || want[1] != result[1] {
+ t.Errorf("got %v, want %v: %s", result, want, test)
}
}
}
@@ -246,22 +246,22 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Fatalf("expected match; got none: %s", test)
+ t.Fatalf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
if len(test.matches) != len(result) {
- t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
+ t.Errorf("got %d matches, want %d: %s", len(result), len(test.matches), test)
continue
}
for k, e := range test.matches {
got := result[k]
if len(got) != cap(got) {
- t.Errorf("match %d: expected capacity %d got %d: %s", k, len(got), cap(got), test)
+ t.Errorf("match %d: got capacity %d, want %d: %s", k, cap(got), len(got), test)
}
- expect := test.text[e[0]:e[1]]
- if expect != string(got) {
- t.Errorf("match %d: expected %q got %q: %s", k, expect, got, test)
+ want := test.text[e[0]:e[1]]
+ if want != string(got) {
+ t.Errorf("match %d: got %q, want %q: %s", k, got, want, test)
}
}
}
@@ -275,18 +275,18 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
if len(test.matches) != len(result) {
- t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
+ t.Errorf("got %d matches, want %d: %s", len(result), len(test.matches), test)
continue
}
for k, e := range test.matches {
- expect := test.text[e[0]:e[1]]
- if expect != result[k] {
- t.Errorf("expected %q got %q: %s", expect, result, test)
+ want := test.text[e[0]:e[1]]
+ if want != result[k] {
+ t.Errorf("got %q, want %q: %s", result[k], want, test)
}
}
}
@@ -298,17 +298,17 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %v, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
if len(test.matches) != len(result) {
- t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
+ t.Errorf("got %d matches, want %d: %s", len(result), len(test.matches), test)
return
}
for k, e := range test.matches {
if e[0] != result[k][0] || e[1] != result[k][1] {
- t.Errorf("match %d: expected %v got %v: %s", k, e, result[k], test)
+ t.Errorf("match %d: got %v, want %v: %s", k, result[k], e, test)
}
}
}
@@ -330,24 +330,24 @@

func testSubmatchBytes(test *FindTest, n int, submatches []int, result [][]byte, t *testing.T) {
if len(submatches) != len(result)*2 {
- t.Errorf("match %d: expected %d submatches; got %d: %s", n, len(submatches)/2, len(result), test)
+ t.Errorf("match %d: got %d submatches, want %d: %s", n, len(result), len(submatches)/2, test)
return
}
for k := 0; k < len(submatches); k += 2 {
if submatches[k] == -1 {
if result[k/2] != nil {
- t.Errorf("match %d: expected nil got %q: %s", n, result, test)
+ t.Errorf("match %d: got %q, want nil: %s", n, result, test)
}
continue
}
got := result[k/2]
if len(got) != cap(got) {
- t.Errorf("match %d: expected capacity %d got %d: %s", n, len(got), cap(got), test)
+ t.Errorf("match %d: got capacity %d, want %d: %s", n, cap(got), len(got), test)
return
}
- expect := test.text[submatches[k]:submatches[k+1]]
- if expect != string(got) {
- t.Errorf("match %d: expected %q got %q: %s", n, expect, got, test)
+ want := test.text[submatches[k]:submatches[k+1]]
+ if want != string(got) {
+ t.Errorf("match %d: got %q, want %q: %s", n, got, want, test)
return
}
}
@@ -360,9 +360,9 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
testSubmatchBytes(&test, 0, test.matches[0], result, t)
}
@@ -371,19 +371,19 @@

func testSubmatchString(test *FindTest, n int, submatches []int, result []string, t *testing.T) {
if len(submatches) != len(result)*2 {
- t.Errorf("match %d: expected %d submatches; got %d: %s", n, len(submatches)/2, len(result), test)
+ t.Errorf("match %d: got %d submatches, want %d: %s", n, len(result), len(submatches)/2, test)
return
}
for k := 0; k < len(submatches); k += 2 {
if submatches[k] == -1 {
if result[k/2] != "" {
- t.Errorf("match %d: expected nil got %q: %s", n, result, test)
+ t.Errorf("match %d: got %q, want empty string: %s", n, result, test)
}
continue
}
- expect := test.text[submatches[k]:submatches[k+1]]
- if expect != result[k/2] {
- t.Errorf("match %d: expected %q got %q: %s", n, expect, result, test)
+ want := test.text[submatches[k]:submatches[k+1]]
+ if want != result[k/2] {
+ t.Errorf("match %d: got %q, want %q: %s", n, result[k/2], want, test)
return
}
}
@@ -396,23 +396,23 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
testSubmatchString(&test, 0, test.matches[0], result, t)
}
}
}

-func testSubmatchIndices(test *FindTest, n int, expect, result []int, t *testing.T) {
- if len(expect) != len(result) {
- t.Errorf("match %d: expected %d matches; got %d: %s", n, len(expect)/2, len(result)/2, test)
+func testSubmatchIndices(test *FindTest, n int, want, result []int, t *testing.T) {
+ if len(want) != len(result) {
+ t.Errorf("match %d: got %d matches, want %d: %s", n, len(result)/2, len(want)/2, test)
return
}
- for k, e := range expect {
+ for k, e := range want {
if e != result[k] {
- t.Errorf("match %d: submatch error: expected %v got %v: %s", n, expect, result, test)
+ t.Errorf("match %d: submatch error: got %v, want %v: %s", n, result, want, test)
}
}
}
@@ -422,9 +422,9 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %v, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case test.matches != nil && result != nil:
testSubmatchIndices(test, 0, test.matches[0], result, t)
}
@@ -457,11 +457,11 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case len(test.matches) != len(result):
- t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
+ t.Errorf("got %d matches, want %d: %s", len(result), len(test.matches), test)
case test.matches != nil && result != nil:
for k, match := range test.matches {
testSubmatchBytes(&test, k, match, result[k], t)
@@ -477,11 +477,11 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %q, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case len(test.matches) != len(result):
- t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
+ t.Errorf("got %d matches, want %d: %s", len(result), len(test.matches), test)
case test.matches != nil && result != nil:
for k, match := range test.matches {
testSubmatchString(&test, k, match, result[k], t)
@@ -495,11 +495,11 @@
case test.matches == nil && result == nil:
// ok
case test.matches == nil && result != nil:
- t.Errorf("expected no match; got one: %s", test)
+ t.Errorf("got match %v, want none: %s", result, test)
case test.matches != nil && result == nil:
- t.Errorf("expected match; got none: %s", test)
+ t.Errorf("got no match, want one: %s", test)
case len(test.matches) != len(result):
- t.Errorf("expected %d matches; got %d: %s", len(test.matches), len(result), test)
+ t.Errorf("got %d matches, want %d: %s", len(result), len(test.matches), test)
case test.matches != nil && result != nil:
for k, match := range test.matches {
testSubmatchIndices(test, k, match, result[k], t)

Change information

Files:
  • M src/regexp/find_test.go
Change size: M
Delta: 1 file changed, 65 insertions(+), 65 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I17bfc60a06a879ce5e2c64d624c636e2c24135e9
Gerrit-Change-Number: 732780
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Jorge Pinto <jorg...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Dec 26, 2025, 11:56:15 AM (2 days ago) Dec 26
to Gerrit Bot, Jorge Pinto, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. You have a long 84 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
2. You usually need to reference a bug number for all but trivial or cosmetic fixes. For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message. Should you have a bug reference?

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I17bfc60a06a879ce5e2c64d624c636e2c24135e9
    Gerrit-Change-Number: 732780
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Jorge Pinto <jorg...@gmail.com>
    Gerrit-Comment-Date: Fri, 26 Dec 2025 16:56:11 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Jorge Pinto (Gerrit)

    unread,
    Dec 26, 2025, 11:58:03 AM (2 days ago) Dec 26
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, golang-co...@googlegroups.com

    Jorge Pinto added 1 comment

    Patchset-level comments
    Gopher Robot . resolved

    I spotted some possible problems with your PR:

      1. You have a long 84 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
    2. You usually need to reference a bug number for all but trivial or cosmetic fixes. For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message. Should you have a bug reference?

    Please address any problems by updating the GitHub PR.

    When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

    To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

    For more details, see:

    (In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

    Jorge Pinto

    Done

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I17bfc60a06a879ce5e2c64d624c636e2c24135e9
      Gerrit-Change-Number: 732780
      Gerrit-PatchSet: 1
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Jorge Pinto <jorg...@gmail.com>
      Gerrit-Comment-Date: Fri, 26 Dec 2025 16:57:59 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Gopher Robot <go...@golang.org>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Dec 26, 2025, 12:13:18 PM (2 days ago) Dec 26
      to Jorge Pinto, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Russ Cox

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #2 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Russ Cox
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I17bfc60a06a879ce5e2c64d624c636e2c24135e9
      Gerrit-Change-Number: 732780
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Jorge Pinto <jorg...@gmail.com>
      Gerrit-CC: Michael Matloob <mat...@golang.org>
      Gerrit-Attention: Russ Cox <r...@golang.org>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages