Source file
test/fixedbugs/issue22660.go
1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "bytes"
13 "fmt"
14 "io/ioutil"
15 "log"
16 "os"
17 "os/exec"
18 "path/filepath"
19 "strings"
20 )
21
22 func main() {
23 f, err := ioutil.TempFile("", "issue22660.go")
24 if err != nil {
25 log.Fatal(err)
26 }
27 f.Close()
28 defer os.Remove(f.Name())
29
30
31 path := filepath.Join("users", "xxx", "go")
32 var src bytes.Buffer
33 fmt.Fprintf(&src, "//line %s:1\n", filepath.Join(path, "foo.go"))
34
35 if err := ioutil.WriteFile(f.Name(), src.Bytes(), 0660); err != nil {
36 log.Fatal(err)
37 }
38
39 out, err := exec.Command("go", "tool", "compile", "-p=p", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput()
40 if err == nil {
41 log.Fatalf("expected compiling %s to fail", f.Name())
42 }
43
44 if !strings.HasPrefix(string(out), path) {
45 log.Fatalf("expected full path (%s) in error message, got:\n%s", path, out)
46 }
47 }
48
View as plain text