]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: better error message for invalid ERROR pattern in tests
authorRobert Griesemer <gri@golang.org>
Wed, 22 May 2024 17:26:49 +0000 (10:26 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 22 May 2024 19:45:33 +0000 (19:45 +0000)
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>
src/cmd/compile/internal/types2/check_test.go
src/go/types/check_test.go

index 63f831aa920a704c799ab9e46d49933fe669f93e..8b7b5316f04a842be5d3f24516eb92e063f43b84 100644 (file)
@@ -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
index 6ad7ef3a27b6810fafb3c23e538a2807c263a226..6c523b5d9ce848cb2edb62a4edd4f881c9985c16 100644 (file)
@@ -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