@@ -113,7 +113,7 @@ func TestHandle_noerrHandler(t *testing.T) {
113
113
try .To1 (throw ())
114
114
})
115
115
116
- t .Run ("noerr is error order is first and error happens" , func (t * testing.T ) {
116
+ t .Run ("noerr is first and error happens" , func (t * testing.T ) {
117
117
t .Parallel ()
118
118
var err error
119
119
var handlerCalled bool
@@ -173,6 +173,8 @@ func TestHandle_noerrHandler(t *testing.T) {
173
173
handlerCalled = noerr
174
174
})
175
175
176
+ defer err2 .Handle (& err )
177
+
176
178
defer err2 .Handle (& err , func (err error ) error {
177
179
test .Require (t , false , "no error to handle!" )
178
180
// this should not be called, so lets try to fuckup things...
@@ -189,6 +191,44 @@ func TestHandle_noerrHandler(t *testing.T) {
189
191
try .To (noErr ())
190
192
})
191
193
194
+ t .Run ("noerr handler is first of MANY and error happens UNTIL reset" , func (t * testing.T ) {
195
+ t .Parallel ()
196
+ var err error
197
+ var noerrHandlerCalled , errHandlerCalled bool
198
+ defer func () {
199
+ test .Require (t , noerrHandlerCalled )
200
+ test .Require (t , errHandlerCalled )
201
+ }()
202
+
203
+ // This is the handler we are thesting!
204
+ defer err2 .Handle (& err , func (noerr bool ) {
205
+ test .Require (t , true )
206
+ test .Require (t , noerr )
207
+ noerrHandlerCalled = noerr
208
+ })
209
+
210
+ // this is the err handler that resets the error to nil
211
+ defer err2 .Handle (& err , func (err error ) error {
212
+ test .Require (t , true ) // helps fast debugging
213
+
214
+ // this should not be called, so lets try to fuckup things...
215
+ noerrHandlerCalled = false // see first deferred function
216
+ // keep the track that we have been here
217
+ errHandlerCalled = true // see first deferred function
218
+ return nil
219
+ })
220
+
221
+ defer err2 .Handle (& err , func (err error ) error {
222
+ test .Require (t , true ) // helps fast debugging
223
+ // this should not be called, so lets try to fuckup things...
224
+ noerrHandlerCalled = false // see first deferred function
225
+
226
+ errHandlerCalled = true // see first deferred function
227
+ return err
228
+ })
229
+ try .To1 (throw ())
230
+ })
231
+
192
232
t .Run ("noerr handler is middle of MANY and NO error happens" , func (t * testing.T ) {
193
233
t .Parallel ()
194
234
var err error
@@ -197,6 +237,8 @@ func TestHandle_noerrHandler(t *testing.T) {
197
237
test .Require (t , handlerCalled )
198
238
}()
199
239
240
+ defer err2 .Handle (& err )
241
+
200
242
defer err2 .Handle (& err , func (err error ) error {
201
243
test .Require (t , false , "no error to handle!" )
202
244
// this should not be called, so lets try to fuckup things...
0 commit comments