Skip to content

Commit 2e509e6

Browse files
committed
cmd/go: convert some more tests to script tests
Convert more tests to script tests so they can run in parallel with the rest of the script tests. This CL converts TestPackageMainTestCompilerFlags, TestGoListTest, TestListTemplateContextFunction, and TestIssue22588. Change-Id: I4f8410e85d4811e82d85d884d28a2a0d6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/727420 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
1 parent c270e71 commit 2e509e6

File tree

5 files changed

+81
-101
lines changed

5 files changed

+81
-101
lines changed

src/cmd/go/go_test.go

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -972,19 +972,6 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
972972
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with old release")
973973
}
974974

975-
func TestPackageMainTestCompilerFlags(t *testing.T) {
976-
tg := testgo(t)
977-
defer tg.cleanup()
978-
tg.parallel()
979-
tg.makeTempdir()
980-
tg.setenv("GOPATH", tg.path("."))
981-
tg.tempFile("src/p1/p1.go", "package main\n")
982-
tg.tempFile("src/p1/p1_test.go", "package main\nimport \"testing\"\nfunc Test(t *testing.T){}\n")
983-
tg.run("test", "-c", "-n", "p1")
984-
tg.grepBothNot(`([\\/]compile|gccgo).* (-p main|-fgo-pkgpath=main).*p1\.go`, "should not have run compile -p main p1.go")
985-
tg.grepStderr(`([\\/]compile|gccgo).* (-p p1|-fgo-pkgpath=p1).*p1\.go`, "should have run compile -p p1 p1.go")
986-
}
987-
988975
// Issue 4104.
989976
func TestGoTestWithPackageListedMultipleTimes(t *testing.T) {
990977
tooSlow(t, "links and runs a test")
@@ -1070,43 +1057,6 @@ func TestGoListDeps(t *testing.T) {
10701057
}
10711058
}
10721059

1073-
func TestGoListTest(t *testing.T) {
1074-
skipIfGccgo(t, "gccgo does not have standard packages")
1075-
tg := testgo(t)
1076-
defer tg.cleanup()
1077-
tg.parallel()
1078-
tg.makeTempdir()
1079-
tg.setenv("GOCACHE", tg.tempdir)
1080-
1081-
tg.run("list", "-test", "-deps", "bytes")
1082-
tg.grepStdout(`^bytes.test$`, "missing test main")
1083-
tg.grepStdout(`^bytes$`, "missing real bytes")
1084-
tg.grepStdout(`^bytes \[bytes.test\]$`, "missing test copy of bytes")
1085-
tg.grepStdout(`^testing \[bytes.test\]$`, "missing test copy of testing")
1086-
tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing")
1087-
1088-
tg.run("list", "-test", "bytes")
1089-
tg.grepStdout(`^bytes.test$`, "missing test main")
1090-
tg.grepStdout(`^bytes$`, "missing real bytes")
1091-
tg.grepStdout(`^bytes \[bytes.test\]$`, "unexpected test copy of bytes")
1092-
tg.grepStdoutNot(`^testing \[bytes.test\]$`, "unexpected test copy of testing")
1093-
tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing")
1094-
1095-
tg.run("list", "-test", "cmd/buildid", "cmd/gofmt")
1096-
tg.grepStdout(`^cmd/buildid$`, "missing cmd/buildid")
1097-
tg.grepStdout(`^cmd/gofmt$`, "missing cmd/gofmt")
1098-
tg.grepStdout(`^cmd/gofmt\.test$`, "missing cmd/gofmt test")
1099-
tg.grepStdoutNot(`^cmd/buildid\.test$`, "unexpected cmd/buildid test")
1100-
tg.grepStdoutNot(`^testing`, "unexpected testing")
1101-
1102-
tg.run("list", "-test", "runtime/cgo")
1103-
tg.grepStdout(`^runtime/cgo$`, "missing runtime/cgo")
1104-
1105-
tg.run("list", "-deps", "-f", "{{if .DepOnly}}{{.ImportPath}}{{end}}", "sort")
1106-
tg.grepStdout(`^internal/reflectlite$`, "missing internal/reflectlite")
1107-
tg.grepStdoutNot(`^sort`, "unexpected sort")
1108-
}
1109-
11101060
func TestGoListCompiledCgo(t *testing.T) {
11111061
tooSlow(t, "compiles cgo files")
11121062

@@ -1528,40 +1478,6 @@ func main() {}
15281478
tg.run("run", tg.path("bar.go"))
15291479
}
15301480

1531-
func TestListTemplateContextFunction(t *testing.T) {
1532-
t.Parallel()
1533-
for _, tt := range []struct {
1534-
v string
1535-
want string
1536-
}{
1537-
{"GOARCH", runtime.GOARCH},
1538-
{"GOOS", runtime.GOOS},
1539-
{"GOROOT", testGOROOT},
1540-
{"GOPATH", os.Getenv("GOPATH")},
1541-
{"CgoEnabled", ""},
1542-
{"UseAllFiles", ""},
1543-
{"Compiler", ""},
1544-
{"BuildTags", ""},
1545-
{"ReleaseTags", ""},
1546-
{"InstallSuffix", ""},
1547-
} {
1548-
tt := tt
1549-
t.Run(tt.v, func(t *testing.T) {
1550-
tg := testgo(t)
1551-
tg.parallel()
1552-
defer tg.cleanup()
1553-
tmpl := "{{context." + tt.v + "}}"
1554-
tg.run("list", "-f", tmpl)
1555-
if tt.want == "" {
1556-
return
1557-
}
1558-
if got := strings.TrimSpace(tg.getStdout()); got != tt.want {
1559-
t.Errorf("go list -f %q: got %q; want %q", tmpl, got, tt.want)
1560-
}
1561-
})
1562-
}
1563-
}
1564-
15651481
// Test that you cannot use a local import in a package
15661482
// accessed by a non-local import (found in a GOPATH/GOROOT).
15671483
// See golang.org/issue/17475.
@@ -2247,23 +2163,6 @@ func TestCacheCoverage(t *testing.T) {
22472163
tg.run("test", "-cover", "-short", "math", "strings")
22482164
}
22492165

2250-
func TestIssue22588(t *testing.T) {
2251-
// Don't get confused by stderr coming from tools.
2252-
tg := testgo(t)
2253-
defer tg.cleanup()
2254-
tg.parallel()
2255-
2256-
tg.wantNotStale("runtime", "", "must be non-stale to compare staleness under -toolexec")
2257-
2258-
if _, err := os.Stat("/usr/bin/time"); err != nil {
2259-
t.Skip(err)
2260-
}
2261-
2262-
tg.run("list", "-f={{.Stale}}", "runtime")
2263-
tg.run("list", "-toolexec=/usr/bin/time", "-f={{.Stale}}", "runtime")
2264-
tg.grepStdout("false", "incorrectly reported runtime as stale")
2265-
}
2266-
22672166
func TestIssue22531(t *testing.T) {
22682167
tooSlow(t, "links binaries")
22692168
if gocacheverify.Value() == "1" {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This is a script test conversion of TestListTemplateContextFunction
2+
# originally added in CL 20010, which fixed #14547.
3+
# Test the ability to use the build context in the go list template.
4+
5+
go list -f '{{context.GOARCH}} {{context.GOOS}} {{context.GOROOT}} {{context.GOPATH}}'
6+
cmpenv stdout want.txt
7+
8+
go list -f '{{context.CgoEnabled}} {{context.UseAllFiles}} {{context.Compiler}} {{context.BuildTags}} {{context.ReleaseTags}} {{context.InstallSuffix}}'
9+
10+
-- go.mod --
11+
module foo
12+
-- foo.go --
13+
package foo
14+
-- want.txt --
15+
$GOARCH $GOOS $GOROOT $GOPATH
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This is a script test conversion of TestGoListTest which was added in
2+
# CL 107916, which added support for go list -test.
3+
# Test the behavior of go list -test.
4+
5+
[compiler:gccgo] skip 'gccgo does not have standard packages'
6+
7+
go list -test -deps bytes
8+
stdout '^bytes.test$' # test main
9+
stdout '^bytes$' # real bytes
10+
stdout '^bytes \[bytes.test\]$' # test copy of bytes
11+
stdout 'testing \[bytes.test\]$' # test copy of testing
12+
! stdout ^testing$ # should not have real testing
13+
14+
go list -test bytes
15+
stdout '^bytes.test$' # test main
16+
stdout '^bytes$' # real bytes
17+
stdout '^bytes \[bytes.test\]$' # test copy of bytes
18+
! stdout '^testing \[bytes.test\]$' # should not have test copy of testing
19+
! stdout '^testing$' # should not have real testing
20+
21+
go list -test cmd/buildid cmd/gofmt
22+
stdout '^cmd/buildid$' # cmd/buildid
23+
stdout '^cmd/gofmt$' # cmd/gofmt
24+
stdout '^cmd/gofmt\.test$' # cmd/gofmt test
25+
! stdout '^cmd/buildid\.test$' # should not have cmd/buildid test
26+
! stdout '^testing' # should not have real testing
27+
28+
go list -test runtime/cgo
29+
stdout '^runtime/cgo$' # runtime/cgo
30+
31+
go list -deps -f '{{if .DepOnly}}{{.ImportPath}}{{end}}' sort
32+
stdout '^internal/reflectlite$' # internal/reflectlite
33+
! stdout '^sort' # should not have sort
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This is a script test conversion of TestIssue22588 which was added in CL 76017.
2+
# Test that the stderr of a tool run under toolexec doesn't affect caching.
3+
4+
# Don't get confused by stderr coming from tools.
5+
[!exec:/usr/bin/time] skip
6+
7+
! stale runtime 'must be non-stale to compare staleness under -toolexec'
8+
9+
go list -f '{{.Stale}}' runtime
10+
go list -toolexec /usr/bin/time -f '{{.Stale}}' runtime
11+
stdout 'false' # runtime should not be reported as stale
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is a script test conversion of TestPackageMainTestCompilerFlags
2+
# originally added in CL 86265, which fixed #23180.
3+
# Test that we don't pass the package name 'main' to -p when building the
4+
# test package for a main package.
5+
6+
go test -c -n p1
7+
# should not have run compile -p main p1.go
8+
! stdout '([\\/]compile|gccgo).* (-p main|-fgo-pkgpath=main).*p1\.go'
9+
! stderr '([\\/]compile|gccgo).* (-p main|-fgo-pkgpath=main).*p1\.go'
10+
# should have run compile -p p1 p1.go
11+
stderr '([\\/]compile|gccgo).* (-p p1|-fgo-pkgpath=p1).*p1\.go'
12+
13+
-- go.mod --
14+
module p1
15+
-- p1.go --
16+
package main
17+
-- p1_test.go --
18+
package main
19+
20+
import "testing"
21+
22+
func Test(t *testing.T){}

0 commit comments

Comments
 (0)