1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:24:42 -07:00
go/test/fixedbugs/issue22660.go
griesemer ca2a886cba cmd/compile: record original and absolute file names for line directives
Also, with this change, error locations don't print absolute positions
in [] brackets following positions relative to line directives. To get
the absolute positions as well, specify the -L flag.

Fixes #22660.

Change-Id: I9ecfa254f053defba9c802222874155fa12fee2c
Reviewed-on: https://go-review.googlesource.com/77090
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2017-11-13 16:47:41 +00:00

51 lines
1.1 KiB
Go

// run
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
func main() {
if runtime.GOOS == "nacl" {
return // no file system available on builders
}
f, err := ioutil.TempFile("", "issue22660.go")
if err != nil {
log.Fatal(err)
}
f.Close()
defer os.Remove(f.Name())
// path must appear in error messages even if we strip them with -trimpath
path := filepath.Join("users", "xxx", "go")
var src bytes.Buffer
fmt.Fprintf(&src, "//line %s:1\n", filepath.Join(path, "foo.go"))
if err := ioutil.WriteFile(f.Name(), src.Bytes(), 0660); err != nil {
log.Fatal(err)
}
out, err := exec.Command("go", "tool", "compile", fmt.Sprintf("-trimpath=%s", path), f.Name()).CombinedOutput()
if err == nil {
log.Fatalf("expected compiling %s to fail", f.Name())
}
if !strings.HasPrefix(string(out), path) {
log.Fatalf("expected full path (%s) in error message, got:\n%s", path, out)
}
}