mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
test: compile source files as if from "test" module
This CL updates test/run.go to compile xxx.dir/x.go with a package path of "test/x" instead of just "x". This prevents collisions with standard library packages. It also requires updating a handful of tests to account for the updated package paths. Fixes #25693. Change-Id: I49208c56ab3cb229ed667d547cd6e004d2175fcf Reviewed-on: https://go-review.googlesource.com/c/go/+/395258 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
b2643c6739
commit
b95d332c7e
@ -1,10 +1,7 @@
|
|||||||
// +build !windows
|
// errorcheckdir
|
||||||
// errorcheckdir -n
|
|
||||||
|
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package ignored
|
package ignored
|
||||||
|
|
||||||
// TODO(ysmolsky): Fix golang.org/issue/25693 to enable on Windows.
|
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"./mysync"
|
|
||||||
"log"
|
"log"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"./mysync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -23,8 +24,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expecting := []string{
|
expecting := []string{
|
||||||
"mysync.(*WaitGroup).Add",
|
"test/mysync.(*WaitGroup).Add",
|
||||||
"mysync.(*WaitGroup).Done",
|
"test/mysync.(*WaitGroup).Done",
|
||||||
}
|
}
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
if frames[i].Function != expecting[i] {
|
if frames[i].Function != expecting[i] {
|
||||||
|
@ -51,14 +51,14 @@ func f() int {
|
|||||||
}
|
}
|
||||||
iter := runtime.CallersFrames(pcs[:n])
|
iter := runtime.CallersFrames(pcs[:n])
|
||||||
f, more := iter.Next()
|
f, more := iter.Next()
|
||||||
if f.Function != "a.f" || !strings.HasSuffix(f.File, "a.go") || f.Line != 22 {
|
if f.Function != "test/a.f" || !strings.HasSuffix(f.File, "a.go") || f.Line != 22 {
|
||||||
panic(fmt.Sprintf("bad f %v\n", f))
|
panic(fmt.Sprintf("bad f %v\n", f))
|
||||||
}
|
}
|
||||||
if !more {
|
if !more {
|
||||||
panic("traceback truncated after f")
|
panic("traceback truncated after f")
|
||||||
}
|
}
|
||||||
f, more = iter.Next()
|
f, more = iter.Next()
|
||||||
if f.Function != "a.init" || !strings.HasSuffix(f.File, "a.go") || f.Line != 15 {
|
if f.Function != "test/a.init" || !strings.HasSuffix(f.File, "a.go") || f.Line != 15 {
|
||||||
panic(fmt.Sprintf("bad init %v\n", f))
|
panic(fmt.Sprintf("bad init %v\n", f))
|
||||||
}
|
}
|
||||||
if !more {
|
if !more {
|
||||||
|
@ -5,11 +5,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"./a"
|
|
||||||
_ "unsafe"
|
_ "unsafe"
|
||||||
|
|
||||||
|
"./a"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:linkname s a.s
|
//go:linkname s test/a.s
|
||||||
var s string
|
var s string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package p
|
package p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"./a" // ERROR "imported and not used: \x22a\x22 as surprise|imported and not used: surprise"
|
"./a" // ERROR "imported and not used: \x22test/a\x22 as surprise|imported and not used: surprise"
|
||||||
"./b" // ERROR "imported and not used: \x22b\x22 as surprise2|imported and not used: surprise2"
|
"./b" // ERROR "imported and not used: \x22test/b\x22 as surprise2|imported and not used: surprise2"
|
||||||
b "./b" // ERROR "imported and not used: \x22b\x22$|imported and not used: surprise2"
|
b "./b" // ERROR "imported and not used: \x22test/b\x22$|imported and not used: surprise2"
|
||||||
foo "math" // ERROR "imported and not used: \x22math\x22 as foo|imported and not used: math"
|
foo "math" // ERROR "imported and not used: \x22math\x22 as foo|imported and not used: math"
|
||||||
"fmt" // actually used
|
"fmt" // actually used
|
||||||
"strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings"
|
"strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings"
|
||||||
|
@ -2,7 +2,7 @@ package y
|
|||||||
|
|
||||||
import _ "unsafe"
|
import _ "unsafe"
|
||||||
|
|
||||||
//go:linkname byteIndex linkname1.indexByte
|
//go:linkname byteIndex test/linkname1.indexByte
|
||||||
func byteIndex(xs []byte, b byte) int // ERROR "leaking param: xs"
|
func byteIndex(xs []byte, b byte) int // ERROR "leaking param: xs"
|
||||||
|
|
||||||
func ContainsSlash(data []byte) bool { // ERROR "leaking param: data" "can inline ContainsSlash"
|
func ContainsSlash(data []byte) bool { // ERROR "leaking param: data" "can inline ContainsSlash"
|
||||||
|
32
test/run.go
32
test/run.go
@ -263,14 +263,13 @@ func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, er
|
|||||||
return runcmd(cmd...)
|
return runcmd(cmd...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, pkgname string, names ...string) (out []byte, err error) {
|
func compileInDir(runcmd runCmd, dir string, flags []string, pkgname string, names ...string) (out []byte, err error) {
|
||||||
if pkgname != "main" {
|
cmd := []string{goTool(), "tool", "compile", "-e", "-D", "test", "-I", "."}
|
||||||
pkgname = strings.TrimSuffix(names[0], ".go")
|
if pkgname == "main" {
|
||||||
}
|
cmd = append(cmd, "-p=main")
|
||||||
cmd := []string{goTool(), "tool", "compile", "-e", "-p=" + pkgname}
|
} else {
|
||||||
if localImports {
|
pkgname = path.Join("test", strings.TrimSuffix(names[0], ".go"))
|
||||||
// Set relative path for local imports and import search path to current dir.
|
cmd = append(cmd, "-o", pkgname+".a", "-p", pkgname)
|
||||||
cmd = append(cmd, "-D", ".", "-I", ".")
|
|
||||||
}
|
}
|
||||||
cmd = append(cmd, flags...)
|
cmd = append(cmd, flags...)
|
||||||
if *linkshared {
|
if *linkshared {
|
||||||
@ -615,7 +614,6 @@ func (t *test) run() {
|
|||||||
wantError := false
|
wantError := false
|
||||||
wantAuto := false
|
wantAuto := false
|
||||||
singlefilepkgs := false
|
singlefilepkgs := false
|
||||||
localImports := true
|
|
||||||
f, err := splitQuoted(action)
|
f, err := splitQuoted(action)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.err = fmt.Errorf("invalid test recipe: %v", err)
|
t.err = fmt.Errorf("invalid test recipe: %v", err)
|
||||||
@ -659,12 +657,6 @@ func (t *test) run() {
|
|||||||
wantError = false
|
wantError = false
|
||||||
case "-s":
|
case "-s":
|
||||||
singlefilepkgs = true
|
singlefilepkgs = true
|
||||||
case "-n":
|
|
||||||
// Do not set relative path for local imports to current dir,
|
|
||||||
// e.g. do not pass -D . -I . to the compiler.
|
|
||||||
// Used in fixedbugs/bug345.go to allow compilation and import of local pkg.
|
|
||||||
// See golang.org/issue/25635
|
|
||||||
localImports = false
|
|
||||||
case "-t": // timeout in seconds
|
case "-t": // timeout in seconds
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
var err error
|
var err error
|
||||||
@ -886,7 +878,7 @@ func (t *test) run() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
_, t.err = compileInDir(runcmd, longdir, flags, localImports, pkg.name, pkg.files...)
|
_, t.err = compileInDir(runcmd, longdir, flags, pkg.name, pkg.files...)
|
||||||
if t.err != nil {
|
if t.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -910,7 +902,7 @@ func (t *test) run() {
|
|||||||
errPkg--
|
errPkg--
|
||||||
}
|
}
|
||||||
for i, pkg := range pkgs {
|
for i, pkg := range pkgs {
|
||||||
out, err := compileInDir(runcmd, longdir, flags, localImports, pkg.name, pkg.files...)
|
out, err := compileInDir(runcmd, longdir, flags, pkg.name, pkg.files...)
|
||||||
if i == errPkg {
|
if i == errPkg {
|
||||||
if wantError && err == nil {
|
if wantError && err == nil {
|
||||||
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
|
t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
|
||||||
@ -959,7 +951,7 @@ func (t *test) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, pkg := range pkgs {
|
for i, pkg := range pkgs {
|
||||||
_, err := compileInDir(runcmd, longdir, flags, localImports, pkg.name, pkg.files...)
|
_, err := compileInDir(runcmd, longdir, flags, pkg.name, pkg.files...)
|
||||||
// Allow this package compilation fail based on conditions below;
|
// Allow this package compilation fail based on conditions below;
|
||||||
// its errors were checked in previous case.
|
// its errors were checked in previous case.
|
||||||
if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) {
|
if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) {
|
||||||
@ -1283,6 +1275,10 @@ func (t *test) makeTempDir() {
|
|||||||
if *keep {
|
if *keep {
|
||||||
log.Printf("Temporary directory is %s", t.tempDir)
|
log.Printf("Temporary directory is %s", t.tempDir)
|
||||||
}
|
}
|
||||||
|
err = os.Mkdir(filepath.Join(t.tempDir, "test"), 0o755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkExpectedOutput compares the output from compiling and/or running with the contents
|
// checkExpectedOutput compares the output from compiling and/or running with the contents
|
||||||
|
Loading…
x
Reference in New Issue
Block a user