From b003ee499a97f28a1328a8eaeb380596fad5788b Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 6 Dec 2022 14:43:39 -0800 Subject: internal/types: consistently use double quotes around ERROR patterns Before matching the pattern, the double quotes are simply stripped (no Go string unquoting) for now. This is a first step towards use of proper Go strings as ERROR patterns. The changes were obtained through a couple of global regexp find/replace commands: /\* ERROR ([^"]+) \*/ => /* ERROR "$1" */ // ERROR ([^"]+)$ => // ERROR "$1" followed up by manual fixes where multiple "/* ERROR"-style errors appeared on the same line (in that case, the first regexp matches the first and last ERROR). For #51006. Change-Id: Ib92c2d5e339075aeec1ea74c339b5fecf953d1a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/455718 Auto-Submit: Robert Griesemer Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/check_test.go | 8 +++++++- src/cmd/compile/internal/types2/testdata/local/issue47996.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/cmd/compile') diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go index 611466ba01..6825133048 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -196,8 +196,14 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) { indices = indices[:0] for i, want := range errList { pattern := strings.TrimSpace(want.Msg[len(" ERROR "):]) + // We expect all patterns to be quoted in double quotes + // and then we remove the quotes. + // TODO(gri) use correct strconv.Unquote eventually if n := len(pattern); n >= 2 && pattern[0] == '"' && pattern[n-1] == '"' { pattern = pattern[1 : n-1] + } else { + t.Errorf("%s:%d:%d: unquoted pattern: %s", filename, line, want.Pos.Col(), pattern) + continue } rx, err := regexp.Compile(pattern) if err != nil { @@ -303,7 +309,7 @@ func TestCheck(t *testing.T) { } func TestSpec(t *testing.T) { testDirFiles(t, "../../../../internal/types/testdata/spec", 0, false) } func TestExamples(t *testing.T) { - testDirFiles(t, "../../../../internal/types/testdata/examples", 45, false) + testDirFiles(t, "../../../../internal/types/testdata/examples", 50, false) } // TODO(gri) narrow column tolerance func TestFixedbugs(t *testing.T) { testDirFiles(t, "../../../../internal/types/testdata/fixedbugs", 100, false) diff --git a/src/cmd/compile/internal/types2/testdata/local/issue47996.go b/src/cmd/compile/internal/types2/testdata/local/issue47996.go index 2c4b6610fe..6fb50a611b 100644 --- a/src/cmd/compile/internal/types2/testdata/local/issue47996.go +++ b/src/cmd/compile/internal/types2/testdata/local/issue47996.go @@ -5,4 +5,4 @@ package p // don't crash -func T /* ERROR missing */ [P] /* ERROR missing */ m /* ERROR unexpected */ () /* ERROR \) */ { /* ERROR { */ } /* ERROR } */ +func T /* ERROR "missing" */ [P] /* ERROR "missing" */ m /* ERROR "unexpected" */ () /* ERROR "\)" */ { /* ERROR "{" */ } /* ERROR "}" */ -- cgit v1.3