1
0
mirror of https://github.com/golang/go synced 2024-11-27 01:51:23 -07:00

cmd/go: convert tests using testdata/src/(xtestonly|cgotest) to script framework

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

Updates #36320
Updates #17751

Change-Id: I3465cad1b0ba0d912067429146f1cb0668d5aa6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/214284
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Michael Matloob 2020-01-10 11:15:41 -05:00
parent 68fab3e93f
commit 250c06f54e
7 changed files with 64 additions and 50 deletions

View File

@ -1131,15 +1131,6 @@ func TestVersionControlErrorMessageIncludesCorrectDirectory(t *testing.T) {
tg.grepStderr(regexp.QuoteMeta(quoted), "go get -u error does not mention shadow/root1/src/foo") tg.grepStderr(regexp.QuoteMeta(quoted), "go get -u error does not mention shadow/root1/src/foo")
} }
func TestInstallFailsWithNoBuildableFiles(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.setenv("CGO_ENABLED", "0")
tg.runFail("install", "cgotest")
tg.grepStderr("build constraints exclude all Go files", "go install cgotest did not report 'build constraints exclude all Go files'")
}
// Issue 21895 // Issue 21895
func TestMSanAndRaceRequireCgo(t *testing.T) { func TestMSanAndRaceRequireCgo(t *testing.T) {
if !canMSan && !canRace { if !canMSan && !canRace {
@ -1254,19 +1245,6 @@ func TestGoListCmdOnlyShowsCommands(t *testing.T) {
} }
} }
func TestGoListDedupsPackages(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
// TODO: tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("list", "xtestonly", "./testdata/src/xtestonly/...")
got := strings.TrimSpace(tg.getStdout())
const want = "xtestonly"
if got != want {
t.Errorf("got %q; want %q", got, want)
}
}
func TestGoListDeps(t *testing.T) { func TestGoListDeps(t *testing.T) {
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
@ -2131,14 +2109,6 @@ func TestListTemplateContextFunction(t *testing.T) {
} }
} }
func TestGoTestXtestonlyWorks(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("clean", "-i", "xtestonly")
tg.run("test", "xtestonly")
}
func TestGoTestBuildsAnXtestContainingOnlyNonRunnableExamples(t *testing.T) { func TestGoTestBuildsAnXtestContainingOnlyNonRunnableExamples(t *testing.T) {
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()

View File

@ -0,0 +1,11 @@
env CGO_ENABLED=0
! go install cgotest
stderr 'build constraints exclude all Go files'
-- cgotest/m.go --
package cgotest
import "C"
var _ C.int

View File

@ -0,0 +1,30 @@
# Setup
mkdir $WORK/tmp/testdata/src/xtestonly
cp f.go $WORK/tmp/testdata/src/xtestonly/f.go
cp f_test.go $WORK/tmp/testdata/src/xtestonly/f_test.go
env GOPATH=$WORK/tmp/testdata
cd $WORK
# Check output of go list to ensure no duplicates
go list xtestonly ./testdata/src/xtestonly/...
cmp stdout $WORK/gopath/src/wantstdout
-- wantstdout --
xtestonly
-- f.go --
package xtestonly
func F() int { return 42 }
-- f_test.go --
package xtestonly_test
import (
"testing"
"xtestonly"
)
func TestF(t *testing.T) {
if x := xtestonly.F(); x != 42 {
t.Errorf("f.F() = %d, want 42", x)
}
}

View File

@ -0,0 +1,23 @@
[short] skip
go test xtestonly
! stdout '^ok.*\[no tests to run\]'
stdout '^ok'
-- xtestonly/f.go --
package xtestonly
func F() int { return 42 }
-- xtestonly/f_test.go --
package xtestonly_test
import (
"testing"
"xtestonly"
)
func TestF(t *testing.T) {
if x := xtestonly.F(); x != 42 {
t.Errorf("f.F() = %d, want 42", x)
}
}

View File

@ -1,5 +0,0 @@
package cgotest
import "C"
var _ C.int

View File

@ -1,3 +0,0 @@
package xtestonly
func F() int { return 42 }

View File

@ -1,12 +0,0 @@
package xtestonly_test
import (
"testing"
"xtestonly"
)
func TestF(t *testing.T) {
if x := xtestonly.F(); x != 42 {
t.Errorf("f.F() = %d, want 42", x)
}
}