Skip to content

Commit 56256a7

Browse files
committed
more norrr test cases
1 parent c432749 commit 56256a7

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

err2_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestHandle_noerrHandler(t *testing.T) {
113113
try.To1(throw())
114114
})
115115

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) {
117117
t.Parallel()
118118
var err error
119119
var handlerCalled bool
@@ -173,6 +173,8 @@ func TestHandle_noerrHandler(t *testing.T) {
173173
handlerCalled = noerr
174174
})
175175

176+
defer err2.Handle(&err)
177+
176178
defer err2.Handle(&err, func(err error) error {
177179
test.Require(t, false, "no error to handle!")
178180
// this should not be called, so lets try to fuckup things...
@@ -189,6 +191,44 @@ func TestHandle_noerrHandler(t *testing.T) {
189191
try.To(noErr())
190192
})
191193

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+
192232
t.Run("noerr handler is middle of MANY and NO error happens", func(t *testing.T) {
193233
t.Parallel()
194234
var err error
@@ -197,6 +237,8 @@ func TestHandle_noerrHandler(t *testing.T) {
197237
test.Require(t, handlerCalled)
198238
}()
199239

240+
defer err2.Handle(&err)
241+
200242
defer err2.Handle(&err, func(err error) error {
201243
test.Require(t, false, "no error to handle!")
202244
// this should not be called, so lets try to fuckup things...

0 commit comments

Comments
 (0)