Source file
test/fixedbugs/issue21317.go
1
2
3
4
5
6
7
8
9
10
11
12
13 package main
14
15 import (
16 "fmt"
17 "io/ioutil"
18 "log"
19 "os"
20 "os/exec"
21 "strings"
22 )
23
24 func main() {
25 f, err := ioutil.TempFile("", "issue21317.go")
26 if err != nil {
27 log.Fatal(err)
28 }
29 fmt.Fprintf(f, `
30 package main
31
32 import "fmt"
33
34 func main() {
35 n, err := fmt.Println(1)
36 }
37 `)
38 f.Close()
39 defer os.RemoveAll(f.Name())
40
41
42 cmd := exec.Command("go", "tool", "compile", "-p=main", "-importcfg="+os.Getenv("STDLIB_IMPORTCFG"), f.Name())
43 out, err := cmd.CombinedOutput()
44 if err == nil {
45 log.Fatalf("expected cmd/compile to fail")
46 }
47 wantErrs := []string{
48 "7:9: declared and not used: n",
49 "7:12: declared and not used: err",
50 }
51 outStr := string(out)
52 for _, want := range wantErrs {
53 if !strings.Contains(outStr, want) {
54 log.Fatalf("failed to match %q\noutput: %q", want, outStr)
55 }
56 }
57 }
58
View as plain text