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 9package main 10 11import ( 12 "bytes" 13 "fmt" 14 "io/ioutil" 15 "log" 16 "os" 17 "os/exec" 18 "path/filepath" 19 "strings" 20) 21 22func 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 // path must appear in error messages even if we strip them with -trimpath 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