container/stub: override goexit methods
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 1m52s
Test / Hpkg (push) Successful in 3m34s
Test / Sandbox (race detector) (push) Successful in 4m29s
Test / Hakurei (race detector) (push) Successful in 5m25s
Test / Hakurei (push) Successful in 2m25s
Test / Flake checks (push) Successful in 1m36s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 1m52s
Test / Hpkg (push) Successful in 3m34s
Test / Sandbox (race detector) (push) Successful in 4m29s
Test / Hakurei (race detector) (push) Successful in 5m25s
Test / Hakurei (push) Successful in 2m25s
Test / Flake checks (push) Successful in 1m36s
FailNow, Fatal, Fatalf, SkipNow, Skip and Skipf must be called from the goroutine created by the test. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -1,15 +1,36 @@
|
||||
package stub
|
||||
|
||||
import "testing"
|
||||
|
||||
// PanicExit is a magic panic value treated as a simulated exit.
|
||||
const PanicExit = 0xdeadbeef
|
||||
|
||||
const (
|
||||
panicFailNow = 0xcafe0000 + iota
|
||||
panicFatal
|
||||
panicFatalf
|
||||
)
|
||||
|
||||
// HandleExit must be deferred before calling with the stub.
|
||||
func HandleExit() {
|
||||
r := recover()
|
||||
if r == PanicExit {
|
||||
return
|
||||
}
|
||||
if r != nil {
|
||||
func (s *Stub[K]) HandleExit() { handleExit(s.TB, true) }
|
||||
|
||||
func handleExit(t testing.TB, root bool) {
|
||||
switch r := recover(); r {
|
||||
case PanicExit:
|
||||
break
|
||||
|
||||
case panicFailNow:
|
||||
if root {
|
||||
t.FailNow()
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
break
|
||||
|
||||
case panicFatal, panicFatalf, nil:
|
||||
break
|
||||
|
||||
default:
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user