@@ -266,7 +266,7 @@ func tester() (t testing.TB) {
266
266
// Note that when [Plain] asserter is used ([SetDefault]), optional arguments
267
267
// are used to override the auto-generated assert violation message.
268
268
func NotImplemented (a ... any ) {
269
- current ().reportAssertionFault ("not implemented" , a )
269
+ current ().reportAssertionFault (0 , "not implemented" , a )
270
270
}
271
271
272
272
// ThatNot asserts that the term is NOT true. If is it panics with the given
@@ -278,7 +278,7 @@ func NotImplemented(a ...any) {
278
278
func ThatNot (term bool , a ... any ) {
279
279
if term {
280
280
defMsg := assertionMsg
281
- current ().reportAssertionFault (defMsg , a )
281
+ current ().reportAssertionFault (0 , defMsg , a )
282
282
}
283
283
}
284
284
@@ -291,7 +291,7 @@ func ThatNot(term bool, a ...any) {
291
291
func That (term bool , a ... any ) {
292
292
if ! term {
293
293
defMsg := assertionMsg
294
- current ().reportAssertionFault (defMsg , a )
294
+ current ().reportAssertionFault (0 , defMsg , a )
295
295
}
296
296
}
297
297
@@ -303,7 +303,7 @@ func That(term bool, a ...any) {
303
303
func NotNil [P ~ * T , T any ](p P , a ... any ) {
304
304
if p == nil {
305
305
defMsg := assertionMsg + ": pointer shouldn't be nil"
306
- current ().reportAssertionFault (defMsg , a )
306
+ current ().reportAssertionFault (0 , defMsg , a )
307
307
}
308
308
}
309
309
@@ -315,7 +315,7 @@ func NotNil[P ~*T, T any](p P, a ...any) {
315
315
func Nil [T any ](p * T , a ... any ) {
316
316
if p != nil {
317
317
defMsg := assertionMsg + ": pointer should be nil"
318
- current ().reportAssertionFault (defMsg , a )
318
+ current ().reportAssertionFault (0 , defMsg , a )
319
319
}
320
320
}
321
321
@@ -333,7 +333,7 @@ func Nil[T any](p *T, a ...any) {
333
333
func INil (i any , a ... any ) {
334
334
if i != nil {
335
335
defMsg := assertionMsg + ": interface should be nil"
336
- current ().reportAssertionFault (defMsg , a )
336
+ current ().reportAssertionFault (0 , defMsg , a )
337
337
}
338
338
}
339
339
@@ -351,7 +351,7 @@ func INil(i any, a ...any) {
351
351
func INotNil (i any , a ... any ) {
352
352
if i == nil {
353
353
defMsg := assertionMsg + ": interface shouldn't be nil"
354
- current ().reportAssertionFault (defMsg , a )
354
+ current ().reportAssertionFault (0 , defMsg , a )
355
355
}
356
356
}
357
357
@@ -363,7 +363,7 @@ func INotNil(i any, a ...any) {
363
363
func SNil [S ~ []T , T any ](s S , a ... any ) {
364
364
if s != nil {
365
365
defMsg := assertionMsg + ": slice should be nil"
366
- current ().reportAssertionFault (defMsg , a )
366
+ current ().reportAssertionFault (0 , defMsg , a )
367
367
}
368
368
}
369
369
@@ -375,7 +375,7 @@ func SNil[S ~[]T, T any](s S, a ...any) {
375
375
func CNil [C ~ chan T , T any ](c C , a ... any ) {
376
376
if c != nil {
377
377
defMsg := assertionMsg + ": channel shouldn't be nil"
378
- current ().reportAssertionFault (defMsg , a )
378
+ current ().reportAssertionFault (0 , defMsg , a )
379
379
}
380
380
}
381
381
@@ -387,7 +387,7 @@ func CNil[C ~chan T, T any](c C, a ...any) {
387
387
func MNil [M ~ map [T ]U , T comparable , U any ](m M , a ... any ) {
388
388
if m != nil {
389
389
defMsg := assertionMsg + ": map should be nil"
390
- current ().reportAssertionFault (defMsg , a )
390
+ current ().reportAssertionFault (0 , defMsg , a )
391
391
}
392
392
}
393
393
@@ -399,7 +399,7 @@ func MNil[M ~map[T]U, T comparable, U any](m M, a ...any) {
399
399
func SNotNil [S ~ []T , T any ](s S , a ... any ) {
400
400
if s == nil {
401
401
defMsg := assertionMsg + ": slice shouldn't be nil"
402
- current ().reportAssertionFault (defMsg , a )
402
+ current ().reportAssertionFault (0 , defMsg , a )
403
403
}
404
404
}
405
405
@@ -411,7 +411,7 @@ func SNotNil[S ~[]T, T any](s S, a ...any) {
411
411
func CNotNil [C ~ chan T , T any ](c C , a ... any ) {
412
412
if c == nil {
413
413
defMsg := assertionMsg + ": channel shouldn't be nil"
414
- current ().reportAssertionFault (defMsg , a )
414
+ current ().reportAssertionFault (0 , defMsg , a )
415
415
}
416
416
}
417
417
@@ -423,7 +423,7 @@ func CNotNil[C ~chan T, T any](c C, a ...any) {
423
423
func MNotNil [M ~ map [T ]U , T comparable , U any ](m M , a ... any ) {
424
424
if m == nil {
425
425
defMsg := assertionMsg + ": map shouldn't be nil"
426
- current ().reportAssertionFault (defMsg , a )
426
+ current ().reportAssertionFault (0 , defMsg , a )
427
427
}
428
428
}
429
429
@@ -456,12 +456,12 @@ func Equal[T comparable](val, want T, a ...any) {
456
456
457
457
func doShouldBeEqual [T comparable ](val , want T , a []any ) {
458
458
defMsg := fmt .Sprintf (assertionMsg + gotWantFmt , val , want )
459
- current ().newReportAssertionFault ( defMsg , a )
459
+ current ().reportAssertionFault ( 1 , defMsg , a )
460
460
}
461
461
462
462
func doShouldNotBeEqual [T comparable ](val , want T , a []any ) {
463
463
defMsg := fmt .Sprintf (assertionMsg + ": got '%v' want (!= '%v')" , val , want )
464
- current ().reportAssertionFault (defMsg , a )
464
+ current ().reportAssertionFault (1 , defMsg , a )
465
465
}
466
466
467
467
// DeepEqual asserts that the (whatever) values are equal. If not it
@@ -474,7 +474,7 @@ func doShouldNotBeEqual[T comparable](val, want T, a []any) {
474
474
func DeepEqual (val , want any , a ... any ) {
475
475
if ! reflect .DeepEqual (val , want ) {
476
476
defMsg := fmt .Sprintf (assertionMsg + gotWantFmt , val , want )
477
- current ().reportAssertionFault (defMsg , a )
477
+ current ().reportAssertionFault (0 , defMsg , a )
478
478
}
479
479
}
480
480
@@ -493,7 +493,7 @@ func DeepEqual(val, want any, a ...any) {
493
493
func NotDeepEqual (val , want any , a ... any ) {
494
494
if reflect .DeepEqual (val , want ) {
495
495
defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want (!= '%v')" , val , want )
496
- current ().reportAssertionFault (defMsg , a )
496
+ current ().reportAssertionFault (0 , defMsg , a )
497
497
}
498
498
}
499
499
@@ -530,7 +530,7 @@ func Longer(s string, length int, a ...any) {
530
530
531
531
if l <= length {
532
532
defMsg := fmt .Sprintf (assertionMsg + gotWantLongerFmt , l , length )
533
- current ().reportAssertionFault (defMsg , a )
533
+ current ().reportAssertionFault (0 , defMsg , a )
534
534
}
535
535
}
536
536
@@ -549,7 +549,7 @@ func Shorter(str string, length int, a ...any) {
549
549
550
550
if l >= length {
551
551
defMsg := fmt .Sprintf (assertionMsg + gotWantShorterFmt , l , length )
552
- current ().reportAssertionFault (defMsg , a )
552
+ current ().reportAssertionFault (0 , defMsg , a )
553
553
}
554
554
}
555
555
@@ -586,7 +586,7 @@ func SLonger[S ~[]T, T any](obj S, length int, a ...any) {
586
586
587
587
if l <= length {
588
588
defMsg := fmt .Sprintf (assertionMsg + gotWantLongerFmt , l , length )
589
- current ().reportAssertionFault (defMsg , a )
589
+ current ().reportAssertionFault (0 , defMsg , a )
590
590
}
591
591
}
592
592
@@ -605,7 +605,7 @@ func SShorter[S ~[]T, T any](obj S, length int, a ...any) {
605
605
606
606
if l >= length {
607
607
defMsg := fmt .Sprintf (assertionMsg + gotWantShorterFmt , l , length )
608
- current ().reportAssertionFault (defMsg , a )
608
+ current ().reportAssertionFault (0 , defMsg , a )
609
609
}
610
610
}
611
611
@@ -642,7 +642,7 @@ func MLonger[M ~map[T]U, T comparable, U any](obj M, length int, a ...any) {
642
642
643
643
if l <= length {
644
644
defMsg := fmt .Sprintf (assertionMsg + gotWantLongerFmt , l , length )
645
- current ().reportAssertionFault (defMsg , a )
645
+ current ().reportAssertionFault (0 , defMsg , a )
646
646
}
647
647
}
648
648
@@ -661,7 +661,7 @@ func MShorter[M ~map[T]U, T comparable, U any](obj M, length int, a ...any) {
661
661
662
662
if l >= length {
663
663
defMsg := fmt .Sprintf (assertionMsg + gotWantShorterFmt , l , length )
664
- current ().reportAssertionFault (defMsg , a )
664
+ current ().reportAssertionFault (0 , defMsg , a )
665
665
}
666
666
}
667
667
@@ -680,7 +680,7 @@ func CLen[C ~chan T, T any](obj C, length int, a ...any) {
680
680
681
681
if l != length {
682
682
defMsg := fmt .Sprintf (assertionMsg + gotWantFmt , l , length )
683
- current ().reportAssertionFault (defMsg , a )
683
+ current ().reportAssertionFault (0 , defMsg , a )
684
684
}
685
685
}
686
686
@@ -699,7 +699,7 @@ func CLonger[C ~chan T, T any](obj C, length int, a ...any) {
699
699
700
700
if l <= length {
701
701
defMsg := fmt .Sprintf (assertionMsg + gotWantLongerFmt , l , length )
702
- current ().reportAssertionFault (defMsg , a )
702
+ current ().reportAssertionFault (0 , defMsg , a )
703
703
}
704
704
}
705
705
@@ -718,7 +718,7 @@ func CShorter[C ~chan T, T any](obj C, length int, a ...any) {
718
718
719
719
if l >= length {
720
720
defMsg := fmt .Sprintf (assertionMsg + gotWantShorterFmt , l , length )
721
- current ().reportAssertionFault (defMsg , a )
721
+ current ().reportAssertionFault (0 , defMsg , a )
722
722
}
723
723
}
724
724
@@ -732,12 +732,16 @@ func MKeyExists[M ~map[T]U, T comparable, U any](obj M, key T, a ...any) (val U)
732
732
val , ok = obj [key ]
733
733
734
734
if ! ok {
735
- defMsg := fmt .Sprintf (assertionMsg + ": key '%v' doesn't exist" , key )
736
- current ().reportAssertionFault (defMsg , a )
735
+ doMKeyExists (key , a )
737
736
}
738
737
return val
739
738
}
740
739
740
+ func doMKeyExists [T comparable ](key T , a []any ) {
741
+ defMsg := fmt .Sprintf (assertionMsg + ": key '%v' doesn't exist" , key )
742
+ current ().reportAssertionFault (1 , defMsg , a )
743
+ }
744
+
741
745
// NotEmpty asserts that the string is not empty. If it is, it panics/errors
742
746
// (according the current Asserter) with the auto-generated message. You can
743
747
// append the generated got-want message by using optional message arguments.
@@ -747,7 +751,7 @@ func MKeyExists[M ~map[T]U, T comparable, U any](obj M, key T, a ...any) (val U)
747
751
func NotEmpty (obj string , a ... any ) {
748
752
if obj == "" {
749
753
defMsg := assertionMsg + ": string shouldn't be empty"
750
- current ().reportAssertionFault (defMsg , a )
754
+ current ().reportAssertionFault (0 , defMsg , a )
751
755
}
752
756
}
753
757
@@ -760,7 +764,7 @@ func NotEmpty(obj string, a ...any) {
760
764
func Empty (obj string , a ... any ) {
761
765
if obj != "" {
762
766
defMsg := assertionMsg + ": string should be empty"
763
- current ().reportAssertionFault (defMsg , a )
767
+ current ().reportAssertionFault (0 , defMsg , a )
764
768
}
765
769
}
766
770
@@ -777,8 +781,7 @@ func SEmpty[S ~[]T, T any](obj S, a ...any) {
777
781
l := len (obj )
778
782
779
783
if l != 0 {
780
- defMsg := assertionMsg + ": slice should be empty"
781
- current ().reportAssertionFault (defMsg , a )
784
+ doEmptyNamed ("" , "slice" , a )
782
785
}
783
786
}
784
787
@@ -795,8 +798,7 @@ func SNotEmpty[S ~[]T, T any](obj S, a ...any) {
795
798
l := len (obj )
796
799
797
800
if l == 0 {
798
- defMsg := assertionMsg + ": slice shouldn't be empty"
799
- current ().reportAssertionFault (defMsg , a )
801
+ doEmptyNamed ("not" , "slice" , a )
800
802
}
801
803
}
802
804
@@ -815,8 +817,7 @@ func MEmpty[M ~map[T]U, T comparable, U any](obj M, a ...any) {
815
817
l := len (obj )
816
818
817
819
if l != 0 {
818
- defMsg := assertionMsg + ": map should be empty"
819
- current ().reportAssertionFault (defMsg , a )
820
+ doEmptyNamed ("" , "map" , a )
820
821
}
821
822
}
822
823
@@ -835,11 +836,16 @@ func MNotEmpty[M ~map[T]U, T comparable, U any](obj M, a ...any) {
835
836
l := len (obj )
836
837
837
838
if l == 0 {
838
- defMsg := assertionMsg + ": map shouldn't be empty"
839
- current ().reportAssertionFault (defMsg , a )
839
+ doEmptyNamed ("not" , "map" , a )
840
840
}
841
841
}
842
842
843
+ func doEmptyNamed (not , name string , a []any ) {
844
+ not = x .Whom (not == "not" , " not " , "" )
845
+ defMsg := assertionMsg + ": " + name + " should" + not + "be empty"
846
+ current ().reportAssertionFault (1 , defMsg , a )
847
+ }
848
+
843
849
// NoError asserts that the error is nil. If is not it panics with the given
844
850
// formatting string. Thanks to inlining, the performance penalty is equal to a
845
851
// single 'if-statement' that is almost nothing.
@@ -853,7 +859,7 @@ func MNotEmpty[M ~map[T]U, T comparable, U any](obj M, a ...any) {
853
859
func NoError (err error , a ... any ) {
854
860
if err != nil {
855
861
defMsg := assertionMsg + conCatErrStr + err .Error ()
856
- current ().reportAssertionFault (defMsg , a )
862
+ current ().reportAssertionFault (0 , defMsg , a )
857
863
}
858
864
}
859
865
@@ -866,7 +872,7 @@ func NoError(err error, a ...any) {
866
872
func Error (err error , a ... any ) {
867
873
if err == nil {
868
874
defMsg := "Error:" + assertionMsg + ": missing error"
869
- current ().reportAssertionFault (defMsg , a )
875
+ current ().reportAssertionFault (0 , defMsg , a )
870
876
}
871
877
}
872
878
@@ -878,11 +884,15 @@ func Error(err error, a ...any) {
878
884
// are used to override the auto-generated assert violation message.
879
885
func Greater [T Number ](val , want T , a ... any ) {
880
886
if val <= want {
881
- defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want <= '%v'" , val , want )
882
- current ().reportAssertionFault (defMsg , a )
887
+ doGreater (val , want , a )
883
888
}
884
889
}
885
890
891
+ func doGreater [T Number ](val , want T , a []any ) {
892
+ defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want <= '%v'" , val , want )
893
+ current ().reportAssertionFault (1 , defMsg , a )
894
+ }
895
+
886
896
// Less asserts that the value is less than want. If it is not it panics and
887
897
// builds a violation message. Thanks to inlining, the performance penalty is
888
898
// equal to a single 'if-statement' that is almost nothing.
@@ -891,11 +901,15 @@ func Greater[T Number](val, want T, a ...any) {
891
901
// are used to override the auto-generated assert violation message.
892
902
func Less [T Number ](val , want T , a ... any ) {
893
903
if val >= want {
894
- defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want >= '%v'" , val , want )
895
- current ().reportAssertionFault (defMsg , a )
904
+ doLess (val , want , a )
896
905
}
897
906
}
898
907
908
+ func doLess [T Number ](val , want T , a []any ) {
909
+ defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want >= '%v'" , val , want )
910
+ current ().reportAssertionFault (1 , defMsg , a )
911
+ }
912
+
899
913
// Zero asserts that the value is 0. If it is not it panics and builds a
900
914
// violation message. Thanks to inlining, the performance penalty is equal to a
901
915
// single 'if-statement' that is almost nothing.
@@ -910,7 +924,7 @@ func Zero[T Number](val T, a ...any) {
910
924
911
925
func doZero [T Number ](val T , a []any ) {
912
926
defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want (== '0')" , val )
913
- current ().newReportAssertionFault ( defMsg , a )
927
+ current ().reportAssertionFault ( 1 , defMsg , a )
914
928
}
915
929
916
930
// NotZero asserts that the value != 0. If it is not it panics and builds a
@@ -927,7 +941,7 @@ func NotZero[T Number](val T, a ...any) {
927
941
928
942
func doNotZero [T Number ](val T , a []any ) {
929
943
defMsg := fmt .Sprintf (assertionMsg + ": got '%v', want (!= 0)" , val )
930
- current ().newReportAssertionFault ( defMsg , a )
944
+ current ().reportAssertionFault ( 1 , defMsg , a )
931
945
}
932
946
933
947
// current returns a current default asserter used for package-level
0 commit comments