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: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
// non-parallel subtests:
{"TestFailingSubtestsA", true, 1},
{"TestFailingSubtestsA", false, 2},
+ // fatal test
+ {"TestFatal[CD]", true, 1},
+ {"TestFatal[CD]", false, 2},
}
for _, tt := range tests {
func TestFailingB(t *testing.T) {
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())
+}
// a call to runtime.Goexit, record the duration and send
// a signal saying that the test is done.
defer func() {
+ if t.failed {
+ atomic.AddUint32(&numFailed, 1)
+ }
+
if t.raceErrors+race.Errors() > 0 {
t.Errorf("race detected during execution of test")
}
t.raceErrors = -race.Errors()
fn(t)
- if t.failed {
- atomic.AddUint32(&numFailed, 1)
- }
+ // code beyond here will not be executed when FailNow is invoked
t.finished = true
}