1
1
package testza
2
2
3
3
import (
4
+ "atomicgo.dev/assert"
4
5
"errors"
5
6
"fmt"
6
7
"os"
@@ -68,7 +69,7 @@ func AssertKindOf(t testRunner, expectedKind reflect.Kind, object any, msg ...an
68
69
test .Helper ()
69
70
}
70
71
71
- if ! internal . IsKind ( expectedKind , object ) {
72
+ if ! assert . Kind ( object , expectedKind ) {
72
73
internal .Fail (t ,
73
74
fmt .Sprintf ("A value that !!should be a type of kind %s!! is a type of kind %s." , expectedKind .String (), reflect .TypeOf (object ).Kind ().String ()),
74
75
internal .NewObjectsExpectedActual (expectedKind , object ),
@@ -93,7 +94,7 @@ func AssertNotKindOf(t testRunner, kind reflect.Kind, object any, msg ...any) {
93
94
test .Helper ()
94
95
}
95
96
96
- if internal . IsKind ( kind , object ) {
97
+ if assert . Kind ( object , kind ) {
97
98
internal .Fail (t ,
98
99
fmt .Sprintf ("A value that !!should not be a type of kind %s!! is a type of kind %s." , kind .String (), reflect .TypeOf (object ).Kind ().String ()),
99
100
internal.Objects {
@@ -117,7 +118,7 @@ func AssertNotKindOf(t testRunner, kind reflect.Kind, object any, msg ...any) {
117
118
// testza.AssertNumeric(t, 1.23)
118
119
// testza.AssertNumeric(t, uint(123))
119
120
func AssertNumeric (t testRunner , object any , msg ... any ) {
120
- if ! internal . IsNumber (object ) {
121
+ if ! assert . Number (object ) {
121
122
internal .Fail (t , "An object that !!should be a number!! is not of a numeric type." , internal .NewObjectsSingleUnknown (object ), msg ... )
122
123
}
123
124
}
@@ -133,7 +134,7 @@ func AssertNumeric(t testRunner, object any, msg ...any) {
133
134
// testza.AssertNotNumeric(t, true)
134
135
// testza.AssertNotNumeric(t, "123")
135
136
func AssertNotNumeric (t testRunner , object any , msg ... any ) {
136
- if internal . IsNumber (object ) {
137
+ if assert . Number (object ) {
137
138
internal .Fail (t , "An object that !!should not be a number!! is of a numeric type." , internal .NewObjectsSingleUnknown (object ), msg ... )
138
139
}
139
140
}
@@ -152,7 +153,7 @@ func AssertZero(t testRunner, value any, msg ...any) {
152
153
test .Helper ()
153
154
}
154
155
155
- if ! internal . IsZero (value ) {
156
+ if ! assert . Zero (value ) {
156
157
internal .Fail (t , "An object that !!should have its zero value!!, does not have its zero value." , internal .NewObjectsSingleUnknown (value ), msg ... )
157
158
}
158
159
}
@@ -171,7 +172,7 @@ func AssertNotZero(t testRunner, value any, msg ...any) {
171
172
test .Helper ()
172
173
}
173
174
174
- if internal . IsZero (value ) {
175
+ if assert . Zero (value ) {
175
176
internal .Fail (t , "An object that !!should not have its zero value!!, does have its zero value." , internal .NewObjectsSingleUnknown (value ), msg ... )
176
177
}
177
178
}
@@ -189,7 +190,7 @@ func AssertEqual(t testRunner, expected any, actual any, msg ...any) {
189
190
test .Helper ()
190
191
}
191
192
192
- if ! internal . IsEqual (expected , actual ) {
193
+ if ! assert . Equal (expected , actual ) {
193
194
internal .Fail (t , "Two objects that !!should be equal!!, are not equal." , internal .NewObjectsExpectedActualWithDiff (expected , actual ), msg ... )
194
195
}
195
196
}
@@ -207,7 +208,7 @@ func AssertNotEqual(t testRunner, expected any, actual any, msg ...any) {
207
208
test .Helper ()
208
209
}
209
210
210
- if internal . IsEqual (expected , actual ) {
211
+ if assert . Equal (expected , actual ) {
211
212
objects := internal.Objects {
212
213
{
213
214
Name : "Both Objects" ,
@@ -341,7 +342,7 @@ func AssertImplements(t testRunner, interfaceObject, object any, msg ...any) {
341
342
test .Helper ()
342
343
}
343
344
344
- if ! internal . DoesImplement ( interfaceObject , object ) {
345
+ if ! assert . Implements ( object , interfaceObject ) {
345
346
internal .Fail (t , fmt .Sprintf ("An object that !!should implement %s!! does not implement it." , reflect .TypeOf (interfaceObject ).String ()), internal.Objects {}, msg ... )
346
347
}
347
348
}
@@ -359,7 +360,7 @@ func AssertNotImplements(t testRunner, interfaceObject, object any, msg ...any)
359
360
test .Helper ()
360
361
}
361
362
362
- if internal . DoesImplement ( interfaceObject , object ) {
363
+ if assert . Implements ( object , interfaceObject ) {
363
364
internal .Fail (t , fmt .Sprintf ("An object that !!should not implement %s!! does implement it." , reflect .TypeOf (interfaceObject ).String ()), internal.Objects {}, msg ... )
364
365
}
365
366
}
@@ -378,7 +379,7 @@ func AssertContains(t testRunner, object, element any, msg ...any) {
378
379
test .Helper ()
379
380
}
380
381
381
- if ! internal . DoesContain (object , element ) {
382
+ if ! assert . Contains (object , element ) {
382
383
internal .Fail (t , "An object !!does not contain!! the object it should contain." , internal.Objects {
383
384
internal .NewObjectsSingleNamed ("Missing Object" , element )[0 ],
384
385
internal .NewObjectsSingleNamed ("Full Object" , object )[0 ],
@@ -399,7 +400,7 @@ func AssertNotContains(t testRunner, object, element any, msg ...any) {
399
400
test .Helper ()
400
401
}
401
402
402
- if internal . DoesContain (object , element ) {
403
+ if assert . Contains (object , element ) {
403
404
internal .Fail (t , "An object !!does contain!! an object it should not contain." , internal.Objects {
404
405
internal .NewObjectsSingleUnknown (object )[0 ],
405
406
internal .NewObjectsSingleNamed ("Element that should not be in the object" , element )[0 ],
@@ -422,13 +423,9 @@ func AssertPanics(t testRunner, f func(), msg ...any) {
422
423
test .Helper ()
423
424
}
424
425
425
- defer func () {
426
- if r := recover (); r == nil {
427
- internal .Fail (t , "A function that !!should panic!! did not panic." , internal.Objects {}, msg ... )
428
- }
429
- }()
430
-
431
- f ()
426
+ if ! assert .Panic (f ) {
427
+ internal .Fail (t , "A function that !!should panic!! did not panic." , internal.Objects {}, msg ... )
428
+ }
432
429
}
433
430
434
431
// AssertNotPanics asserts that a function does not panic.
@@ -445,13 +442,9 @@ func AssertNotPanics(t testRunner, f func(), msg ...any) {
445
442
test .Helper ()
446
443
}
447
444
448
- defer func () {
449
- if r := recover (); r != nil {
450
- internal .Fail (t , "A function that !!should not panic!! did panic." , internal.Objects {}, msg ... )
451
- }
452
- }()
453
-
454
- f ()
445
+ if assert .Panic (f ) {
446
+ internal .Fail (t , "A function that !!should not panic!! did panic." , internal.Objects {}, msg ... )
447
+ }
455
448
}
456
449
457
450
// AssertNil asserts that an object is nil.
@@ -466,7 +459,7 @@ func AssertNil(t testRunner, object any, msg ...any) {
466
459
test .Helper ()
467
460
}
468
461
469
- if ! internal . IsNil (object ) {
462
+ if ! assert . Nil (object ) {
470
463
internal .Fail (t , "An object that !!should be nil!! is not nil." , internal .NewObjectsExpectedActual (nil , object ), msg ... )
471
464
}
472
465
}
@@ -485,7 +478,7 @@ func AssertNotNil(t testRunner, object any, msg ...any) {
485
478
test .Helper ()
486
479
}
487
480
488
- if internal . IsNil (object ) {
481
+ if assert . Nil (object ) {
489
482
internal .Fail (t , "An object that !!should not be nil!! is nil." , internal .NewObjectsSingleUnknown (object ), msg ... )
490
483
}
491
484
}
@@ -1067,7 +1060,7 @@ func AssertUnique[elementType comparable](t testRunner, list []elementType, msg
1067
1060
test .Helper ()
1068
1061
}
1069
1062
1070
- if len ( FuzzUtilDistinctSet ( list )) != len (list ) {
1063
+ if ! assert . Unique (list ) {
1071
1064
internal .Fail (t , "The list is !!not unique!!." , internal .NewObjectsSingleNamed ("List" , list ), msg ... )
1072
1065
}
1073
1066
}
@@ -1084,7 +1077,7 @@ func AssertNotUnique[elementType comparable](t testRunner, list []elementType, m
1084
1077
test .Helper ()
1085
1078
}
1086
1079
1087
- if len ( FuzzUtilDistinctSet ( list )) == len (list ) {
1080
+ if assert . Unique (list ) {
1088
1081
internal .Fail (t , "The list !!is unique!!, but should not." , internal .NewObjectsSingleNamed ("List" , list ), msg ... )
1089
1082
}
1090
1083
}
0 commit comments