Skip to content

Commit b189b5b

Browse files
committed
Push and Pop works for sub-goroutines + docs
1 parent bcca59e commit b189b5b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

assert/assert.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ const (
179179
// PushTester allows you to change the current default asserter by accepting it
180180
// as a second argument.
181181
//
182+
// Note that you MUST call PushTester for sub-goroutines:
183+
//
184+
// defer assert.PushTester(t)() // does the cleanup
185+
// ...
186+
// go func() {
187+
// assert.PushTester(t) // left cleanup out! Leave it for the test, see ^
188+
// ...
189+
//
182190
// Note that the second argument, if given, changes the default asserter for
183191
// whole package. The argument is mainly for temporary development use and isn't
184192
// not preferred API usage.
@@ -190,13 +198,7 @@ func PushTester(t testing.TB, a ...defInd) function {
190198
// it's good to keep the API as simple as possible
191199
SetDefault(TestFull)
192200
}
193-
testers.Tx(func(m testersMap) {
194-
rid := goid()
195-
if _, ok := m[rid]; ok {
196-
panic("PushTester is already called")
197-
}
198-
m[rid] = t
199-
})
201+
testers.Set(goid(), t)
200202
return PopTester
201203
}
202204

@@ -219,10 +221,7 @@ func PushTester(t testing.TB, a ...defInd) function {
219221
//
220222
// defer assert.PushTester(t)()
221223
func PopTester() {
222-
defer testers.Tx(func(m testersMap) {
223-
goid := goid()
224-
delete(m, goid)
225-
})
224+
defer testers.Del(goid())
226225

227226
r := recover()
228227
if r == nil {

0 commit comments

Comments
 (0)