Commit d0925228 authored by fraenkel's avatar fraenkel Committed by Ian Lance Taylor

testing: failfast fails fast when Fatal called

When a test calls t.Fatal()/t.Fatalf(), only deferred code will execute.
Increment the failure count as part of a deferred call.

Fixes #24412

Change-Id: Ibb154015fcd3d0fb7739718fdda8c9ad22f9e896
Reviewed-on: https://go-review.googlesource.com/101035
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 6d5ebc70
...@@ -5700,6 +5700,9 @@ func TestFailFast(t *testing.T) { ...@@ -5700,6 +5700,9 @@ func TestFailFast(t *testing.T) {
// non-parallel subtests: // non-parallel subtests:
{"TestFailingSubtestsA", true, 1}, {"TestFailingSubtestsA", true, 1},
{"TestFailingSubtestsA", false, 2}, {"TestFailingSubtestsA", false, 2},
// fatal test
{"TestFatal[CD]", true, 1},
{"TestFatal[CD]", false, 2},
} }
for _, tt := range tests { for _, tt := range tests {
......
...@@ -52,3 +52,11 @@ func TestFailingSubtestsA(t *testing.T) { ...@@ -52,3 +52,11 @@ func TestFailingSubtestsA(t *testing.T) {
func TestFailingB(t *testing.T) { func TestFailingB(t *testing.T) {
t.Errorf("FAIL - %s", t.Name()) t.Errorf("FAIL - %s", t.Name())
} }
func TestFatalC(t *testing.T) {
t.Fatalf("FAIL - %s", t.Name())
}
func TestFatalD(t *testing.T) {
t.Fatalf("FAIL - %s", t.Name())
}
...@@ -731,6 +731,10 @@ func tRunner(t *T, fn func(t *T)) { ...@@ -731,6 +731,10 @@ func tRunner(t *T, fn func(t *T)) {
// a call to runtime.Goexit, record the duration and send // a call to runtime.Goexit, record the duration and send
// a signal saying that the test is done. // a signal saying that the test is done.
defer func() { defer func() {
if t.failed {
atomic.AddUint32(&numFailed, 1)
}
if t.raceErrors+race.Errors() > 0 { if t.raceErrors+race.Errors() > 0 {
t.Errorf("race detected during execution of test") t.Errorf("race detected during execution of test")
} }
...@@ -790,9 +794,7 @@ func tRunner(t *T, fn func(t *T)) { ...@@ -790,9 +794,7 @@ func tRunner(t *T, fn func(t *T)) {
t.raceErrors = -race.Errors() t.raceErrors = -race.Errors()
fn(t) fn(t)
if t.failed { // code beyond here will not be executed when FailNow is invoked
atomic.AddUint32(&numFailed, 1)
}
t.finished = true t.finished = true
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment