Source file
test/fixedbugs/issue22662b.go
1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import (
14 "io/ioutil"
15 "log"
16 "os"
17 "os/exec"
18 "strings"
19 )
20
21
22
23 var tests = []struct {
24 src, pos string
25 }{
26 {"//line :10\n", ":10:"},
27 {"//line :10:4\n", "filename:10:4"},
28 {"//line foo.go:10\n", "foo.go:10:"},
29 {"//line foo.go:10:4\n", "foo.go:10:4:"},
30 {"//line foo.go:10:4\n\n", "foo.go:11:1:"},
31
32 {"/*line :10*/", ":10:"},
33 {"/*line :10:4*/", "filename:10:4"},
34 {"/*line foo.go:10*/", "foo.go:10:"},
35 {"/*line foo.go:10:4*/", "foo.go:10:4:"},
36 {"/*line foo.go:10:4*/\n", "foo.go:11:1:"},
37 }
38
39 func main() {
40 f, err := ioutil.TempFile("", "issue22662b.go")
41 if err != nil {
42 log.Fatal(err)
43 }
44 f.Close()
45 defer os.Remove(f.Name())
46
47 for _, test := range tests {
48 if err := ioutil.WriteFile(f.Name(), []byte(test.src), 0660); err != nil {
49 log.Fatal(err)
50 }
51
52 out, err := exec.Command("go", "tool", "compile", "-p=p", f.Name()).CombinedOutput()
53 if err == nil {
54 log.Fatalf("expected compiling\n---\n%s\n---\nto fail", test.src)
55 }
56
57 errmsg := strings.Replace(string(out), f.Name(), "filename", -1)
58 if !strings.HasPrefix(errmsg, test.pos) {
59 log.Fatalf("%q: got %q; want position %q", test.src, errmsg, test.pos)
60 }
61 }
62 }
63
View as plain text