| 1 |
// +build !js,gc |
| 2 |
// run |
| 3 |
|
| 4 |
// Copyright 2017 The Go Authors. All rights reserved. |
| 5 |
// Use of this source code is governed by a BSD-style |
| 6 |
// license that can be found in the LICENSE file. |
| 7 |
|
| 8 |
// As of "Mon 6 Nov 2017", run.go doesn't yet have proper |
| 9 |
// column matching so instead match the output manually |
| 10 |
// by exec-ing |
| 11 |
|
| 12 |
package main |
| 13 |
|
| 14 |
import ( |
| 15 |
"fmt" |
| 16 |
"io/ioutil" |
| 17 |
"log" |
| 18 |
"os" |
| 19 |
"os/exec" |
| 20 |
"strings" |
| 21 |
) |
| 22 |
|
| 23 |
func main() { |
| 24 |
f, err := ioutil.TempFile("", "issue21317.go") |
| 25 |
if err != nil { |
| 26 |
log.Fatal(err) |
| 27 |
} |
| 28 |
fmt.Fprintf(f, ` |
| 29 |
package main |
| 30 |
|
| 31 |
import "fmt" |
| 32 |
|
| 33 |
func main() { |
| 34 |
n, err := fmt.Println(1) |
| 35 |
} |
| 36 |
`) |
| 37 |
f.Close() |
| 38 |
defer os.RemoveAll(f.Name()) |
| 39 |
|
| 40 |
// compile and test output |
| 41 |
cmd := exec.Command("go", "tool", "compile", f.Name()) |
| 42 |
out, err := cmd.CombinedOutput() |
| 43 |
if err == nil { |
| 44 |
log.Fatalf("expected cmd/compile to fail") |
| 45 |
} |
| 46 |
wantErrs := []string{ |
| 47 |
"7:9: n declared but not used", |
| 48 |
"7:12: err declared but not used", |
| 49 |
} |
| 50 |
outStr := string(out) |
| 51 |
for _, want := range wantErrs { |
| 52 |
if !strings.Contains(outStr, want) { |
| 53 |
log.Fatalf("failed to match %q\noutput: %q", want, outStr) |
| 54 |
} |
| 55 |
} |
| 56 |
} |