Skip to content

Commit

Permalink
Add failing test for 'missing Done' detection failure
Browse files Browse the repository at this point in the history
Add a failing test for a 'missing Done' detection failure: a Defer
called from a defered function must have another matching Done.
  • Loading branch information
dolmen committed Jun 10, 2023
1 parent d07c1d3 commit e7bb3ab
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ func TestCDeferWithoutDone(t *testing.T) {
c.Assert(tc.cleanup, qt.PanicMatches, `Done not called after Defer`)
}

func TestCDeferFromDefer(t *testing.T) {
c := qt.New(t)
tc := &testingTWithCleanup{
TB: t,
cleanup: func() {},
}
c1 := qt.New(tc)
c1.Defer(func() {
c1.Log("defer 1")
// This defer is triggered from the first Done().
// It should have its own Done() call too.
c1.Defer(func() {
c1.Log("defer 2")
})
})
c1.Done()
// Check that we report the missing second Done().
c.Assert(tc.cleanup, qt.PanicMatches, `Done not called after Defer`)
}

func TestCDeferVsCleanupOrder(t *testing.T) {
c := qt.New(t)
var defers []int
Expand Down

0 comments on commit e7bb3ab

Please sign in to comment.