Debian Codegraph @

test/fixedbugs/issue21317.go

raw
1 // run
2
3 //go:build !js && !wasip1 && gc
4
5 // Copyright 2017 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
8
9 // As of "Mon 6 Nov 2017", run.go doesn't yet have proper
10 // column matching so instead match the output manually
11 // by exec-ing
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 // compile and test output
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 }