diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 1722f1a2c34..260c91e800b 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -972,19 +972,6 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) { tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with old release") } -func TestPackageMainTestCompilerFlags(t *testing.T) { - tg := testgo(t) - defer tg.cleanup() - tg.parallel() - tg.makeTempdir() - tg.setenv("GOPATH", tg.path(".")) - tg.tempFile("src/p1/p1.go", "package main\n") - tg.tempFile("src/p1/p1_test.go", "package main\nimport \"testing\"\nfunc Test(t *testing.T){}\n") - tg.run("test", "-c", "-n", "p1") - tg.grepBothNot(`([\\/]compile|gccgo).* (-p main|-fgo-pkgpath=main).*p1\.go`, "should not have run compile -p main p1.go") - tg.grepStderr(`([\\/]compile|gccgo).* (-p p1|-fgo-pkgpath=p1).*p1\.go`, "should have run compile -p p1 p1.go") -} - // Issue 4104. func TestGoTestWithPackageListedMultipleTimes(t *testing.T) { tooSlow(t, "links and runs a test") @@ -1070,43 +1057,6 @@ func TestGoListDeps(t *testing.T) { } } -func TestGoListTest(t *testing.T) { - skipIfGccgo(t, "gccgo does not have standard packages") - tg := testgo(t) - defer tg.cleanup() - tg.parallel() - tg.makeTempdir() - tg.setenv("GOCACHE", tg.tempdir) - - tg.run("list", "-test", "-deps", "bytes") - tg.grepStdout(`^bytes.test$`, "missing test main") - tg.grepStdout(`^bytes$`, "missing real bytes") - tg.grepStdout(`^bytes \[bytes.test\]$`, "missing test copy of bytes") - tg.grepStdout(`^testing \[bytes.test\]$`, "missing test copy of testing") - tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing") - - tg.run("list", "-test", "bytes") - tg.grepStdout(`^bytes.test$`, "missing test main") - tg.grepStdout(`^bytes$`, "missing real bytes") - tg.grepStdout(`^bytes \[bytes.test\]$`, "unexpected test copy of bytes") - tg.grepStdoutNot(`^testing \[bytes.test\]$`, "unexpected test copy of testing") - tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing") - - tg.run("list", "-test", "cmd/buildid", "cmd/gofmt") - tg.grepStdout(`^cmd/buildid$`, "missing cmd/buildid") - tg.grepStdout(`^cmd/gofmt$`, "missing cmd/gofmt") - tg.grepStdout(`^cmd/gofmt\.test$`, "missing cmd/gofmt test") - tg.grepStdoutNot(`^cmd/buildid\.test$`, "unexpected cmd/buildid test") - tg.grepStdoutNot(`^testing`, "unexpected testing") - - tg.run("list", "-test", "runtime/cgo") - tg.grepStdout(`^runtime/cgo$`, "missing runtime/cgo") - - tg.run("list", "-deps", "-f", "{{if .DepOnly}}{{.ImportPath}}{{end}}", "sort") - tg.grepStdout(`^internal/reflectlite$`, "missing internal/reflectlite") - tg.grepStdoutNot(`^sort`, "unexpected sort") -} - func TestGoListCompiledCgo(t *testing.T) { tooSlow(t, "compiles cgo files") @@ -1528,40 +1478,6 @@ func main() {} tg.run("run", tg.path("bar.go")) } -func TestListTemplateContextFunction(t *testing.T) { - t.Parallel() - for _, tt := range []struct { - v string - want string - }{ - {"GOARCH", runtime.GOARCH}, - {"GOOS", runtime.GOOS}, - {"GOROOT", testGOROOT}, - {"GOPATH", os.Getenv("GOPATH")}, - {"CgoEnabled", ""}, - {"UseAllFiles", ""}, - {"Compiler", ""}, - {"BuildTags", ""}, - {"ReleaseTags", ""}, - {"InstallSuffix", ""}, - } { - tt := tt - t.Run(tt.v, func(t *testing.T) { - tg := testgo(t) - tg.parallel() - defer tg.cleanup() - tmpl := "{{context." + tt.v + "}}" - tg.run("list", "-f", tmpl) - if tt.want == "" { - return - } - if got := strings.TrimSpace(tg.getStdout()); got != tt.want { - t.Errorf("go list -f %q: got %q; want %q", tmpl, got, tt.want) - } - }) - } -} - // Test that you cannot use a local import in a package // accessed by a non-local import (found in a GOPATH/GOROOT). // See golang.org/issue/17475. @@ -2247,23 +2163,6 @@ func TestCacheCoverage(t *testing.T) { tg.run("test", "-cover", "-short", "math", "strings") } -func TestIssue22588(t *testing.T) { - // Don't get confused by stderr coming from tools. - tg := testgo(t) - defer tg.cleanup() - tg.parallel() - - tg.wantNotStale("runtime", "", "must be non-stale to compare staleness under -toolexec") - - if _, err := os.Stat("/usr/bin/time"); err != nil { - t.Skip(err) - } - - tg.run("list", "-f={{.Stale}}", "runtime") - tg.run("list", "-toolexec=/usr/bin/time", "-f={{.Stale}}", "runtime") - tg.grepStdout("false", "incorrectly reported runtime as stale") -} - func TestIssue22531(t *testing.T) { tooSlow(t, "links binaries") if gocacheverify.Value() == "1" { diff --git a/src/cmd/go/testdata/script/list_template_context_function.txt b/src/cmd/go/testdata/script/list_template_context_function.txt new file mode 100644 index 00000000000..70c47c87f8e --- /dev/null +++ b/src/cmd/go/testdata/script/list_template_context_function.txt @@ -0,0 +1,15 @@ +# This is a script test conversion of TestListTemplateContextFunction +# originally added in CL 20010, which fixed #14547. +# Test the ability to use the build context in the go list template. + +go list -f '{{context.GOARCH}} {{context.GOOS}} {{context.GOROOT}} {{context.GOPATH}}' +cmpenv stdout want.txt + +go list -f '{{context.CgoEnabled}} {{context.UseAllFiles}} {{context.Compiler}} {{context.BuildTags}} {{context.ReleaseTags}} {{context.InstallSuffix}}' + +-- go.mod -- +module foo +-- foo.go -- +package foo +-- want.txt -- +$GOARCH $GOOS $GOROOT $GOPATH diff --git a/src/cmd/go/testdata/script/list_test.txt b/src/cmd/go/testdata/script/list_test.txt new file mode 100644 index 00000000000..f65cd80db2b --- /dev/null +++ b/src/cmd/go/testdata/script/list_test.txt @@ -0,0 +1,33 @@ +# This is a script test conversion of TestGoListTest which was added in +# CL 107916, which added support for go list -test. +# Test the behavior of go list -test. + +[compiler:gccgo] skip 'gccgo does not have standard packages' + +go list -test -deps bytes +stdout '^bytes.test$' # test main +stdout '^bytes$' # real bytes +stdout '^bytes \[bytes.test\]$' # test copy of bytes +stdout 'testing \[bytes.test\]$' # test copy of testing +! stdout ^testing$ # should not have real testing + +go list -test bytes +stdout '^bytes.test$' # test main +stdout '^bytes$' # real bytes +stdout '^bytes \[bytes.test\]$' # test copy of bytes +! stdout '^testing \[bytes.test\]$' # should not have test copy of testing +! stdout '^testing$' # should not have real testing + +go list -test cmd/buildid cmd/gofmt +stdout '^cmd/buildid$' # cmd/buildid +stdout '^cmd/gofmt$' # cmd/gofmt +stdout '^cmd/gofmt\.test$' # cmd/gofmt test +! stdout '^cmd/buildid\.test$' # should not have cmd/buildid test +! stdout '^testing' # should not have real testing + +go list -test runtime/cgo +stdout '^runtime/cgo$' # runtime/cgo + +go list -deps -f '{{if .DepOnly}}{{.ImportPath}}{{end}}' sort +stdout '^internal/reflectlite$' # internal/reflectlite +! stdout '^sort' # should not have sort diff --git a/src/cmd/go/testdata/script/list_toolexec_stderr_issue22588.txt b/src/cmd/go/testdata/script/list_toolexec_stderr_issue22588.txt new file mode 100644 index 00000000000..dd2eaed2a1f --- /dev/null +++ b/src/cmd/go/testdata/script/list_toolexec_stderr_issue22588.txt @@ -0,0 +1,11 @@ +# This is a script test conversion of TestIssue22588 which was added in CL 76017. +# Test that the stderr of a tool run under toolexec doesn't affect caching. + +# Don't get confused by stderr coming from tools. +[!exec:/usr/bin/time] skip + +! stale runtime 'must be non-stale to compare staleness under -toolexec' + +go list -f '{{.Stale}}' runtime +go list -toolexec /usr/bin/time -f '{{.Stale}}' runtime +stdout 'false' # runtime should not be reported as stale \ No newline at end of file diff --git a/src/cmd/go/testdata/script/test_main_compiler_flags.txt b/src/cmd/go/testdata/script/test_main_compiler_flags.txt new file mode 100644 index 00000000000..e207ecae16a --- /dev/null +++ b/src/cmd/go/testdata/script/test_main_compiler_flags.txt @@ -0,0 +1,22 @@ +# This is a script test conversion of TestPackageMainTestCompilerFlags +# originally added in CL 86265, which fixed #23180. +# Test that we don't pass the package name 'main' to -p when building the +# test package for a main package. + +go test -c -n p1 +# should not have run compile -p main p1.go +! stdout '([\\/]compile|gccgo).* (-p main|-fgo-pkgpath=main).*p1\.go' +! stderr '([\\/]compile|gccgo).* (-p main|-fgo-pkgpath=main).*p1\.go' +# should have run compile -p p1 p1.go +stderr '([\\/]compile|gccgo).* (-p p1|-fgo-pkgpath=p1).*p1\.go' + +-- go.mod -- +module p1 +-- p1.go -- +package main +-- p1_test.go -- +package main + +import "testing" + +func Test(t *testing.T){}