]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert tests using testdata/testimport dir to script framework
authorMichael Matloob <matloob@golang.org>
Wed, 8 Jan 2020 18:25:08 +0000 (13:25 -0500)
committerMichael Matloob <matloob@golang.org>
Wed, 19 Feb 2020 20:49:24 +0000 (20:49 +0000)
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: I3773508310865b198bc5f06dfc5ee7e34e92cdd0
Reviewed-on: https://go-review.googlesource.com/c/go/+/213818
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/test_relative_cmdline.txt [new file with mode: 0644]
src/cmd/go/testdata/script/test_relative_import.txt [new file with mode: 0644]
src/cmd/go/testdata/script/test_relative_import_dash_i.txt [new file with mode: 0644]
src/cmd/go/testdata/testimport/p.go [deleted file]
src/cmd/go/testdata/testimport/p1/p1.go [deleted file]
src/cmd/go/testdata/testimport/p2/p2.go [deleted file]
src/cmd/go/testdata/testimport/p_test.go [deleted file]
src/cmd/go/testdata/testimport/x_test.go [deleted file]

index 57a5bb8f5a70aca92671ca0d5883e3772d03e4a0..46c2a3e2a708b6893dd70f355abe50c81bcd145e 100644 (file)
@@ -1146,31 +1146,6 @@ func TestAccidentalGitCheckout(t *testing.T) {
        }
 }
 
-func TestRelativeImportsGoTest(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.run("test", "./testdata/testimport")
-}
-
-func TestRelativeImportsGoTestDashI(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-
-       // don't let test -i overwrite runtime
-       tg.wantNotStale("runtime", "", "must be non-stale before test -i")
-
-       tg.run("test", "-i", "./testdata/testimport")
-}
-
-func TestRelativeImportsInCommandLinePackage(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-       // TODO: tg.parallel()
-       files, err := filepath.Glob("./testdata/testimport/*.go")
-       tg.must(err)
-       tg.run(append([]string{"test"}, files...)...)
-}
-
 func TestVersionControlErrorMessageIncludesCorrectDirectory(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
diff --git a/src/cmd/go/testdata/script/test_relative_cmdline.txt b/src/cmd/go/testdata/script/test_relative_cmdline.txt
new file mode 100644 (file)
index 0000000..2f9c80f
--- /dev/null
@@ -0,0 +1,50 @@
+# Relative imports in command line package
+
+# Run tests outside GOPATH.
+env GOPATH=$WORK/tmp
+
+go test ./testimport/p.go ./testimport/p_test.go ./testimport/x_test.go
+stdout '^ok'
+
+-- testimport/p.go --
+package p
+
+func F() int { return 1 }
+-- testimport/p1/p1.go --
+package p1
+
+func F() int { return 1 }
+-- testimport/p2/p2.go --
+package p2
+
+func F() int { return 1 }
+-- testimport/p_test.go --
+package p
+
+import (
+       "./p1"
+
+       "testing"
+)
+
+func TestF(t *testing.T) {
+       if F() != p1.F() {
+               t.Fatal(F())
+       }
+}
+-- testimport/x_test.go --
+package p_test
+
+import (
+       . "../testimport"
+
+       "./p2"
+
+       "testing"
+)
+
+func TestF1(t *testing.T) {
+       if F() != p2.F() {
+               t.Fatal(F())
+       }
+}
\ No newline at end of file
diff --git a/src/cmd/go/testdata/script/test_relative_import.txt b/src/cmd/go/testdata/script/test_relative_import.txt
new file mode 100644 (file)
index 0000000..0d212b4
--- /dev/null
@@ -0,0 +1,30 @@
+# Relative imports in go test
+
+# Run tests outside GOPATH.
+env GOPATH=$WORK/tmp
+
+go test ./testimport
+stdout '^ok'
+
+-- testimport/p.go --
+package p
+
+func F() int { return 1 }
+-- testimport/p1/p1.go --
+package p1
+
+func F() int { return 1 }
+-- testimport/p_test.go --
+package p
+
+import (
+       "./p1"
+
+       "testing"
+)
+
+func TestF(t *testing.T) {
+       if F() != p1.F() {
+               t.Fatal(F())
+       }
+}
\ No newline at end of file
diff --git a/src/cmd/go/testdata/script/test_relative_import_dash_i.txt b/src/cmd/go/testdata/script/test_relative_import_dash_i.txt
new file mode 100644 (file)
index 0000000..dafa04e
--- /dev/null
@@ -0,0 +1,31 @@
+# Relative imports in go test -i
+
+# Run tests outside GOPATH.
+env GOPATH=$WORK/tmp
+
+# Check that it's safe to pass -i (which installs dependencies in $GOPATH/pkg) to go test.
+! stale runtime # don't let test -i overwrite runtime
+go test -i ./testimport
+
+-- testimport/p.go --
+package p
+
+func F() int { return 1 }
+-- testimport/p1/p1.go --
+package p1
+
+func F() int { return 1 }
+-- testimport/p_test.go --
+package p
+
+import (
+       "./p1"
+
+       "testing"
+)
+
+func TestF(t *testing.T) {
+       if F() != p1.F() {
+               t.Fatal(F())
+       }
+}
\ No newline at end of file
diff --git a/src/cmd/go/testdata/testimport/p.go b/src/cmd/go/testdata/testimport/p.go
deleted file mode 100644 (file)
index f94d2cd..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package p
-
-func F() int { return 1 }
diff --git a/src/cmd/go/testdata/testimport/p1/p1.go b/src/cmd/go/testdata/testimport/p1/p1.go
deleted file mode 100644 (file)
index fd31527..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package p1
-
-func F() int { return 1 }
diff --git a/src/cmd/go/testdata/testimport/p2/p2.go b/src/cmd/go/testdata/testimport/p2/p2.go
deleted file mode 100644 (file)
index d488886..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package p2
-
-func F() int { return 1 }
diff --git a/src/cmd/go/testdata/testimport/p_test.go b/src/cmd/go/testdata/testimport/p_test.go
deleted file mode 100644 (file)
index a3fb4a9..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-package p
-
-import (
-       "./p1"
-
-       "testing"
-)
-
-func TestF(t *testing.T) {
-       if F() != p1.F() {
-               t.Fatal(F())
-       }
-}
diff --git a/src/cmd/go/testdata/testimport/x_test.go b/src/cmd/go/testdata/testimport/x_test.go
deleted file mode 100644 (file)
index b253e3f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-package p_test
-
-import (
-       . "../testimport"
-
-       "./p2"
-
-       "testing"
-)
-
-func TestF1(t *testing.T) {
-       if F() != p2.F() {
-               t.Fatal(F())
-       }
-}