Skip to content

Commit 4d6c171

Browse files
committed
cmd/go: convert more tests to the script framework
Part of converting all tests to script framework to improve test parallelism. Updates #36320 Updates #17751 Change-Id: I394844da1ffc0dcde7f5862c41ed8efa7c5ca088 Reviewed-on: https://go-review.googlesource.com/c/go/+/214429 Reviewed-by: Jay Conrod <[email protected]>
1 parent ff811c8 commit 4d6c171

9 files changed

+76
-101
lines changed

src/cmd/go/go_test.go

-99
Original file line numberDiff line numberDiff line change
@@ -1102,42 +1102,6 @@ func TestAccidentalGitCheckout(t *testing.T) {
11021102
}
11031103
}
11041104

1105-
func TestVersionControlErrorMessageIncludesCorrectDirectory(t *testing.T) {
1106-
tg := testgo(t)
1107-
defer tg.cleanup()
1108-
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/shadow/root1"))
1109-
tg.runFail("get", "-u", "foo")
1110-
1111-
// TODO(iant): We should not have to use strconv.Quote here.
1112-
// The code in vcs.go should be changed so that it is not required.
1113-
quoted := strconv.Quote(filepath.Join("testdata", "shadow", "root1", "src", "foo"))
1114-
quoted = quoted[1 : len(quoted)-1]
1115-
1116-
tg.grepStderr(regexp.QuoteMeta(quoted), "go get -u error does not mention shadow/root1/src/foo")
1117-
}
1118-
1119-
// Issue 21895
1120-
func TestMSanAndRaceRequireCgo(t *testing.T) {
1121-
if !canMSan && !canRace {
1122-
t.Skip("skipping because both msan and the race detector are not supported")
1123-
}
1124-
1125-
tg := testgo(t)
1126-
defer tg.cleanup()
1127-
tg.tempFile("triv.go", `package main; func main() {}`)
1128-
tg.setenv("CGO_ENABLED", "0")
1129-
if canRace {
1130-
tg.runFail("install", "-race", "triv.go")
1131-
tg.grepStderr("-race requires cgo", "did not correctly report that -race requires cgo")
1132-
tg.grepStderrNot("-msan", "reported that -msan instead of -race requires cgo")
1133-
}
1134-
if canMSan {
1135-
tg.runFail("install", "-msan", "triv.go")
1136-
tg.grepStderr("-msan requires cgo", "did not correctly report that -msan requires cgo")
1137-
tg.grepStderrNot("-race", "reported that -race instead of -msan requires cgo")
1138-
}
1139-
}
1140-
11411105
func TestPackageMainTestCompilerFlags(t *testing.T) {
11421106
tg := testgo(t)
11431107
defer tg.cleanup()
@@ -1776,28 +1740,6 @@ func main() {
17761740
tg.run("run", tg.path("foo.go"))
17771741
}
17781742

1779-
// cmd/cgo: undefined reference when linking a C-library using gccgo
1780-
func TestIssue7573(t *testing.T) {
1781-
if !canCgo {
1782-
t.Skip("skipping because cgo not enabled")
1783-
}
1784-
testenv.MustHaveExecPath(t, "gccgo")
1785-
1786-
tg := testgo(t)
1787-
defer tg.cleanup()
1788-
tg.parallel()
1789-
tg.tempFile("src/cgoref/cgoref.go", `
1790-
package main
1791-
// #cgo LDFLAGS: -L alibpath -lalib
1792-
// void f(void) {}
1793-
import "C"
1794-
1795-
func main() { C.f() }`)
1796-
tg.setenv("GOPATH", tg.path("."))
1797-
tg.run("build", "-n", "-compiler", "gccgo", "cgoref")
1798-
tg.grepStderr(`gccgo.*\-L [^ ]*alibpath \-lalib`, `no Go-inline "#cgo LDFLAGS:" ("-L alibpath -lalib") passed to gccgo linking stage`)
1799-
}
1800-
18011743
func TestListTemplateContextFunction(t *testing.T) {
18021744
t.Parallel()
18031745
for _, tt := range []struct {
@@ -1986,16 +1928,6 @@ func TestImportLocal(t *testing.T) {
19861928
tg.grepStderr("cannot import current directory", "did not diagnose import current directory")
19871929
}
19881930

1989-
func TestGoRunDirs(t *testing.T) {
1990-
tg := testgo(t)
1991-
defer tg.cleanup()
1992-
tg.cd("testdata/rundir")
1993-
tg.runFail("run", "x.go", "sub/sub.go")
1994-
tg.grepStderr("named files must all be in one directory; have ./ and sub/", "wrong output")
1995-
tg.runFail("run", "sub/sub.go", "x.go")
1996-
tg.grepStderr("named files must all be in one directory; have sub/ and ./", "wrong output")
1997-
}
1998-
19991931
func TestGoInstallPkgdir(t *testing.T) {
20001932
skipIfGccgo(t, "gccgo has no standard packages")
20011933
tooSlow(t)
@@ -2013,26 +1945,6 @@ func TestGoInstallPkgdir(t *testing.T) {
20131945
tg.mustExist(filepath.Join(pkg, "sync/atomic.a"))
20141946
}
20151947

2016-
func TestGoInstallShadowedGOPATH(t *testing.T) {
2017-
// golang.org/issue/3652.
2018-
// go get foo.io (not foo.io/subdir) was not working consistently.
2019-
2020-
testenv.MustHaveExternalNetwork(t)
2021-
2022-
tg := testgo(t)
2023-
defer tg.cleanup()
2024-
tg.makeTempdir()
2025-
tg.setenv("GOPATH", tg.path("gopath1")+string(filepath.ListSeparator)+tg.path("gopath2"))
2026-
2027-
tg.tempDir("gopath1/src/test")
2028-
tg.tempDir("gopath2/src/test")
2029-
tg.tempFile("gopath2/src/test/main.go", "package main\nfunc main(){}\n")
2030-
2031-
tg.cd(tg.path("gopath2/src/test"))
2032-
tg.runFail("install")
2033-
tg.grepStderr("no install location for.*gopath2.src.test: hidden by .*gopath1.src.test", "missing error")
2034-
}
2035-
20361948
func TestGoBuildGOPATHOrder(t *testing.T) {
20371949
// golang.org/issue/14176#issuecomment-179895769
20381950
// golang.org/issue/14192
@@ -2353,17 +2265,6 @@ func main() {
23532265
tg.run("build", "-o", exe, "p")
23542266
}
23552267

2356-
func TestBuildTagsNoComma(t *testing.T) {
2357-
skipIfGccgo(t, "gccgo has no standard packages")
2358-
tg := testgo(t)
2359-
defer tg.cleanup()
2360-
tg.makeTempdir()
2361-
tg.setenv("GOPATH", tg.path("go"))
2362-
tg.run("build", "-tags", "tag1 tag2", "math")
2363-
tg.runFail("build", "-tags", "tag1,tag2 tag3", "math")
2364-
tg.grepBoth("space-separated list contains comma", "-tags with a comma-separated list didn't error")
2365-
}
2366-
23672268
func copyFile(src, dst string, perm os.FileMode) error {
23682269
sf, err := os.Open(src)
23692270
if err != nil {

src/cmd/go/testdata/rundir/sub/sub.go

-1
This file was deleted.

src/cmd/go/testdata/rundir/x.go

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[gccgo] skip 'gccgo has no standard packages'
2+
go build -tags 'tag1 tag2' math
3+
! go build -tags 'tag1,tag2 tag3' math
4+
stderr 'space-separated list contains comma'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Issue #7573
2+
# cmd/cgo: undefined reference when linking a C-library using gccgo
3+
4+
[!cgo] skip
5+
[!gccgo] skip
6+
7+
go build -r -compiler gccgo cgoref
8+
stderr 'gccgo.*\-L [^ ]*alibpath \-lalib' # make sure that Go-inline "#cgo LDFLAGS:" ("-L alibpath -lalib") passed to gccgo linking stage
9+
10+
-- cgoref/cgoref.go --
11+
package main
12+
// #cgo LDFLAGS: -L alibpath -lalib
13+
// void f(void) {}
14+
import "C"
15+
16+
func main() { C.f() }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Test that the Version Control error message includes the correct directory
2+
! go get -u foo
3+
stderr gopath(\\\\|/)src(\\\\|/)foo
4+
5+
-- foo/foo.go --
6+
package foo
7+
-- math/math.go --
8+
package math
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Tests Issue #21895
2+
3+
[!msan] [!race] skip 'skipping because both msan and the race detector are not supported'
4+
5+
env CGO_ENABLED=0
6+
7+
[race] ! go install -race triv.go
8+
[race] stderr '-race requires cgo'
9+
[race] ! stderr '-msan'
10+
11+
[msan] ! go install -msan triv.go
12+
[msan] stderr '-msan requires cgo'
13+
[msan] ! stderr '-race'
14+
15+
-- triv.go --
16+
package main
17+
18+
func main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Tests Issue #3562
2+
# go get foo.io (not foo.io/subdir) was not working consistently.
3+
4+
[!net] skip
5+
6+
env GOPATH=$WORK/gopath1:$WORK/gopath2
7+
8+
mkdir $WORK/gopath1/src/test
9+
mkdir $WORK/gopath2/src/test
10+
cp main.go $WORK/gopath2/src/test/main.go
11+
cd $WORK/gopath2/src/test
12+
13+
! go install
14+
stderr 'no install location for.*gopath2.src.test: hidden by .*gopath1.src.test'
15+
16+
-- main.go --
17+
package main
18+
19+
func main() {}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cd rundir
2+
3+
! go run x.go sub/sub.go
4+
stderr 'named files must all be in one directory; have ./ and sub/'
5+
! go run sub/sub.go x.go
6+
stderr 'named files must all be in one directory; have sub/ and ./'
7+
8+
-- rundir/sub/sub.go --
9+
package main
10+
-- rundir/x.go --
11+
package main

0 commit comments

Comments
 (0)