Skip to content

Commit 6861b2e

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: better error message for invalid ERROR pattern in tests
When unquoting of an ERROR or ERRORx pattern fails, say so instead of simply printing "syntax error". Change-Id: I586dffa86ca80f5b40a5cbe16a7005cc1f7862f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/586958 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 8d464e4 commit 6861b2e

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Diff for: src/cmd/compile/internal/types2/check_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,17 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, colDelta uin
247247
panic("unreachable")
248248
}
249249
}
250-
pattern, err := strconv.Unquote(strings.TrimSpace(pattern))
250+
unquoted, err := strconv.Unquote(strings.TrimSpace(pattern))
251251
if err != nil {
252-
t.Errorf("%s:%d:%d: %v", filename, line, want.Pos.Col(), err)
252+
t.Errorf("%s:%d:%d: invalid ERROR pattern (cannot unquote %s)", filename, line, want.Pos.Col(), pattern)
253253
continue
254254
}
255255
if substr {
256-
if !strings.Contains(gotMsg, pattern) {
256+
if !strings.Contains(gotMsg, unquoted) {
257257
continue
258258
}
259259
} else {
260-
rx, err := regexp.Compile(pattern)
260+
rx, err := regexp.Compile(unquoted)
261261
if err != nil {
262262
t.Errorf("%s:%d:%d: %v", filename, line, want.Pos.Col(), err)
263263
continue

Diff for: src/go/types/check_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,17 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, manual bool,
262262
panic("unreachable")
263263
}
264264
}
265-
pattern, err := strconv.Unquote(strings.TrimSpace(pattern))
265+
unquoted, err := strconv.Unquote(strings.TrimSpace(pattern))
266266
if err != nil {
267-
t.Errorf("%s:%d:%d: %v", filename, line, want.col, err)
267+
t.Errorf("%s:%d:%d: invalid ERROR pattern (cannot unquote %s)", filename, line, want.col, pattern)
268268
continue
269269
}
270270
if substr {
271-
if !strings.Contains(gotMsg, pattern) {
271+
if !strings.Contains(gotMsg, unquoted) {
272272
continue
273273
}
274274
} else {
275-
rx, err := regexp.Compile(pattern)
275+
rx, err := regexp.Compile(unquoted)
276276
if err != nil {
277277
t.Errorf("%s:%d:%d: %v", filename, line, want.col, err)
278278
continue

0 commit comments

Comments
 (0)