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")
}
}
-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")
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.
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" {
--- /dev/null
+# 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