| 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 |
package main |
| 9 |
|
| 10 |
import ( |
| 11 |
"bytes" |
| 12 |
"fmt" |
| 13 |
"io/ioutil" |
| 14 |
"log" |
| 15 |
"os" |
| 16 |
"os/exec" |
| 17 |
"path/filepath" |
| 18 |
"strings" |
| 19 |
) |
| 20 |
|
| 21 |
func main() { |
| 22 |
f, err := ioutil.TempFile("", "issue22660.go") |
| 23 |
if err != nil { |
| 24 |
log.Fatal(err) |
| 25 |
} |
| 26 |
f.Close() |
| 27 |
defer os.Remove(f.Name()) |
| 28 |
|
| 29 |
// path must appear in error messages even if we strip them with -trimpath |
| 30 |
path := filepath.Join("users", "xxx", "go") |
| 31 |
var src bytes.Buffer |
| 32 |
fmt.Fprintf(&src, "//line %s:1\n", filepath.Join(path, "foo.go")) |
| 33 |
|
| 34 |
if err := ioutil.WriteFile(f.Name(), src.Bytes(), 0660); err != nil { |
| 35 |
log.Fatal(err) |
| 36 |
} |
| 37 |
|
| 38 |
out, err := exec.Command("go", "tool", "compile", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput() |
| 39 |
if err == nil { |
| 40 |
log.Fatalf("expected compiling %s to fail", f.Name()) |
| 41 |
} |
| 42 |
|
| 43 |
if !strings.HasPrefix(string(out), path) { |
| 44 |
log.Fatalf("expected full path (%s) in error message, got:\n%s", path, out) |
| 45 |
} |
| 46 |
} |