Skip to content

Commit

Permalink
cmd/go: convert tests using testdata/src/(exclude|empty) to script fr…
Browse files Browse the repository at this point in the history
…amework

Part of converting all tests to script framework to improve
test parallelism.

Updates golang#36320
Updates golang#17751

Change-Id: Icc14d4188574badf3da71d34857616f2a2ad5862
Reviewed-on: https://go-review.googlesource.com/c/go/+/214138
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
matloob committed Feb 19, 2020
1 parent 1ee337e commit f08734d
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 92 deletions.
73 changes: 0 additions & 73 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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") {
Expand Down
37 changes: 37 additions & 0 deletions src/cmd/go/testdata/script/build_no_go.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions src/cmd/go/testdata/script/build_unsupported_goos.txt
Original file line number Diff line number Diff line change
@@ -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'
49 changes: 49 additions & 0 deletions src/cmd/go/testdata/script/test_empty.txt
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions src/cmd/go/testdata/script/test_race_install.txt
Original file line number Diff line number Diff line change
@@ -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

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkg/pkg.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkgtest/pkg.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkgtest/test_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkgtestxtest/test_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkgtestxtest/xtest_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkgxtest/pkg.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/pkgxtest/xtest_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/test/test_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/testxtest/test_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/testxtest/xtest_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/empty/xtest/xtest_test.go

This file was deleted.

Empty file.
1 change: 0 additions & 1 deletion src/cmd/go/testdata/src/exclude/ignore/_x.go

This file was deleted.

3 changes: 0 additions & 3 deletions src/cmd/go/testdata/src/exclude/x.go

This file was deleted.

3 changes: 0 additions & 3 deletions src/cmd/go/testdata/src/exclude/x_linux.go

This file was deleted.

0 comments on commit f08734d

Please sign in to comment.