tg.run("install", "./testonly...")
}
-func TestGoTestFooTestWorks(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "testdata/standalone_test.go")
-}
-
-func TestGoTestTestMainSeesTestingFlags(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "testdata/standalone_testmain_flag_test.go")
-}
-
-// Issue 22388
-func TestGoTestMainWithWrongSignature(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.runFail("test", "testdata/standalone_main_wrong_test.go")
- tg.grepStderr(`wrong signature for TestMain, must be: func TestMain\(m \*testing.M\)`, "detected wrong error message")
-}
-
-func TestGoTestMainAsNormalTest(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "testdata/standalone_main_normal_test.go")
- tg.grepBoth(okPattern, "go test did not say ok")
-}
-
func TestGoTestXtestonlyWorks(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
okPattern = `(?m)^ok`
)
-func TestMatchesNoTests(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- // TODO: tg.parallel()
- tg.run("test", "-run", "ThisWillNotMatch", "testdata/standalone_test.go")
- tg.grepBoth(noMatchesPattern, "go test did not say [no tests to run]")
-}
-
-func TestMatchesNoBenchmarksIsOK(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- // TODO: tg.parallel()
- tg.run("test", "-run", "^$", "-bench", "ThisWillNotMatch", "testdata/standalone_benchmark_test.go")
- tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
- tg.grepBoth(okPattern, "go test did not say ok")
-}
-
-func TestMatchesOnlyBenchmarkIsOK(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- // TODO: tg.parallel()
- tg.run("test", "-run", "^$", "-bench", ".", "testdata/standalone_benchmark_test.go")
- tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
- tg.grepBoth(okPattern, "go test did not say ok")
-}
-
-func TestBenchmarkLabelsOutsideGOPATH(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- // TODO: tg.parallel()
- tg.run("test", "-run", "^$", "-bench", ".", "testdata/standalone_benchmark_test.go")
- 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.grepBothNot(`(?m)^pkg:`, "go test did say pkg:")
-}
-
-func TestMatchesOnlyTestIsOK(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- // TODO: tg.parallel()
- tg.run("test", "-run", "Test", "testdata/standalone_test.go")
- tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
- tg.grepBoth(okPattern, "go test did not say ok")
-}
-
-func TestMatchesNoTestsWithSubtests(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "-run", "ThisWillNotMatch", "testdata/standalone_sub_test.go")
- tg.grepBoth(noMatchesPattern, "go test did not say [no tests to run]")
-}
-
-func TestMatchesNoSubtestsMatch(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "-run", "Test/ThisWillNotMatch", "testdata/standalone_sub_test.go")
- tg.grepBoth(noMatchesPattern, "go test did not say [no tests to run]")
-}
-
-func TestMatchesNoSubtestsDoesNotOverrideFailure(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.runFail("test", "-run", "TestThatFails/ThisWillNotMatch", "testdata/standalone_fail_sub_test.go")
- tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
- tg.grepBoth("FAIL", "go test did not say FAIL")
-}
-
-func TestMatchesOnlySubtestIsOK(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "-run", "Test/Sub", "testdata/standalone_sub_test.go")
- tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
- tg.grepBoth(okPattern, "go test did not say ok")
-}
-
-func TestMatchesNoSubtestsParallel(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "-run", "Test/Sub/ThisWillNotMatch", "testdata/standalone_parallel_sub_test.go")
- tg.grepBoth(noMatchesPattern, "go test did not say [no tests to run]")
-}
-
-func TestMatchesOnlySubtestParallelIsOK(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.run("test", "-run", "Test/Sub/Nested", "testdata/standalone_parallel_sub_test.go")
- tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
- tg.grepBoth(okPattern, "go test did not say ok")
-}
-
// Issue 18845
func TestBenchTimeout(t *testing.T) {
tooSlow(t)
tg.must(robustio.RemoveAll(matches[1]))
}
-func TestParallelNumber(t *testing.T) {
- tooSlow(t)
- for _, n := range [...]string{"-1", "0"} {
- t.Run(n, func(t *testing.T) {
- tg := testgo(t)
- defer tg.cleanup()
- tg.runFail("test", "-parallel", n, "testdata/standalone_parallel_sub_test.go")
- tg.grepBoth("-parallel can only be given", "go test -parallel with N<1 did not error")
- })
- }
-}
-
func TestWrongGOOSErrorBeforeLoadError(t *testing.T) {
skipIfGccgo(t, "gccgo assumes cross-compilation is always possible")
tg := testgo(t)
--- /dev/null
+# Test TestMain
+go test standalone_main_normal_test.go
+! stdout '^ok.*\[no tests to run\]'
+! stderr '^ok.*\[no tests to run\]'
+stdout '^ok'
+
+# Test TestMain sees testing flags
+go test standalone_testmain_flag_test.go
+stdout '^ok.*\[no tests to run\]'
+
+# Test TestMain with wrong signature (Issue #22388)
+! go test standalone_main_wrong_test.go
+stderr 'wrong signature for TestMain, must be: func TestMain\(m \*testing.M\)'
+
+-- standalone_main_normal_test.go --
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package standalone_main_normal_test
+
+import "testing"
+
+func TestMain(t *testing.T) {
+}
+-- standalone_main_wrong_test.go --
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package standalone_main_wrong_test
+
+import "testing"
+
+func TestMain(m *testing.Main) {
+}
+-- standalone_testmain_flag_test.go --
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package standalone_testmain_flag_test
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "testing"
+)
+
+func TestMain(m *testing.M) {
+ // A TestMain should be able to access testing flags if it calls
+ // flag.Parse without needing to use testing.Init.
+ flag.Parse()
+ found := false
+ flag.VisitAll(func(f *flag.Flag) {
+ if f.Name == "test.count" {
+ found = true
+ }
+ })
+ if !found {
+ fmt.Println("testing flags not registered")
+ os.Exit(1)
+ }
+ os.Exit(m.Run())
+}
--- /dev/null
+# Benchmark labels, file outside gopath
+# TODO(matloob): This test was called TestBenchmarkLabelsOutsideGOPATH
+# why "OutsideGOPATH"? Does the go command need to be run outside GOPATH?
+# Do the files need to exist outside GOPATH?
+cp $GOPATH/src/standalone_benchmark_test.go $WORK/tmp/standalone_benchmark_test.go
+go test -run '^$' -bench . $WORK/tmp/standalone_benchmark_test.go
+stdout '^goos: '$GOOS
+stdout '^goarch: '$GOARCH
+! stdout '^pkg:'
+! stderr '^pkg:'
+
+-- standalone_benchmark_test.go --
+package standalone_benchmark
+
+import "testing"
+
+func Benchmark(b *testing.B) {
+}
\ No newline at end of file
--- /dev/null
+# Matches no benchmarks
+go test -run '^$' -bench ThisWillNotMatch standalone_benchmark_test.go
+! stdout '^ok.*\[no tests to run\]'
+! stderr '^ok.*\[no tests to run\]'
+stdout '^ok'
+
+-- standalone_benchmark_test.go --
+package standalone_benchmark
+
+import "testing"
+
+func Benchmark(b *testing.B) {
+}
\ No newline at end of file
--- /dev/null
+# The subtests don't match
+go test -run Test/ThisWillNotMatch standalone_sub_test.go
+stdout '^ok.*\[no tests to run\]'
+
+-- standalone_sub_test.go --
+package standalone_sub_test
+
+import "testing"
+
+func Test(t *testing.T) {
+ t.Run("Sub", func(t *testing.T) {})
+}
\ No newline at end of file
--- /dev/null
+# Matches no subtests, but parent test still fails
+! go test -run TestThatFails/ThisWillNotMatch standalone_fail_sub_test.go
+! stdout '^ok.*\[no tests to run\]'
+! stderr '^ok.*\[no tests to run\]'
+stdout 'FAIL'
+
+-- standalone_fail_sub_test.go --
+package standalone_fail_sub_test
+
+import "testing"
+
+func TestThatFails(t *testing.T) {
+ t.Run("Sub", func(t *testing.T) {})
+ t.Fail()
+}
\ No newline at end of file
+# Matches no subtests, parallel
+go test -run Test/Sub/ThisWillNotMatch standalone_parallel_sub_test.go
+stdout '^ok.*\[no tests to run\]'
+
+-- standalone_parallel_sub_test.go --
package standalone_parallel_sub_test
import "testing"
--- /dev/null
+# Matches no tests
+go test -run ThisWillNotMatch standalone_test.go
+stdout '^ok.*\[no tests to run\]'
+
+-- standalone_test.go --
+package standalone_test
+
+import "testing"
+
+func Test(t *testing.T) {
+}
\ No newline at end of file
--- /dev/null
+# Matches no tests with subtests
+go test -run ThisWillNotMatch standalone_sub_test.go
+stdout '^ok.*\[no tests to run\]'
+
+-- standalone_sub_test.go --
+package standalone_sub_test
+
+import "testing"
+
+func Test(t *testing.T) {
+ t.Run("Sub", func(t *testing.T) {})
+}
\ No newline at end of file
--- /dev/null
+# Matches only benchmarks
+go test -run '^$' -bench . standalone_benchmark_test.go
+! stdout '^ok.*\[no tests to run\]'
+! stderr '^ok.*\[no tests to run\]'
+stdout '^ok'
+
+-- standalone_benchmark_test.go --
+package standalone_benchmark
+
+import "testing"
+
+func Benchmark(b *testing.B) {
+}
\ No newline at end of file
--- /dev/null
+# Matches only subtests
+go test -run Test/Sub standalone_sub_test.go
+! stdout '^ok.*\[no tests to run\]'
+! stderr '^ok.*\[no tests to run\]'
+stdout '^ok'
+
+-- standalone_sub_test.go --
+package standalone_sub_test
+
+import "testing"
+
+func Test(t *testing.T) {
+ t.Run("Sub", func(t *testing.T) {})
+}
\ No newline at end of file
--- /dev/null
+# Matches only subtests, parallel
+go test -run Test/Sub/Nested standalone_parallel_sub_test.go
+! stdout '^ok.*\[no tests to run\]'
+! stderr '^ok.*\[no tests to run\]'
+stdout '^ok'
+
+-- standalone_parallel_sub_test.go --
+package standalone_parallel_sub_test
+
+import "testing"
+
+func Test(t *testing.T) {
+ ch := make(chan bool, 1)
+ t.Run("Sub", func(t *testing.T) {
+ t.Parallel()
+ <-ch
+ t.Run("Nested", func(t *testing.T) {})
+ })
+ // Ensures that Sub will finish after its t.Run call already returned.
+ ch <- true
+}
--- /dev/null
+# Matches only tests
+go test -run Test standalone_test.go
+! stdout '^ok.*\[no tests to run\]'
+! stderr '^ok.*\[no tests to run\]'
+stdout '^ok'
+
+-- standalone_test.go --
+package standalone_test
+
+import "testing"
+
+func Test(t *testing.T) {
+}
\ No newline at end of file
--- /dev/null
+[short] skip
+
+# go test -parallel -1 shouldn't work
+! go test -parallel -1 standalone_parallel_sub_test.go
+stdout '-parallel can only be given'
+
+# go test -parallel 0 shouldn't work
+! go test -parallel 0 standalone_parallel_sub_test.go
+stdout '-parallel can only be given'
+
+-- standalone_parallel_sub_test.go --
+package standalone_parallel_sub_test
+
+import "testing"
+
+func Test(t *testing.T) {
+ ch := make(chan bool, 1)
+ t.Run("Sub", func(t *testing.T) {
+ t.Parallel()
+ <-ch
+ t.Run("Nested", func(t *testing.T) {})
+ })
+ // Ensures that Sub will finish after its t.Run call already returned.
+ ch <- true
+}
+++ /dev/null
-package standalone_benchmark
-
-import "testing"
-
-func Benchmark(b *testing.B) {
-}
+++ /dev/null
-package standalone_fail_sub_test
-
-import "testing"
-
-func TestThatFails(t *testing.T) {
- t.Run("Sub", func(t *testing.T) {})
- t.Fail()
-}
+++ /dev/null
-// Copyright 2017 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package standalone_main_normal_test
-
-import "testing"
-
-func TestMain(t *testing.T) {
-}
+++ /dev/null
-// Copyright 2017 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package standalone_main_wrong_test
-
-import "testing"
-
-func TestMain(m *testing.Main) {
-}
+++ /dev/null
-package standalone_sub_test
-
-import "testing"
-
-func Test(t *testing.T) {
- t.Run("Sub", func(t *testing.T) {})
-}
+++ /dev/null
-package standalone_test
-
-import "testing"
-
-func Test(t *testing.T) {
-}
+++ /dev/null
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package standalone_testmain_flag_test
-
-import (
- "flag"
- "fmt"
- "os"
- "testing"
-)
-
-func TestMain(m *testing.M) {
- // A TestMain should be able to access testing flags if it calls
- // flag.Parse without needing to use testing.Init.
- flag.Parse()
- found := false
- flag.VisitAll(func(f *flag.Flag) {
- if f.Name == "test.count" {
- found = true
- }
- })
- if !found {
- fmt.Println("testing flags not registered")
- os.Exit(1)
- }
- os.Exit(m.Run())
-}