mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
runtime, testing: support Goexit, SkipNow, FailNow
Keep a pending Goexit separate from the active panic state so recovered deferred panics do not cancel the original Goexit unwind. Goexit should also ignore -panic=trap, since it is not a panic. Wire testing.FailNow and SkipNow through runtime.Goexit, and run tests and benchmarks in goroutines. This lets Goexit terminate the user function without skipping test bookkeeping. Add Goexit/recover coverage and enable crypto/ecdh in the Linux stdlib test list.
This commit is contained in:
Vendored
+65
@@ -158,6 +158,71 @@ func runtimeGoexit() {
|
||||
runtime.Goexit()
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runtimeGoexitRecoveredPanic()
|
||||
println("unreachable after Goexit helper")
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runtimeGoexitNestedRecoveredPanic()
|
||||
println("unreachable after nested Goexit helper")
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
runtimeGoexitLoopDefers()
|
||||
println("unreachable after loop Goexit helper")
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func runtimeGoexitRecoveredPanic() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
printitf("Goexit recovered deferred panic:", r)
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
panic("panic during Goexit")
|
||||
}()
|
||||
runtime.Goexit()
|
||||
}
|
||||
|
||||
func runtimeGoexitNestedRecoveredPanic() {
|
||||
defer func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
printitf("Goexit nested recovered deferred panic:", r)
|
||||
}
|
||||
}()
|
||||
panic("nested panic during Goexit")
|
||||
}()
|
||||
runtime.Goexit()
|
||||
}
|
||||
|
||||
func runtimeGoexitLoopDefers() {
|
||||
for i := 0; i < 2; i++ {
|
||||
defer func() {
|
||||
println("Goexit loop defer")
|
||||
}()
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
printitf("Goexit loop recovered deferred panic:", r)
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
panic("loop panic during Goexit")
|
||||
}()
|
||||
runtime.Goexit()
|
||||
}
|
||||
|
||||
// Test that a repanic inside a deferred function propagates correctly
|
||||
|
||||
Reference in New Issue
Block a user