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 "log"
15 "os"
16 "os/exec"
17 "path/filepath"
18 "strings"
19 )
20
21 func main() {
22 f, err := os.CreateTemp("", "issue22660.go")
23 if err != nil {
24 log.Fatal(err)
25 }
26 f.Close()
27 defer os.Remove(f.Name())
28
29
30 path := filepath.Join("users", "xxx", "go")
31 filename := filepath.Join(path, "foo.go")
32 var src bytes.Buffer
33 fmt.Fprintf(&src, "//line %s:1\n", filename)
34 if err := os.WriteFile(f.Name(), src.Bytes(), 0660); err != nil {
35 log.Fatal(err)
36 }
37
38 out, err := exec.Command("go", "tool", "compile", "-p=p", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput()
39 if err == nil {
40
41 log.Fatalf("expected compiling %s to fail with syntax error", f.Name())
42 }
43
44
45
46
47
48 if !strings.Contains(string(out), string(filepath.Separator)+filename) {
49 log.Fatalf("expected full path and filename (%s) in error message, got:\n%s", filename, out)
50 }
51 }
52
View as plain text