]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert TestLinkXImportPathEscape to the script framework
authorMichael Matloob <matloob@golang.org>
Mon, 13 Jan 2020 20:39:20 +0000 (15:39 -0500)
committerMichael Matloob <matloob@golang.org>
Thu, 27 Feb 2020 21:33:33 +0000 (21:33 +0000)
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: Ib386838081abad8bc6b01c1f0a4656553d0b6ff3
Reviewed-on: https://go-review.googlesource.com/c/go/+/214579
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/build_link_x_import_path_escape.txt [new file with mode: 0644]
src/cmd/go/testdata/src/my.pkg/main/main.go [deleted file]
src/cmd/go/testdata/src/my.pkg/pkg.go [deleted file]

index 8389f86b6e03f5662df184e38a51af71eea1ef95..9d9d898ae3444ffaaab6cf068cb3fcc87014647f 100644 (file)
@@ -317,7 +317,6 @@ var mtimeTick time.Duration = 1 * time.Second
 type testgoData struct {
        t              *testing.T
        temps          []string
-       wd             string
        env            []string
        tempdir        string
        ran            bool
@@ -367,9 +366,6 @@ func (tg *testgoData) parallel() {
        if tg.ran {
                tg.t.Fatal("internal testsuite error: call to parallel after run")
        }
-       if tg.wd != "" {
-               tg.t.Fatal("internal testsuite error: call to parallel after cd")
-       }
        for _, e := range tg.env {
                if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
                        val := e[strings.Index(e, "=")+1:]
@@ -680,15 +676,6 @@ func (tg *testgoData) creatingTemp(path string) {
        if filepath.IsAbs(path) && !strings.HasPrefix(path, tg.tempdir) {
                tg.t.Fatalf("internal testsuite error: creatingTemp(%q) with absolute path not in temporary directory", path)
        }
-       // If we have changed the working directory, make sure we have
-       // an absolute path, because we are going to change directory
-       // back before we remove the temporary.
-       if !filepath.IsAbs(path) {
-               if tg.wd == "" || strings.HasPrefix(tg.wd, testGOROOT) {
-                       tg.t.Fatalf("internal testsuite error: creatingTemp(%q) within GOROOT/src", path)
-               }
-               path = filepath.Join(tg.wd, path)
-       }
        tg.must(robustio.RemoveAll(path))
        tg.temps = append(tg.temps, path)
 }
@@ -842,16 +829,6 @@ var testWork = flag.Bool("testwork", false, "")
 // cleanup cleans up a test that runs testgo.
 func (tg *testgoData) cleanup() {
        tg.t.Helper()
-       if tg.wd != "" {
-               wd, _ := os.Getwd()
-               tg.t.Logf("ended in %s", wd)
-
-               if err := os.Chdir(tg.wd); err != nil {
-                       // We are unlikely to be able to continue.
-                       fmt.Fprintln(os.Stderr, "could not restore working directory, crashing:", err)
-                       os.Exit(2)
-               }
-       }
        if *testWork {
                tg.t.Logf("TESTWORK=%s\n", tg.path("."))
                return
@@ -2093,27 +2070,6 @@ const (
        okPattern        = `(?m)^ok`
 )
 
-func TestLinkXImportPathEscape(t *testing.T) {
-       // golang.org/issue/16710
-       skipIfGccgo(t, "gccgo does not support -ldflags -X")
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.parallel()
-       tg.makeTempdir()
-       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-       exe := tg.path("linkx" + exeSuffix)
-       tg.creatingTemp(exe)
-       tg.run("build", "-o", exe, "-ldflags", "-X=my.pkg.Text=linkXworked", "my.pkg/main")
-       out, err := exec.Command(exe).CombinedOutput()
-       if err != nil {
-               tg.t.Fatal(err)
-       }
-       if string(out) != "linkXworked\n" {
-               tg.t.Log(string(out))
-               tg.t.Fatal(`incorrect output: expected "linkXworked\n"`)
-       }
-}
-
 // Issue 18044.
 func TestLdBindNow(t *testing.T) {
        tg := testgo(t)
diff --git a/src/cmd/go/testdata/script/build_link_x_import_path_escape.txt b/src/cmd/go/testdata/script/build_link_x_import_path_escape.txt
new file mode 100644 (file)
index 0000000..daa544d
--- /dev/null
@@ -0,0 +1,18 @@
+[gccgo] skip 'gccgo does not support -ldflags -X'
+
+go build -o linkx$GOEXE -ldflags -X=my.pkg.Text=linkXworked my.pkg/main
+exec ./linkx$GOEXE
+stderr '^linkXworked$'
+
+-- my.pkg/main/main.go --
+package main
+
+import "my.pkg"
+
+func main() {
+       println(pkg.Text)
+}
+-- my.pkg/pkg.go --
+package pkg
+
+var Text = "unset"
diff --git a/src/cmd/go/testdata/src/my.pkg/main/main.go b/src/cmd/go/testdata/src/my.pkg/main/main.go
deleted file mode 100644 (file)
index c3e8de1..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package main
-
-import "my.pkg"
-
-func main() {
-       println(pkg.Text)
-}
diff --git a/src/cmd/go/testdata/src/my.pkg/pkg.go b/src/cmd/go/testdata/src/my.pkg/pkg.go
deleted file mode 100644 (file)
index 17702a6..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package pkg
-
-var Text = "unset"