}
// grepBothNot looks for a regular expression in the test run's
-// standard output or stand error and fails, logging msg, if it is
+// standard output or standard error and fails, logging msg, if it is
// found.
func (tg *testgoData) grepBothNot(match, msg string) {
tg.t.Helper()
}
}
-func TestWildcardsDoNotLookInUselessDirectories(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
- tg.runFail("list", "...")
- tg.grepBoth("badpkg", "go list ... failure does not mention badpkg")
- tg.run("list", "m...")
-}
-
func TestRelativeImportsGoTest(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.grepBothNot("duplicate load|internal error", "internal error")
}
-func TestFatalInBenchmarkCauseNonZeroExitStatus(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- // TODO: tg.parallel()
- tg.runFail("test", "-run", "^$", "-bench", ".", "./testdata/src/benchfatal")
- tg.grepBothNot("^ok", "test passed unexpectedly")
- tg.grepBoth("FAIL.*benchfatal", "test did not run everything")
-}
-
func TestBinaryOnlyPackages(t *testing.T) {
tooSlow(t)
tg.grepBoth(okPattern, "go test did not say ok")
}
-func TestBenchmarkLabels(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.parallel()
- tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
- tg.run("test", "-run", "^$", "-bench", ".", "bench")
- tg.grepStdout(`(?m)^goos: `+runtime.GOOS, "go test did not print goos")
- tg.grepStdout(`(?m)^goarch: `+runtime.GOARCH, "go test did not print goarch")
- tg.grepStdout(`(?m)^pkg: bench`, "go test did not say pkg: bench")
- tg.grepBothNot(`(?s)pkg:.*pkg:`, "go test said pkg multiple times")
-}
-
func TestBenchmarkLabelsOutsideGOPATH(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
goversion=<current Go version; for example, 1.12>
:=<OS-specific path list separator>
-The scripts supporting files are unpacked relative to $GOPATH/src (aka $WORK/gopath/src)
+The scripts' supporting files are unpacked relative to $GOPATH/src (aka $WORK/gopath/src)
and then the script begins execution in that directory as well. Thus the example above runs
in $WORK/gopath/src with GOPATH=$WORK/gopath and $WORK/gopath/src/hello.go
containing the listed contents.
--- /dev/null
+# Tests that go test -bench prints out goos, goarch, and pkg.
+
+# Check for goos, goarch, and pkg.
+go test -run ^$ -bench . bench
+stdout '^goos: '$GOOS
+stdout '^goarch: '$GOARCH
+stdout '^pkg: bench'
+
+# Check go test does not print pkg multiple times
+! stdout 'pkg:.*pkg: '
+! stderr 'pkg:.*pkg:'
+
+-- bench/x_test.go --
+package bench
+
+import "testing"
+
+func Benchmark(b *testing.B) {
+}