diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-04 04:51:49 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-04 04:51:49 +0900 |
| commit | 4051577d6b037e9d9dbeaa8817b906f7b3a8eb26 (patch) | |
| tree | 23b7c68ad3128cf980c4ede60cfe99ddf557cc51 /container/stub/exit.go | |
| parent | ddfb865e2d526485935099a8cd454929ed5f6176 (diff) | |
container/stub: override goexit methods
FailNow, Fatal, Fatalf, SkipNow, Skip and Skipf must be called from the goroutine created by the test.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/stub/exit.go')
| -rw-r--r-- | container/stub/exit.go | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/container/stub/exit.go b/container/stub/exit.go index 8d859461..0f44b5dc 100644 --- a/container/stub/exit.go +++ b/container/stub/exit.go @@ -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) } } |
