From: Michael Matloob Date: Thu, 9 Jan 2020 20:22:10 +0000 (-0500) Subject: cmd/go: convert tests using testdata/src/(exclude|empty) to script framework X-Git-Tag: go1.15beta1~1209 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f08734dd72f27917263b5b8c04b40373beb73095;p=gostls13.git cmd/go: convert tests using testdata/src/(exclude|empty) to script framework Part of converting all tests to script framework to improve test parallelism. Updates #36320 Updates #17751 Change-Id: Icc14d4188574badf3da71d34857616f2a2ad5862 Reviewed-on: https://go-review.googlesource.com/c/go/+/214138 Reviewed-by: Jay Conrod --- diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index f19fcf90a0..6955236e78 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1974,69 +1974,6 @@ func TestCoverageRuns(t *testing.T) { checkCoverage(tg, data) } -func TestTestEmpty(t *testing.T) { - if !canRace { - t.Skip("no race detector") - } - - wd, _ := os.Getwd() - testdata := filepath.Join(wd, "testdata") - for _, dir := range []string{"pkg", "test", "xtest", "pkgtest", "pkgxtest", "pkgtestxtest", "testxtest"} { - t.Run(dir, func(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", testdata) - tg.cd(filepath.Join(testdata, "src/empty/"+dir)) - tg.run("test", "-cover", "-coverpkg=.", "-race") - }) - if testing.Short() { - break - } - } -} - -func TestNoGoError(t *testing.T) { - wd, _ := os.Getwd() - testdata := filepath.Join(wd, "testdata") - for _, dir := range []string{"empty/test", "empty/xtest", "empty/testxtest", "exclude", "exclude/ignore", "exclude/empty"} { - t.Run(dir, func(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", testdata) - tg.cd(filepath.Join(testdata, "src")) - tg.runFail("build", "./"+dir) - var want string - if strings.Contains(dir, "test") { - want = "no non-test Go files in " - } else if dir == "exclude" { - want = "build constraints exclude all Go files in " - } else { - want = "no Go files in " - } - tg.grepStderr(want, "wrong reason for failure") - }) - } -} - -func TestTestRaceInstall(t *testing.T) { - if !canRace { - t.Skip("no race detector") - } - tooSlow(t) - - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - - tg.tempDir("pkg") - pkgdir := tg.path("pkg") - tg.run("install", "-race", "-pkgdir="+pkgdir, "std") - tg.run("test", "-race", "-pkgdir="+pkgdir, "-i", "-v", "empty/pkg") - if tg.getStderr() != "" { - t.Error("go test -i -race: rebuilds cached packages") - } -} - func TestBuildDryRunWithCgo(t *testing.T) { if !canCgo { t.Skip("skipping because cgo not enabled") @@ -3548,16 +3485,6 @@ func TestExecBuildX(t *testing.T) { tg.must(robustio.RemoveAll(matches[1])) } -func TestWrongGOOSErrorBeforeLoadError(t *testing.T) { - skipIfGccgo(t, "gccgo assumes cross-compilation is always possible") - tg := testgo(t) - defer tg.cleanup() - tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) - tg.setenv("GOOS", "windwos") - tg.runFail("build", "exclude") - tg.grepStderr("unsupported GOOS/GOARCH pair", "GOOS=windwos go build exclude did not report 'unsupported GOOS/GOARCH pair'") -} - func TestUpxCompression(t *testing.T) { if runtime.GOOS != "linux" || (runtime.GOARCH != "amd64" && runtime.GOARCH != "386") { diff --git a/src/cmd/go/testdata/script/build_no_go.txt b/src/cmd/go/testdata/script/build_no_go.txt new file mode 100644 index 0000000000..3fd7739fbb --- /dev/null +++ b/src/cmd/go/testdata/script/build_no_go.txt @@ -0,0 +1,37 @@ +! go build ./empty/test +stderr 'no non-test Go files in ' + +! go build ./empty/xtest +stderr 'no non-test Go files in ' + +! go build ./empty/testxtest +stderr 'no non-test Go files in ' + +! go build ./exclude +stderr 'build constraints exclude all Go files in ' + +! go build ./exclude/ignore +stderr 'no Go files in ' + +! go build ./exclude/empty +stderr 'no Go files in ' + +-- empty/test/test_test.go -- +package p +-- empty/testxtest/test_test.go -- +package p +-- empty/testxtest/xtest_test.go -- +package p_test +-- empty/xtest/xtest_test.go -- +package p_test +-- exclude/empty/x.txt -- +-- exclude/ignore/_x.go -- +package x +-- exclude/x.go -- +// +build linux,!linux + +package x +-- exclude/x_linux.go -- +// +build windows + +package x diff --git a/src/cmd/go/testdata/script/build_unsupported_goos.txt b/src/cmd/go/testdata/script/build_unsupported_goos.txt new file mode 100644 index 0000000000..d61e420279 --- /dev/null +++ b/src/cmd/go/testdata/script/build_unsupported_goos.txt @@ -0,0 +1,6 @@ +[gccgo] skip # gccgo assumes cross-compilation is always possible + +env GOOS=windwos + +! go build -n exclude +stderr 'unsupported GOOS/GOARCH pair' \ No newline at end of file diff --git a/src/cmd/go/testdata/script/test_empty.txt b/src/cmd/go/testdata/script/test_empty.txt new file mode 100644 index 0000000000..f2c512e791 --- /dev/null +++ b/src/cmd/go/testdata/script/test_empty.txt @@ -0,0 +1,49 @@ +[!race] skip + +cd $GOPATH/src/empty/pkg +go test -cover -coverpkg=. -race + +[short] stop # Only run first case in short mode + +cd $GOPATH/src/empty/test +go test -cover -coverpkg=. -race + +cd $GOPATH/src/empty/xtest +go test -cover -coverpkg=. -race + +cd $GOPATH/src/empty/pkgtest +go test -cover -coverpkg=. -race + +cd $GOPATH/src/empty/pkgxtest +go test -cover -coverpkg=. -race + +cd $GOPATH/src/empty/pkgtestxtest +go test -cover -coverpkg=. -race + +cd $GOPATH/src/empty/testxtest +go test -cover -coverpkg=. -race + +-- empty/pkg/pkg.go -- +package p +-- empty/pkgtest/pkg.go -- +package p +-- empty/pkgtest/test_test.go -- +package p +-- empty/pkgtestxtest/pkg.go -- +package p +-- empty/pkgtestxtest/test_test.go -- +package p +-- empty/pkgtestxtest/xtest_test.go -- +package p_test +-- empty/pkgxtest/pkg.go -- +package p +-- empty/pkgxtest/xtest_test.go -- +package p_test +-- empty/test/test_test.go -- +package p +-- empty/testxtest/test_test.go -- +package p +-- empty/testxtest/xtest_test.go -- +package p_test +-- empty/xtest/xtest_test.go -- +package p_test diff --git a/src/cmd/go/testdata/script/test_race_install.txt b/src/cmd/go/testdata/script/test_race_install.txt new file mode 100644 index 0000000000..66dc19ebb6 --- /dev/null +++ b/src/cmd/go/testdata/script/test_race_install.txt @@ -0,0 +1,13 @@ +[!race] skip +[short] skip + +mkdir $WORKDIR/tmp/pkg +go install -race -pkgdir=$WORKDIR/tmp/pkg std + +# Make sure go test -i -race doesn't rebuild cached packages +go test -race -pkgdir=$WORKDIR/tmp/pkg -i -v empty/pkg +! stderr . + +-- empty/pkg/pkg.go -- +package p + diff --git a/src/cmd/go/testdata/src/empty/pkg/pkg.go b/src/cmd/go/testdata/src/empty/pkg/pkg.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/pkg/pkg.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/pkgtest/pkg.go b/src/cmd/go/testdata/src/empty/pkgtest/pkg.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/pkgtest/pkg.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/pkgtest/test_test.go b/src/cmd/go/testdata/src/empty/pkgtest/test_test.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/pkgtest/test_test.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go b/src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/pkgtestxtest/test_test.go b/src/cmd/go/testdata/src/empty/pkgtestxtest/test_test.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/pkgtestxtest/test_test.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/pkgtestxtest/xtest_test.go b/src/cmd/go/testdata/src/empty/pkgtestxtest/xtest_test.go deleted file mode 100644 index 9b64e8e1a2..0000000000 --- a/src/cmd/go/testdata/src/empty/pkgtestxtest/xtest_test.go +++ /dev/null @@ -1 +0,0 @@ -package p_test diff --git a/src/cmd/go/testdata/src/empty/pkgxtest/pkg.go b/src/cmd/go/testdata/src/empty/pkgxtest/pkg.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/pkgxtest/pkg.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/pkgxtest/xtest_test.go b/src/cmd/go/testdata/src/empty/pkgxtest/xtest_test.go deleted file mode 100644 index 9b64e8e1a2..0000000000 --- a/src/cmd/go/testdata/src/empty/pkgxtest/xtest_test.go +++ /dev/null @@ -1 +0,0 @@ -package p_test diff --git a/src/cmd/go/testdata/src/empty/test/test_test.go b/src/cmd/go/testdata/src/empty/test/test_test.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/test/test_test.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/testxtest/test_test.go b/src/cmd/go/testdata/src/empty/testxtest/test_test.go deleted file mode 100644 index c89cd18d0f..0000000000 --- a/src/cmd/go/testdata/src/empty/testxtest/test_test.go +++ /dev/null @@ -1 +0,0 @@ -package p diff --git a/src/cmd/go/testdata/src/empty/testxtest/xtest_test.go b/src/cmd/go/testdata/src/empty/testxtest/xtest_test.go deleted file mode 100644 index 9b64e8e1a2..0000000000 --- a/src/cmd/go/testdata/src/empty/testxtest/xtest_test.go +++ /dev/null @@ -1 +0,0 @@ -package p_test diff --git a/src/cmd/go/testdata/src/empty/xtest/xtest_test.go b/src/cmd/go/testdata/src/empty/xtest/xtest_test.go deleted file mode 100644 index 9b64e8e1a2..0000000000 --- a/src/cmd/go/testdata/src/empty/xtest/xtest_test.go +++ /dev/null @@ -1 +0,0 @@ -package p_test diff --git a/src/cmd/go/testdata/src/exclude/empty/x.txt b/src/cmd/go/testdata/src/exclude/empty/x.txt deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/cmd/go/testdata/src/exclude/ignore/_x.go b/src/cmd/go/testdata/src/exclude/ignore/_x.go deleted file mode 100644 index 823aafd071..0000000000 --- a/src/cmd/go/testdata/src/exclude/ignore/_x.go +++ /dev/null @@ -1 +0,0 @@ -package x diff --git a/src/cmd/go/testdata/src/exclude/x.go b/src/cmd/go/testdata/src/exclude/x.go deleted file mode 100644 index 9affd21e8c..0000000000 --- a/src/cmd/go/testdata/src/exclude/x.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build linux,!linux - -package x diff --git a/src/cmd/go/testdata/src/exclude/x_linux.go b/src/cmd/go/testdata/src/exclude/x_linux.go deleted file mode 100644 index 41ef6e5d7b..0000000000 --- a/src/cmd/go/testdata/src/exclude/x_linux.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build windows - -package x