summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/issue22662b.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
commitccd992355df7192993c666236047820244914598 (patch)
treef00fea65147227b7743083c6148396f74cd66935 /test/fixedbugs/issue22662b.go
parentInitial commit. (diff)
downloadgolang-1.21-ccd992355df7192993c666236047820244914598.tar.xz
golang-1.21-ccd992355df7192993c666236047820244914598.zip
Adding upstream version 1.21.8.upstream/1.21.8
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/fixedbugs/issue22662b.go')
-rw-r--r--test/fixedbugs/issue22662b.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/fixedbugs/issue22662b.go b/test/fixedbugs/issue22662b.go
new file mode 100644
index 0000000..c7a1e05
--- /dev/null
+++ b/test/fixedbugs/issue22662b.go
@@ -0,0 +1,61 @@
+// +build !js,!wasip1,gc
+// run
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Verify the impact of line directives on error positions and position formatting.
+
+package main
+
+import (
+ "io/ioutil"
+ "log"
+ "os"
+ "os/exec"
+ "strings"
+)
+
+// Each of these tests is expected to fail (missing package clause)
+// at the position determined by the preceding line directive.
+var tests = []struct {
+ src, pos string
+}{
+ {"//line :10\n", ":10:"}, // no filename means no filename
+ {"//line :10:4\n", "filename:10:4"}, // no filename means use existing filename
+ {"//line foo.go:10\n", "foo.go:10:"}, // no column means don't print a column
+ {"//line foo.go:10:4\n", "foo.go:10:4:"}, // column means print a column
+ {"//line foo.go:10:4\n\n", "foo.go:11:1:"}, // relative columns start at 1 after newline
+
+ {"/*line :10*/", ":10:"},
+ {"/*line :10:4*/", "filename:10:4"},
+ {"/*line foo.go:10*/", "foo.go:10:"},
+ {"/*line foo.go:10:4*/", "foo.go:10:4:"},
+ {"/*line foo.go:10:4*/\n", "foo.go:11:1:"},
+}
+
+func main() {
+ f, err := ioutil.TempFile("", "issue22662b.go")
+ if err != nil {
+ log.Fatal(err)
+ }
+ f.Close()
+ defer os.Remove(f.Name())
+
+ for _, test := range tests {
+ if err := ioutil.WriteFile(f.Name(), []byte(test.src), 0660); err != nil {
+ log.Fatal(err)
+ }
+
+ out, err := exec.Command("go", "tool", "compile", "-p=p", f.Name()).CombinedOutput()
+ if err == nil {
+ log.Fatalf("expected compiling\n---\n%s\n---\nto fail", test.src)
+ }
+
+ errmsg := strings.Replace(string(out), f.Name(), "filename", -1) // use "filename" instead of actual (long) filename
+ if !strings.HasPrefix(errmsg, test.pos) {
+ log.Fatalf("%q: got %q; want position %q", test.src, errmsg, test.pos)
+ }
+ }
+}