]> Cypherpunks repositories - gostls13.git/commitdiff
test: compile source files as if from "test" module
authorMatthew Dempsky <mdempsky@google.com>
Wed, 23 Mar 2022 21:24:26 +0000 (14:24 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 24 Mar 2022 17:50:47 +0000 (17:50 +0000)
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>

test/fixedbugs/bug345.go
test/fixedbugs/issue19467.dir/z.go
test/fixedbugs/issue29919.dir/a.go
test/fixedbugs/issue42401.dir/b.go
test/fixedbugs/issue5957.dir/c.go
test/linkname.dir/linkname2.go
test/run.go

index b974a61ffb2b393979d4bb6612d84eb802c4be69..d9349fb06fa45cd20f33768b8a792072b1484a6f 100644 (file)
@@ -1,10 +1,7 @@
-// +build !windows
-// errorcheckdir -n
+// errorcheckdir
 
 // Copyright 2011 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 ignored
-
-// TODO(ysmolsky): Fix golang.org/issue/25693 to enable on Windows.
index d381103ce7ef3f36d106018effce74e8e1c4cc07..cfbf34869cb7cd199974b44a2061ddecd0c98675 100644 (file)
@@ -5,9 +5,10 @@
 package main
 
 import (
-       "./mysync"
        "log"
        "runtime"
+
+       "./mysync"
 )
 
 func main() {
@@ -23,8 +24,8 @@ func main() {
                }
        }
        expecting := []string{
-               "mysync.(*WaitGroup).Add",
-               "mysync.(*WaitGroup).Done",
+               "test/mysync.(*WaitGroup).Add",
+               "test/mysync.(*WaitGroup).Done",
        }
        for i := 0; i < 2; i++ {
                if frames[i].Function != expecting[i] {
index 078f973b4b5c7048bb4fbd9c295c8785ecfd46c5..3b1dac40aab0ce3f0f07c47cd8d9e9491f80db6f 100644 (file)
@@ -51,14 +51,14 @@ func f() int {
        }
        iter := runtime.CallersFrames(pcs[:n])
        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))
        }
        if !more {
                panic("traceback truncated after f")
        }
        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))
        }
        if !more {
index a834f4efe8d96fd71996018ec0ed8c3e45923d95..fc675d82301881e94934c3b72f47ede071844f57 100644 (file)
@@ -5,11 +5,12 @@
 package main
 
 import (
-       "./a"
        _ "unsafe"
+
+       "./a"
 )
 
-//go:linkname s a.s
+//go:linkname s test/a.s
 var s string
 
 func main() {
index d115eacdd56420d852786e6f52411a8adea17e3c..821b37e4ca7abdafff7dad654e5a16c17a21f5df 100644 (file)
@@ -1,9 +1,9 @@
 package p
 
 import (
-       "./a" // ERROR "imported and not used: \x22a\x22 as surprise|imported and not used: surprise"
-       "./b" // ERROR "imported and not used: \x22b\x22 as surprise2|imported and not used: surprise2"
-       b "./b" // ERROR "imported and not used: \x22b\x22$|imported and not used: surprise2"
+       "./a" // ERROR "imported and not used: \x22test/a\x22 as surprise|imported and not used: surprise"
+       "./b" // ERROR "imported and not used: \x22test/b\x22 as surprise2|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"
        "fmt" // actually used
        "strings" // ERROR "imported and not used: \x22strings\x22|imported and not used: strings"
index 9323ac5f1ee28b78a6866adbcc1a4eb3b8e5dab2..d2ee841624b5995ac7f99c778ae0e60195715f93 100644 (file)
@@ -2,7 +2,7 @@ package y
 
 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 ContainsSlash(data []byte) bool { // ERROR "leaking param: data" "can inline ContainsSlash"
index e5dd0e443c8945bff26411ab19708fc6bf242776..61b31780d5550fc1ebc53cee05313306157e5c68 100644 (file)
@@ -263,14 +263,13 @@ func compileFile(runcmd runCmd, longname string, flags []string) (out []byte, er
        return runcmd(cmd...)
 }
 
-func compileInDir(runcmd runCmd, dir string, flags []string, localImports bool, pkgname string, names ...string) (out []byte, err error) {
-       if pkgname != "main" {
-               pkgname = strings.TrimSuffix(names[0], ".go")
-       }
-       cmd := []string{goTool(), "tool", "compile", "-e", "-p=" + pkgname}
-       if localImports {
-               // Set relative path for local imports and import search path to current dir.
-               cmd = append(cmd, "-D", ".", "-I", ".")
+func compileInDir(runcmd runCmd, dir string, flags []string, pkgname string, names ...string) (out []byte, err error) {
+       cmd := []string{goTool(), "tool", "compile", "-e", "-D", "test", "-I", "."}
+       if pkgname == "main" {
+               cmd = append(cmd, "-p=main")
+       } else {
+               pkgname = path.Join("test", strings.TrimSuffix(names[0], ".go"))
+               cmd = append(cmd, "-o", pkgname+".a", "-p", pkgname)
        }
        cmd = append(cmd, flags...)
        if *linkshared {
@@ -615,7 +614,6 @@ func (t *test) run() {
        wantError := false
        wantAuto := false
        singlefilepkgs := false
-       localImports := true
        f, err := splitQuoted(action)
        if err != nil {
                t.err = fmt.Errorf("invalid test recipe: %v", err)
@@ -659,12 +657,6 @@ func (t *test) run() {
                        wantError = false
                case "-s":
                        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
                        args = args[1:]
                        var err error
@@ -886,7 +878,7 @@ func (t *test) run() {
                        return
                }
                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 {
                                return
                        }
@@ -910,7 +902,7 @@ func (t *test) run() {
                        errPkg--
                }
                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 wantError && err == nil {
                                        t.err = fmt.Errorf("compilation succeeded unexpectedly\n%s", out)
@@ -959,7 +951,7 @@ func (t *test) run() {
                }
 
                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;
                        // its errors were checked in previous case.
                        if err != nil && !(wantError && action == "errorcheckandrundir" && i == len(pkgs)-2) {
@@ -1283,6 +1275,10 @@ func (t *test) makeTempDir() {
        if *keep {
                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