mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: send t.signal only if there is no panic
If a signal is sent to t.signal before the panic is triggered, a panicking test may end up with "warning: no tests to run" because the tRunner that invokes the test in t.Run calls runtime.Goexit on panic, which causes the panicking test not be recorded in runTests. Send the signal if and only if there is no panic. Fixes #41479 Change-Id: I812f1303bfe02c443a1902732e68d21620d6672e Reviewed-on: https://go-review.googlesource.com/c/go/+/256098 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Trust: Emmanuel Odeke <emm.odeke@gmail.com> Trust: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
428509402b
commit
4cba6c703f
2 changed files with 22 additions and 2 deletions
|
|
@ -1091,10 +1091,16 @@ func tRunner(t *T, fn func(t *T)) {
|
|||
// complete even if a cleanup function calls t.FailNow. See issue 41355.
|
||||
didPanic := false
|
||||
defer func() {
|
||||
t.signal <- signal
|
||||
if err != nil && !didPanic {
|
||||
if didPanic {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Only report that the test is complete if it doesn't panic,
|
||||
// as otherwise the test binary can exit before the panic is
|
||||
// reported to the user. See issue 41479.
|
||||
t.signal <- signal
|
||||
}()
|
||||
|
||||
doPanic := func(err interface{}) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue