testing: avoid Goexit without unwind support

Goexit cannot run deferred functions on architectures without panic
unwinding. Query runtime.supportsRecover before calling it so unsupported
targets report an error instead of leaving the test runner blocked forever.
This commit is contained in:
Jake Bailey
2026-07-22 10:17:09 -07:00
committed by Damian Gryski
parent 9e7d89d4d5
commit 9e9be09e9a
2 changed files with 13 additions and 3 deletions
+12 -2
View File
@@ -25,6 +25,7 @@ import (
"time"
"unicode"
"unicode/utf8"
_ "unsafe"
)
// Testing flags.
@@ -215,7 +216,10 @@ func (c *common) Failed() bool {
func (c *common) FailNow() {
c.Fail()
c.finished = true
runtime.Goexit()
if supportsRecover() {
runtime.Goexit()
}
c.Error("FailNow is incomplete, requires runtime.Goexit()")
}
// log generates the output.
@@ -287,13 +291,19 @@ func (c *common) Skipf(format string, args ...any) {
func (c *common) SkipNow() {
c.skip()
c.finished = true
runtime.Goexit()
if supportsRecover() {
runtime.Goexit()
}
c.Error("SkipNow is incomplete, requires runtime.Goexit()")
}
func (c *common) skip() {
c.skipped = true
}
//go:linkname supportsRecover runtime.supportsRecover
func supportsRecover() bool
// Skipped reports whether the test was skipped.
func (c *common) Skipped() bool {
return c.skipped