{ // parent *common sub []*T signal chan bool } func (t *T) Run(name string, f func(t *T)) bool { // t = &T{ common: common{ // parent: &t.common, level: t.level + 1, }, context: t.context, } // go tRunner(t, f) // } type panicHandling int const ( normalPanic panicHandling = iota recoverAndReturnPanic ) func tRunner(t *T, fn func(t *T)) { // defer func() { // signal := true // defer func() { // t.signal <- signal }() // if len(t.sub) > 0 { // // Wait for subtests to complete. for _, sub := range t.sub { <-sub.signal } // err := t.runCleanup(recoverAndReturnPanic) // } // }() defer func() { if len(t.sub) == 0 { t.runCleanup(normalPanic) } }() // fn(t) // } (1) (2) (3) func (c *common) runCleanup( ph panicHandling ) (panicVal any) { // for { var cleanup func() c.mu.Lock() if len(c.cleanups) > 0 { last := len(c.cleanups) - 1 cleanup = c.cleanups[last] c.cleanups = c.cleanups[:last] } c.mu.Unlock() if cleanup == nil { return nil } cleanup() } }