mirror of https://github.com/golang/go.git
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
8d464e4ae3
commit
6861b2eff5
|
|
@ -247,17 +247,17 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, colDelta uin
|
|||
panic("unreachable")
|
||||
}
|
||||
}
|
||||
pattern, err := strconv.Unquote(strings.TrimSpace(pattern))
|
||||
unquoted, err := strconv.Unquote(strings.TrimSpace(pattern))
|
||||
if err != nil {
|
||||
t.Errorf("%s:%d:%d: %v", filename, line, want.Pos.Col(), err)
|
||||
t.Errorf("%s:%d:%d: invalid ERROR pattern (cannot unquote %s)", filename, line, want.Pos.Col(), pattern)
|
||||
continue
|
||||
}
|
||||
if substr {
|
||||
if !strings.Contains(gotMsg, pattern) {
|
||||
if !strings.Contains(gotMsg, unquoted) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
rx, err := regexp.Compile(pattern)
|
||||
rx, err := regexp.Compile(unquoted)
|
||||
if err != nil {
|
||||
t.Errorf("%s:%d:%d: %v", filename, line, want.Pos.Col(), err)
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -262,17 +262,17 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, manual bool,
|
|||
panic("unreachable")
|
||||
}
|
||||
}
|
||||
pattern, err := strconv.Unquote(strings.TrimSpace(pattern))
|
||||
unquoted, err := strconv.Unquote(strings.TrimSpace(pattern))
|
||||
if err != nil {
|
||||
t.Errorf("%s:%d:%d: %v", filename, line, want.col, err)
|
||||
t.Errorf("%s:%d:%d: invalid ERROR pattern (cannot unquote %s)", filename, line, want.col, pattern)
|
||||
continue
|
||||
}
|
||||
if substr {
|
||||
if !strings.Contains(gotMsg, pattern) {
|
||||
if !strings.Contains(gotMsg, unquoted) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
rx, err := regexp.Compile(pattern)
|
||||
rx, err := regexp.Compile(unquoted)
|
||||
if err != nil {
|
||||
t.Errorf("%s:%d:%d: %v", filename, line, want.col, err)
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in New Issue