1 // +build !nacl,!js,!wasip1
4 // Copyright 2018 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
8 // Ensure that label redefinition errors print out
9 // a column number that matches the start of the current label's
10 // definition instead of the label delimiting token ":"
26 tmpdir, err := ioutil.TempDir("", "issue26411")
28 log.Fatalf("Failed to create temporary directory: %v", err)
30 defer os.RemoveAll(tmpdir)
46 "^.+:5:1: label foo defined and not used\n",
47 ".+:6:1: label foo already defined at .+:5:1\n$",
64 "^.+:6:13: label bar defined and not used\n",
65 ".+:7:4: label bar already defined at .+:6:13\n",
66 ".+:8:1: label bar already defined at .+:6:13\n",
67 ".+:9:1: label bar already defined at .+:6:13\n$",
72 for i, test := range tests {
73 filename := filepath.Join(tmpdir, fmt.Sprintf("%d.go", i))
74 if err := ioutil.WriteFile(filename, []byte(test.code), 0644); err != nil {
75 log.Printf("#%d: failed to create file %s", i, filename)
78 output, _ := exec.Command("go", "tool", "compile", "-p=p", filename).CombinedOutput()
80 // remove each matching error from the output
81 for _, err := range test.errors {
82 rx := regexp.MustCompile(err)
83 match := rx.Find(output)
84 output = bytes.Replace(output, match, nil, 1) // remove match (which might be nil) from output
87 // at this point all output should have been consumed
89 log.Printf("Test case %d has unmatched errors:\n%s", i, output)