Skip to content

Commit

Permalink
test: add suite tests for panicking of subtests
Browse files Browse the repository at this point in the history
  • Loading branch information
linusbarth authored and dolmen committed Oct 30, 2023
1 parent a4a54a4 commit 7df1a82
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions suite/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,45 @@ func (s *FailfastSuite) Test_B_Passes() {
s.call("Test B Passes")
s.Require().True(true)
}

type subtestPanicSuite struct {
Suite
inTearDownSuite bool
inTearDownTest bool
inTearDownSubTest bool
}

func (s *subtestPanicSuite) TearDownSuite() {
s.inTearDownSuite = true
}

func (s *subtestPanicSuite) TearDownTest() {
s.inTearDownTest = true
}

func (s *subtestPanicSuite) TearDownSubTest() {
s.inTearDownSubTest = true
}

func (s *subtestPanicSuite) TestSubtestPanic() {
s.Run("subtest", func() {
panic("panic")
})
}

func TestSubtestPanic(t *testing.T) {
suite := new(subtestPanicSuite)
ok := testing.RunTests(
allTestsFilter,
[]testing.InternalTest{{
Name: "TestSubtestPanic",
F: func(t *testing.T) {
Run(t, suite)
},
}},
)
assert.False(t, ok)
assert.True(t, suite.inTearDownSubTest)
assert.True(t, suite.inTearDownTest)
assert.True(t, suite.inTearDownSuite)
}

0 comments on commit 7df1a82

Please sign in to comment.