Skip to content

Commit ee26b3d

Browse files
committed
readability and typos
1 parent 01fe351 commit ee26b3d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

err2_test.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestHandle_noerrHandler(t *testing.T) {
6464
defer func() {
6565
test.Require(t, handlerCalled)
6666
}()
67-
// This is the handler we are thesting!
67+
// This is the handler we are testing!
6868
defer err2.Handle(&err, func(noerr bool) {
6969
handlerCalled = noerr
7070
})
@@ -86,7 +86,7 @@ func TestHandle_noerrHandler(t *testing.T) {
8686
return err
8787
})
8888

89-
// This is the handler we are thesting!
89+
// This is the handler we are testing!
9090
defer err2.Handle(&err, func(noerr bool) {
9191
handlerCalled = noerr
9292
})
@@ -101,16 +101,18 @@ func TestHandle_noerrHandler(t *testing.T) {
101101
defer func() {
102102
test.Require(t, !handlerCalled)
103103
}()
104+
105+
// This is the handler we are testing!
104106
defer err2.Handle(&err, func(err error) error {
107+
test.Require(t, !handlerCalled)
105108
handlerCalled = false
106109
test.Require(t, true, "error should be handled")
107110
return err
108111
})
109112

110-
// This is the handler we are thesting!
111-
defer err2.Handle(&err, func(noerr bool) {
112-
test.Require(t, noerr)
113-
handlerCalled = noerr
113+
// This is the handler we are testing! AND it's not called in error.
114+
defer err2.Handle(&err, func(bool) {
115+
test.Require(t, false, "when error this is not called")
114116
})
115117

116118
try.To1(throw())
@@ -122,13 +124,15 @@ func TestHandle_noerrHandler(t *testing.T) {
122124
err error
123125
finalAnnotatedErr = fmt.Errorf("err: %v", errStringInThrow)
124126
handlerCalled bool
127+
callCount int
125128
)
126129
defer func() {
127130
test.Require(t, !handlerCalled)
131+
test.Require(t, callCount == 2)
128132
test.RequireEqual(t, err.Error(), finalAnnotatedErr.Error())
129133
}()
130134

131-
// This is the handler we are thesting!
135+
// This is the handler we are testing! AND it's not called in error.
132136
defer err2.Handle(&err, func(noerr bool) {
133137
test.Require(t, false, "if error occurs/reset, this cannot happen")
134138
handlerCalled = noerr
@@ -138,11 +142,15 @@ func TestHandle_noerrHandler(t *testing.T) {
138142
// and it's not nil
139143
defer err2.Handle(&err, func(er error) error {
140144
test.Require(t, er != nil, "er val: ", er, err)
145+
test.Require(t, callCount == 1, "this is called in sencond")
146+
callCount++
141147
return er
142148
})
143149

144150
defer err2.Handle(&err, func(err error) error {
145151
// this should not be called, so lets try to fuckup things...
152+
test.Require(t, callCount == 0, "this is called in first")
153+
callCount++
146154
handlerCalled = false
147155
test.Require(t, err != nil)
148156
return finalAnnotatedErr
@@ -158,7 +166,7 @@ func TestHandle_noerrHandler(t *testing.T) {
158166
test.Require(t, handlerCalled)
159167
}()
160168

161-
// This is the handler we are thesting!
169+
// This is the handler we are testing!
162170
defer err2.Handle(&err, func(noerr bool) {
163171
test.Require(t, noerr)
164172
handlerCalled = noerr
@@ -181,8 +189,9 @@ func TestHandle_noerrHandler(t *testing.T) {
181189
test.Require(t, handlerCalled)
182190
}()
183191

184-
// This is the handler we are thesting!
192+
// This is the handler we are testing!
185193
defer err2.Handle(&err, func(noerr bool) {
194+
test.Require(t, true)
186195
test.Require(t, noerr)
187196
handlerCalled = noerr
188197
})
@@ -214,7 +223,7 @@ func TestHandle_noerrHandler(t *testing.T) {
214223
test.Require(t, errHandlerCalled)
215224
}()
216225

217-
// This is the handler we are thesting!
226+
// This is the handler we are testing!
218227
defer err2.Handle(&err, func(noerr bool) {
219228
test.Require(t, true) // we are here, for debugging
220229
test.Require(t, noerr)
@@ -261,8 +270,9 @@ func TestHandle_noerrHandler(t *testing.T) {
261270
return err
262271
})
263272

264-
// This is the handler we are thesting!
273+
// This is the handler we are testing!
265274
defer err2.Handle(&err, func(noerr bool) {
275+
test.Require(t, true, "this must be called")
266276
test.Require(t, noerr)
267277
handlerCalled = noerr
268278
})

0 commit comments

Comments
 (0)