Source file
test/fixedbugs/issue52127.go
1
2
3
4
5
6
7
8
9
10
11
12
13 package main
14
15 import (
16 "bytes"
17 "fmt"
18 "os"
19 "os/exec"
20 "path/filepath"
21 )
22
23 func main() {
24 dir, err := os.MkdirTemp("", "issue52127")
25 if err != nil {
26 panic(err)
27 }
28 defer os.RemoveAll(dir)
29
30 args := []string{"go", "build"}
31 write := func(prefix string, i int, data string) {
32 filename := filepath.Join(dir, fmt.Sprintf("%s%d.go", prefix, i))
33 if err := os.WriteFile(filename, []byte(data), 0o644); err != nil {
34 panic(err)
35 }
36 args = append(args, filename)
37 }
38
39 for i := 0; i < 100; i++ {
40 write("a", i, `package p
41 `)
42 }
43 for i := 0; i < 100; i++ {
44 write("b", i, `package p
45 var
46 var
47 var
48 var
49 var
50 `)
51 }
52
53 cmd := exec.Command(args[0], args[1:]...)
54 output, err := cmd.CombinedOutput()
55 if err == nil {
56 panic("compile succeeded unexpectedly")
57 }
58 if !bytes.Contains(output, []byte("syntax error:")) {
59 panic(fmt.Sprintf(`missing "syntax error" in compiler output; got:
60 %s`, output))
61 }
62 }
View as plain text