container/stub: remove function call in handleExit
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m21s
Test / Hpkg (push) Successful in 4m21s
Test / Sandbox (race detector) (push) Successful in 4m44s
Test / Hakurei (race detector) (push) Successful in 5m24s
Test / Hakurei (push) Successful in 2m26s
Test / Flake checks (push) Successful in 1m36s
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m21s
Test / Hpkg (push) Successful in 4m21s
Test / Sandbox (race detector) (push) Successful in 4m44s
Test / Hakurei (race detector) (push) Successful in 5m24s
Test / Hakurei (push) Successful in 2m26s
Test / Flake checks (push) Successful in 1m36s
This gets inlined and does not cause problems usually but turns out -coverpkg uninlines it and breaks the recovery. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
19630a9593
commit
3920acf8c2
@ -149,7 +149,7 @@ func checkSimple(t *testing.T, fname string, testCases []simpleTestCase) {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
k := &kstub{stub.New(t, func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { return &kstub{s} }, tc.want)}
|
k := &kstub{stub.New(t, func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { return &kstub{s} }, tc.want)}
|
||||||
defer k.HandleExit()
|
defer stub.HandleExit(t)
|
||||||
if err := tc.f(k); !reflect.DeepEqual(err, tc.wantErr) {
|
if err := tc.f(k); !reflect.DeepEqual(err, tc.wantErr) {
|
||||||
t.Errorf("%s: error = %v, want %v", fname, err, tc.wantErr)
|
t.Errorf("%s: error = %v, want %v", fname, err, tc.wantErr)
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func checkOpBehaviour(t *testing.T, testCases []opBehaviourTestCase) {
|
|||||||
func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { return &kstub{s} },
|
func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { return &kstub{s} },
|
||||||
stub.Expect{Calls: slices.Concat(tc.early, []stub.Call{{Name: stub.CallSeparator}}, tc.apply)},
|
stub.Expect{Calls: slices.Concat(tc.early, []stub.Call{{Name: stub.CallSeparator}}, tc.apply)},
|
||||||
)}
|
)}
|
||||||
defer k.HandleExit()
|
defer stub.HandleExit(t)
|
||||||
errEarly := tc.op.early(state, k)
|
errEarly := tc.op.early(state, k)
|
||||||
k.Expects(stub.CallSeparator)
|
k.Expects(stub.CallSeparator)
|
||||||
if !reflect.DeepEqual(errEarly, tc.wantErrEarly) {
|
if !reflect.DeepEqual(errEarly, tc.wantErrEarly) {
|
||||||
|
@ -12,20 +12,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// HandleExit must be deferred before calling with the stub.
|
// HandleExit must be deferred before calling with the stub.
|
||||||
func (s *Stub[K]) HandleExit() { handleExit(s.TB, true) }
|
func HandleExit(t testing.TB) {
|
||||||
|
|
||||||
func handleExit(t testing.TB, root bool) {
|
|
||||||
switch r := recover(); r {
|
switch r := recover(); r {
|
||||||
case PanicExit:
|
case PanicExit:
|
||||||
break
|
break
|
||||||
|
|
||||||
case panicFailNow:
|
case panicFailNow:
|
||||||
if root {
|
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
} else {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
break
|
|
||||||
|
|
||||||
case panicFatal, panicFatalf, nil:
|
case panicFatal, panicFatalf, nil:
|
||||||
break
|
break
|
||||||
@ -34,3 +27,18 @@ func handleExit(t testing.TB, root bool) {
|
|||||||
panic(r)
|
panic(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleExitNew handles exits from goroutines created by [Stub.New].
|
||||||
|
func handleExitNew(t testing.TB) {
|
||||||
|
switch r := recover(); r {
|
||||||
|
case PanicExit, panicFatal, panicFatalf, nil:
|
||||||
|
break
|
||||||
|
|
||||||
|
case panicFailNow:
|
||||||
|
t.Fail()
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
"hakurei.app/container/stub"
|
"hakurei.app/container/stub"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:linkname handleExit hakurei.app/container/stub.handleExit
|
//go:linkname handleExitNew hakurei.app/container/stub.handleExitNew
|
||||||
func handleExit(_ testing.TB, _ bool)
|
func handleExitNew(_ testing.TB)
|
||||||
|
|
||||||
// overrideTFailNow overrides the Fail and FailNow method.
|
// overrideTFailNow overrides the Fail and FailNow method.
|
||||||
type overrideTFailNow struct {
|
type overrideTFailNow struct {
|
||||||
@ -33,7 +33,7 @@ func (o *overrideTFailNow) Fail() {
|
|||||||
|
|
||||||
func TestHandleExit(t *testing.T) {
|
func TestHandleExit(t *testing.T) {
|
||||||
t.Run("exit", func(t *testing.T) {
|
t.Run("exit", func(t *testing.T) {
|
||||||
defer handleExit(t, true)
|
defer stub.HandleExit(t)
|
||||||
panic(stub.PanicExit)
|
panic(stub.PanicExit)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ func TestHandleExit(t *testing.T) {
|
|||||||
t.Errorf("FailNow was never called")
|
t.Errorf("FailNow was never called")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
defer handleExit(ot, true)
|
defer stub.HandleExit(ot)
|
||||||
panic(0xcafe0000)
|
panic(0xcafe0000)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -56,16 +56,17 @@ func TestHandleExit(t *testing.T) {
|
|||||||
t.Errorf("Fail was never called")
|
t.Errorf("Fail was never called")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
defer handleExit(ot, false)
|
defer handleExitNew(ot)
|
||||||
panic(0xcafe0000)
|
panic(0xcafe0000)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("nil", func(t *testing.T) {
|
t.Run("nil", func(t *testing.T) {
|
||||||
defer handleExit(t, true)
|
defer stub.HandleExit(t)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("passthrough", func(t *testing.T) {
|
t.Run("passthrough", func(t *testing.T) {
|
||||||
|
t.Run("toplevel", func(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
want := 0xcafebabe
|
want := 0xcafebabe
|
||||||
if r := recover(); r != want {
|
if r := recover(); r != want {
|
||||||
@ -73,7 +74,20 @@ func TestHandleExit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
defer handleExit(t, true)
|
defer stub.HandleExit(t)
|
||||||
panic(0xcafebabe)
|
panic(0xcafebabe)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("new", func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
want := 0xcafe
|
||||||
|
if r := recover(); r != want {
|
||||||
|
t.Errorf("recover: %v, want %v", r, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
}()
|
||||||
|
defer handleExitNew(t)
|
||||||
|
panic(0xcafe)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (s *Stub[K]) New(f func(k K)) {
|
|||||||
s.Helper()
|
s.Helper()
|
||||||
|
|
||||||
defer s.wg.Done()
|
defer s.wg.Done()
|
||||||
defer handleExit(s.TB, false)
|
defer handleExitNew(s.TB)
|
||||||
f(s.makeK(ds))
|
f(s.makeK(ds))
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ func TestStub(t *testing.T) {
|
|||||||
{"New", ExpectArgs{}, nil, nil},
|
{"New", ExpectArgs{}, nil, nil},
|
||||||
{"panic", ExpectArgs{"unreachable"}, nil, nil},
|
{"panic", ExpectArgs{"unreachable"}, nil, nil},
|
||||||
}})
|
}})
|
||||||
func() { defer s.HandleExit(); s.New(func(k stubHolder) { panic("unreachable") }) }()
|
func() { defer HandleExit(t); s.New(func(k stubHolder) { panic("unreachable") }) }()
|
||||||
|
|
||||||
var visit int
|
var visit int
|
||||||
s.VisitIncomplete(func(s *Stub[stubHolder]) {
|
s.VisitIncomplete(func(s *Stub[stubHolder]) {
|
||||||
@ -139,7 +139,7 @@ func TestStub(t *testing.T) {
|
|||||||
ot := &overrideT{T: t}
|
ot := &overrideT{T: t}
|
||||||
ot.error.Store(checkError(t, "Expects: advancing beyond expected calls"))
|
ot.error.Store(checkError(t, "Expects: advancing beyond expected calls"))
|
||||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{})
|
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{})
|
||||||
func() { defer s.HandleExit(); s.Expects("unreachable") }()
|
func() { defer HandleExit(t); s.Expects("unreachable") }()
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("separator", func(t *testing.T) {
|
t.Run("separator", func(t *testing.T) {
|
||||||
@ -149,7 +149,7 @@ func TestStub(t *testing.T) {
|
|||||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||||
{CallSeparator, ExpectArgs{}, nil, nil},
|
{CallSeparator, ExpectArgs{}, nil, nil},
|
||||||
}})
|
}})
|
||||||
func() { defer s.HandleExit(); s.Expects("meow") }()
|
func() { defer HandleExit(t); s.Expects("meow") }()
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("mismatch", func(t *testing.T) {
|
t.Run("mismatch", func(t *testing.T) {
|
||||||
@ -158,7 +158,7 @@ func TestStub(t *testing.T) {
|
|||||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||||
{"panic", ExpectArgs{}, nil, nil},
|
{"panic", ExpectArgs{}, nil, nil},
|
||||||
}})
|
}})
|
||||||
func() { defer s.HandleExit(); s.Expects(CallSeparator) }()
|
func() { defer HandleExit(t); s.Expects(CallSeparator) }()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ func TestStub(t *testing.T) {
|
|||||||
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{
|
||||||
{"nya", ExpectArgs{}, nil, nil},
|
{"nya", ExpectArgs{}, nil, nil},
|
||||||
}})
|
}})
|
||||||
func() { defer s.HandleExit(); s.Expects("meow") }()
|
func() { defer HandleExit(t); s.Expects("meow") }()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -198,7 +198,7 @@ func TestCheckArg(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("mismatch", func(t *testing.T) {
|
t.Run("mismatch", func(t *testing.T) {
|
||||||
defer s.HandleExit()
|
defer HandleExit(t)
|
||||||
s.Expects("meow")
|
s.Expects("meow")
|
||||||
ot.errorf.Store(checkErrorf(t, "%s: %s = %#v, want %#v (%d)", "meow", "time", 0, -1, 1))
|
ot.errorf.Store(checkErrorf(t, "%s: %s = %#v, want %#v (%d)", "meow", "time", 0, -1, 1))
|
||||||
if CheckArg(s, "time", 0, 0) {
|
if CheckArg(s, "time", 0, 0) {
|
||||||
@ -241,7 +241,7 @@ func TestCheckArgReflect(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("mismatch", func(t *testing.T) {
|
t.Run("mismatch", func(t *testing.T) {
|
||||||
defer s.HandleExit()
|
defer HandleExit(t)
|
||||||
s.Expects("meow")
|
s.Expects("meow")
|
||||||
ot.errorf.Store(checkErrorf(t, "%s: %s = %#v, want %#v (%d)", "meow", "time", 0, -1, 1))
|
ot.errorf.Store(checkErrorf(t, "%s: %s = %#v, want %#v (%d)", "meow", "time", 0, -1, 1))
|
||||||
if CheckArgReflect(s, "time", 0, 0) {
|
if CheckArgReflect(s, "time", 0, 0) {
|
||||||
|
@ -44,7 +44,7 @@ func checkOpBehaviour(t *testing.T, testCases []opBehaviourTestCase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sys, s := InternalNew(t, stub.Expect{Calls: slices.Concat(tc.apply, []stub.Call{{Name: stub.CallSeparator}}, tc.revert)}, tc.uid)
|
sys, s := InternalNew(t, stub.Expect{Calls: slices.Concat(tc.apply, []stub.Call{{Name: stub.CallSeparator}}, tc.revert)}, tc.uid)
|
||||||
defer s.HandleExit()
|
defer stub.HandleExit(t)
|
||||||
errApply := tc.op.apply(sys)
|
errApply := tc.op.apply(sys)
|
||||||
s.Expects(stub.CallSeparator)
|
s.Expects(stub.CallSeparator)
|
||||||
if !reflect.DeepEqual(errApply, tc.wantErrApply) {
|
if !reflect.DeepEqual(errApply, tc.wantErrApply) {
|
||||||
@ -91,7 +91,7 @@ func checkOpsBuilder(t *testing.T, fname string, testCases []opsBuilderTestCase)
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
sys, s := InternalNew(t, tc.exp, tc.uid)
|
sys, s := InternalNew(t, tc.exp, tc.uid)
|
||||||
defer s.HandleExit()
|
defer stub.HandleExit(t)
|
||||||
tc.f(sys)
|
tc.f(sys)
|
||||||
s.VisitIncomplete(func(s *stub.Stub[syscallDispatcher]) {
|
s.VisitIncomplete(func(s *stub.Stub[syscallDispatcher]) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user