@@ -42,6 +42,99 @@ func (s *SuiteRequireTwice) TestRequireTwo() {
42
42
r .Equal (1 , 2 )
43
43
}
44
44
45
+ type panickingSuite struct {
46
+ Suite
47
+ panicInSetupSuite bool
48
+ panicInSetupTest bool
49
+ panicInBeforeTest bool
50
+ panicInTest bool
51
+ panicInAfterTest bool
52
+ panicInTearDownTest bool
53
+ panicInTearDownSuite bool
54
+ }
55
+
56
+ func (s * panickingSuite ) SetupSuite () {
57
+ if s .panicInSetupSuite {
58
+ panic ("oops in setup suite" )
59
+ }
60
+ }
61
+
62
+ func (s * panickingSuite ) SetupTest () {
63
+ if s .panicInSetupTest {
64
+ panic ("oops in setup test" )
65
+ }
66
+ }
67
+
68
+ func (s * panickingSuite ) BeforeTest (_ , _ string ) {
69
+ if s .panicInBeforeTest {
70
+ panic ("oops in before test" )
71
+ }
72
+ }
73
+
74
+ func (s * panickingSuite ) Test () {
75
+ if s .panicInTest {
76
+ panic ("oops in test" )
77
+ }
78
+ }
79
+
80
+ func (s * panickingSuite ) AfterTest (_ , _ string ) {
81
+ if s .panicInAfterTest {
82
+ panic ("oops in after test" )
83
+ }
84
+ }
85
+
86
+ func (s * panickingSuite ) TearDownTest () {
87
+ if s .panicInTearDownTest {
88
+ panic ("oops in tear down test" )
89
+ }
90
+ }
91
+
92
+ func (s * panickingSuite ) TearDownSuite () {
93
+ if s .panicInTearDownSuite {
94
+ panic ("oops in tear down suite" )
95
+ }
96
+ }
97
+
98
+ func TestSuiteRecoverPanic (t * testing.T ) {
99
+ ok := true
100
+ panickingTests := []testing.InternalTest {
101
+ {
102
+ Name : "TestPanicInSetupSuite" ,
103
+ F : func (t * testing.T ) { Run (t , & panickingSuite {panicInSetupSuite : true }) },
104
+ },
105
+ {
106
+ Name : "TestPanicInSetupTest" ,
107
+ F : func (t * testing.T ) { Run (t , & panickingSuite {panicInSetupTest : true }) },
108
+ },
109
+ {
110
+ Name : "TestPanicInBeforeTest" ,
111
+ F : func (t * testing.T ) { Run (t , & panickingSuite {panicInBeforeTest : true }) },
112
+ },
113
+ {
114
+ Name : "TestPanicInTest" ,
115
+ F : func (t * testing.T ) { Run (t , & panickingSuite {panicInTest : true }) },
116
+ },
117
+ {
118
+ Name : "TestPanicInAfterTest" ,
119
+ F : func (t * testing.T ) { Run (t , & panickingSuite {panicInAfterTest : true }) },
120
+ },
121
+ {
122
+ Name : "TestPanicInTearDownTest" ,
123
+ F : func (t * testing.T ) { Run (t , & panickingSuite {panicInTearDownTest : true }) },
124
+ },
125
+ {
126
+ Name : "TestPanicInTearDownSuite" ,
127
+ F : func (t * testing.T ) { Run (t , & panickingSuite {panicInTearDownSuite : true }) },
128
+ },
129
+ }
130
+
131
+ require .NotPanics (t , func () {
132
+ ok = testing .RunTests (allTestsFilter , panickingTests )
133
+ })
134
+
135
+ assert .False (t , ok )
136
+ }
137
+
45
138
// This suite is intended to store values to make sure that only
46
139
// testing-suite-related methods are run. It's also a fully
47
140
// functional example of a testing suite, using setup/teardown methods
0 commit comments