@@ -291,37 +291,6 @@ func ThatNot(term bool, a ...any) {
291
291
}
292
292
}
293
293
294
- func ZeroX [T Number ](val T , a ... any ) {
295
- if val != 0 {
296
- doZeroX (val , a )
297
- }
298
- }
299
-
300
- func doZeroX [T Number ](val T , a []any ) {
301
- defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want (== '0')" , val )
302
- currentX ().reportAssertionFault (1 , defMsg , a )
303
- }
304
-
305
- func currentX () (curAsserter asserter ) {
306
- // we need thread local storage, maybe we'll implement that to x.package?
307
- // study `tester` and copy ideas from it.
308
- tlsID := goid ()
309
- asserterMap .Rx (func (m map [int ]asserter ) {
310
- aster , found := m [tlsID ]
311
- if found {
312
- curAsserter = aster
313
- } else {
314
- // use pkg lvl asserter if asserter is not set
315
- curAsserter = defAsserter [def ]
316
- }
317
- })
318
- return curAsserter
319
- }
320
-
321
- func SetDefaultX (i defInd ) {
322
- asserterMap .Set (goid (), defAsserter [i ])
323
- }
324
-
325
294
// That asserts that the term is true. If not it panics with the given
326
295
// formatting string. Thanks to inlining, the performance penalty is equal to a
327
296
// single 'if-statement' that is almost nothing.
@@ -886,12 +855,6 @@ func MNotEmpty[M ~map[T]U, T comparable, U any](obj M, a ...any) {
886
855
}
887
856
}
888
857
889
- func doEmptyNamed (not , name string , a []any ) {
890
- not = x .Whom (not == assertionNot , " not " , "" )
891
- defMsg := assertionMsg + ": " + name + " should" + not + "be empty"
892
- current ().reportAssertionFault (1 , defMsg , a )
893
- }
894
-
895
858
func doNamed (not , tname , got string , a []any ) {
896
859
not = x .Whom (not == assertionNot , " not " , "" )
897
860
defMsg := assertionMsg + ": " + tname + " should" + not + "be " + got
@@ -922,25 +885,14 @@ func NoError(err error, a ...any) {
922
885
// Note that when [Plain] asserter is used ([SetDefault]), optional arguments
923
886
// are used to override the auto-generated assert violation message.
924
887
func Error (err error , a ... any ) {
925
- if err == nil {
926
- doErrorX (a )
927
- }
928
- }
929
-
930
- func ErrorX (err error , a ... any ) {
931
888
if err == nil {
932
889
doError (a )
933
890
}
934
891
}
935
892
936
- func doErrorX (a []any ) {
937
- defMsg := "Error:" + assertionMsg + ": missing error"
938
- currentX ().reportAssertionFault (0 , defMsg , a )
939
- }
940
-
941
893
func doError (a []any ) {
942
894
defMsg := "Error:" + assertionMsg + ": missing error"
943
- current ().reportAssertionFault (0 , defMsg , a )
895
+ current ().reportAssertionFault (1 , defMsg , a )
944
896
}
945
897
946
898
// Greater asserts that the value is greater than want. If it is not it panics
@@ -1011,12 +963,14 @@ func doNotZero[T Number](val T, a []any) {
1011
963
current ().reportAssertionFault (1 , defMsg , a )
1012
964
}
1013
965
1014
- // current returns a current default asserter used for package-level
1015
- // functions like assert.That().
966
+ // current returns a current default asserter used for assert functions like
967
+ // assert.That() in this gorounine .
1016
968
//
1017
- // Note, this indexing stuff is done because of race detection to work on client
969
+ // NOTE this indexing stuff is done because of race detection to work on client
1018
970
// packages. And, yes, we have tested it. This is fastest way to make it without
1019
971
// locks HERE. Only the setting the index is secured with the mutex.
972
+ //
973
+ // NOTE that since our TLS [asserterMap] we still continue to use indexing.
1020
974
func current () (curAsserter asserter ) {
1021
975
// we need thread local storage, maybe we'll implement that to x.package?
1022
976
// study `tester` and copy ideas from it.
@@ -1068,14 +1022,20 @@ func SetDefault(i defInd) (old defInd) {
1068
1022
return
1069
1023
}
1070
1024
1071
- // SetTLS set asserter index for the current thread (Tread Local Storage). That
1072
- // allows us to have multiple different asserter in use in the same app running.
1073
- // Let's say that in some function and its sub-functions want to return plain
1074
- // error messages instead of the panic asserts, they can use following:
1025
+ // SetAsserter set asserter index for the current thread (Tread Local
1026
+ // Storage). That allows us to have multiple different asserter in use in the
1027
+ // same app running. Let's say that in some function and its sub-functions want
1028
+ // to return plain error messages instead of the panic asserts, they can use
1029
+ // following:
1075
1030
//
1076
- // assert.SetTLS (assert.Plain)
1077
- func SetTLS (i defInd ) {
1031
+ // assert.SetAsserter (assert.Plain)
1032
+ func SetAsserter (i defInd ) func ( ) {
1078
1033
asserterMap .Set (goid (), defAsserter [i ])
1034
+ return popCurrentAsserter
1035
+ }
1036
+
1037
+ func popCurrentAsserter () {
1038
+ asserterMap .Del (goid ())
1079
1039
}
1080
1040
1081
1041
// mapDefInd runtime asserters, that's why test asserts are removed for now.
0 commit comments