-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/test2json: do not emit a final Action if the result is not known
If we are parsing a test output, and the test does not end in the usual PASS or FAIL line (say, because it panicked), then we need the exit status of the test binary in order to determine whether the test passed or failed. If we don't have that status available, we shouldn't guess arbitrarily — instead, we should omit the final "pass" or "fail" action entirely. (In practice, we nearly always DO have the final status, such as when running 'go test' or 'go tool test2json some.exe'.) Fixes golang#40132 Change-Id: Iae482577361a6033395fe4a05d746b980e18c3de Reviewed-on: https://go-review.googlesource.com/c/go/+/248624 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
- Loading branch information
Bryan C. Mills
committed
Aug 17, 2020
1 parent
f30044a
commit 1b86bdb
Showing
6 changed files
with
139 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
[short] skip | ||
|
||
go test -c -o mainpanic.exe ./mainpanic & | ||
go test -c -o mainexit0.exe ./mainexit0 & | ||
go test -c -o testpanic.exe ./testpanic & | ||
go test -c -o testbgpanic.exe ./testbgpanic & | ||
wait | ||
|
||
# Test binaries that panic in TestMain should be marked as failing. | ||
|
||
! go test -json ./mainpanic | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
! go tool test2json ./mainpanic.exe | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
# Test binaries that exit with status 0 should be marked as passing. | ||
|
||
go test -json ./mainexit0 | ||
stdout '"Action":"pass"' | ||
! stdout '"Action":"fail"' | ||
|
||
go tool test2json ./mainexit0.exe | ||
stdout '"Action":"pass"' | ||
! stdout '"Action":"fail"' | ||
|
||
# Test functions that panic should never be marked as passing | ||
# (https://golang.org/issue/40132). | ||
|
||
! go test -json ./testpanic | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
! go tool test2json ./testpanic.exe -test.v | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
! go tool test2json ./testpanic.exe | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
# Tests that panic in a background goroutine should be marked as failing. | ||
|
||
! go test -json ./testbgpanic | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
! go tool test2json ./testbgpanic.exe -test.v | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
! go tool test2json ./testbgpanic.exe | ||
stdout '"Action":"fail"' | ||
! stdout '"Action":"pass"' | ||
|
||
-- go.mod -- | ||
module m | ||
go 1.14 | ||
-- mainpanic/mainpanic_test.go -- | ||
package mainpanic_test | ||
|
||
import "testing" | ||
|
||
func TestMain(m *testing.M) { | ||
panic("haha no") | ||
} | ||
-- mainexit0/mainexit0_test.go -- | ||
package mainexit0_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
fmt.Println("nothing to do") | ||
os.Exit(0) | ||
} | ||
-- testpanic/testpanic_test.go -- | ||
package testpanic_test | ||
|
||
import "testing" | ||
|
||
func TestPanic(*testing.T) { | ||
panic("haha no") | ||
} | ||
-- testbgpanic/testbgpanic_test.go -- | ||
package testbgpanic_test | ||
|
||
import "testing" | ||
|
||
func TestPanicInBackground(*testing.T) { | ||
c := make(chan struct{}) | ||
go func() { | ||
panic("haha no") | ||
close(c) | ||
}() | ||
<-c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
{"Action":"pass"} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters