]> Cypherpunks repositories - gostls13.git/commitdiff
testing: failfast fails fast when Fatal called
authorfraenkel <michael.fraenkel@gmail.com>
Fri, 16 Mar 2018 02:37:01 +0000 (22:37 -0400)
committerIan Lance Taylor <iant@golang.org>
Tue, 17 Apr 2018 04:02:53 +0000 (04:02 +0000)
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>
src/cmd/go/go_test.go
src/cmd/go/testdata/src/failfast_test.go
src/testing/testing.go

index ffedcff3d9bdc12a124efae41674e242d1175a51..add30867db3e2b622e7125e7056a54821c13c955 100644 (file)
@@ -5700,6 +5700,9 @@ func TestFailFast(t *testing.T) {
                // non-parallel subtests:
                {"TestFailingSubtestsA", true, 1},
                {"TestFailingSubtestsA", false, 2},
+               // fatal test
+               {"TestFatal[CD]", true, 1},
+               {"TestFatal[CD]", false, 2},
        }
 
        for _, tt := range tests {
index fef4d2a35e1cd117262827073c49565a85fe6d6a..6e64d73fdf9a923d6d43dc91015ba855100a74ef 100644 (file)
@@ -52,3 +52,11 @@ func TestFailingSubtestsA(t *testing.T) {
 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())
+}
index 686e77029ac370c8c24597b34d46e9d0de4a78e6..12e2a8e692549ea44e0a8680a31a73a5e64beed9 100644 (file)
@@ -731,6 +731,10 @@ func tRunner(t *T, fn func(t *T)) {
        // 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")
                }
@@ -790,9 +794,7 @@ func tRunner(t *T, fn func(t *T)) {
        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
 }