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>
37 lines
568 B
Go
37 lines
568 B
Go
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 (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)
|
|
}
|
|
}
|