aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorInanc Gumus <m@inanc.io>2017-10-30 22:41:14 +0300
committerRuss Cox <rsc@golang.org>2017-11-29 16:20:49 +0000
commit153e4096a8a52dac3b6da55b8644cda5ba6d0074 (patch)
tree9f2f82e19b2c86e88fa5addaf37eb173d7edd057 /src/testing/testing.go
parent4a483ce2ab493aaffc37bfb414de93d0622662fd (diff)
downloadgo-153e4096a8a52dac3b6da55b8644cda5ba6d0074.tar.xz
testing: add -failfast to go test
When -test.failfast flag is provided to go test, no new tests get started after the first failure. Fixes #21700 Change-Id: I0092e72f25847af05e7c8e1b811dcbb65a00cbe7 Reviewed-on: https://go-review.googlesource.com/74450 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 4beb9c6c1c..e12b622b03 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -242,6 +242,9 @@ var (
// full test of the package.
short = flag.Bool("test.short", false, "run smaller test suite to save time")
+ // The failfast flag requests that test execution stop after the first test failure.
+ failFast = flag.Bool("test.failfast", false, "do not start new tests after the first test failure")
+
// The directory in which to create profile files and the like. When run from
// "go test", the binary always runs in the source directory for the package;
// this flag lets "go test" tell the binary to write the files in the directory where
@@ -269,6 +272,8 @@ var (
haveExamples bool // are there examples?
cpuList []int
+
+ numFailed uint32 // number of test failures
)
// common holds the elements common between T and B and
@@ -767,6 +772,10 @@ func tRunner(t *T, fn func(t *T)) {
t.start = time.Now()
t.raceErrors = -race.Errors()
fn(t)
+
+ if t.failed {
+ atomic.AddUint32(&numFailed, 1)
+ }
t.finished = true
}
@@ -779,7 +788,7 @@ func tRunner(t *T, fn func(t *T)) {
func (t *T) Run(name string, f func(t *T)) bool {
atomic.StoreInt32(&t.hasSub, 1)
testName, ok, _ := t.context.match.fullName(&t.common, name)
- if !ok {
+ if !ok || shouldFailFast() {
return true
}
t = &T{
@@ -1021,6 +1030,9 @@ func runTests(matchString func(pat, str string) (bool, error), tests []InternalT
for _, procs := range cpuList {
runtime.GOMAXPROCS(procs)
for i := uint(0); i < *count; i++ {
+ if shouldFailFast() {
+ break
+ }
ctx := newTestContext(*parallel, newMatcher(matchString, *match, "-test.run"))
t := &T{
common: common{
@@ -1209,3 +1221,7 @@ func parseCpuList() {
cpuList = append(cpuList, runtime.GOMAXPROCS(-1))
}
}
+
+func shouldFailFast() bool {
+ return *failFast && atomic.LoadUint32(&numFailed) > 0
+}