Skip to content

Commit 11f6c9f

Browse files
committed
PushAsserter impl stack with Pop function that's stroge, clever!
1 parent e5113f1 commit 11f6c9f

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

assert/assert.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,14 +1065,32 @@ func SetDefault(i Asserter) (old Asserter) {
10651065
// function:
10661066
//
10671067
// defer assert.PushAsserter(assert.Plain)()
1068-
func PushAsserter(i Asserter) func() {
1068+
func PushAsserter(i Asserter) (retFn function) {
1069+
var (
1070+
prevFound bool
1071+
prevAsserter asserter
1072+
)
1073+
10691074
// get pkg lvl asserter
10701075
curAsserter := defAsserter[def]
10711076
// .. to check if we are doing unit tests
10721077
if !curAsserter.isUnitTesting() {
1073-
// .. allow TLS specific asserter. NOTE see current()
1078+
// .. allow GLS specific asserter. NOTE see current()
10741079
curGoRID := goid()
1075-
asserterMap.Set(curGoRID, defAsserter[i])
1080+
//asserterMap.Set(curGoRID, defAsserter[i])
1081+
asserterMap.Tx(func(m map[int]asserter) {
1082+
cur, found := m[curGoRID]
1083+
if found {
1084+
prevAsserter = cur
1085+
prevFound = found
1086+
}
1087+
m[curGoRID] = defAsserter[i]
1088+
})
1089+
}
1090+
if prevFound {
1091+
return func() {
1092+
asserterMap.Set(goid(), prevAsserter)
1093+
}
10761094
}
10771095
return PopAsserter
10781096
}

0 commit comments

Comments
 (0)