1
0
mirror of https://github.com/golang/go synced 2024-11-12 12:50:28 -07:00
go/test/fixedbugs/issue22660.go
Ian Lance Taylor f1778c28a9 test: recognize and use gc build tag
Change the run.go driver to recognize the "gc" build tag.

Change existing tests to use the "gc" build tag if they use some
feature that seems specific to the gc compiler, such as passing specific
options to or expecting specific behavior from "go tool compile".
Change tests to use the "!gccgo" build tag if they use "go build" or
"go run", as while those might work with compilers other than gc, they
won't work with the way that gccgo runs its testsuite (which happens
independently of the go command).

For #43252

Change-Id: I666e04b6d7255a77dfc256ee304094e3a6bb15ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/279052
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-12-18 00:10:44 +00:00

47 lines
1.0 KiB
Go

// +build !js,gc
// 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"
"strings"
)
func main() {
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)
}
}