@@ -47,7 +47,7 @@ type ErrorAssertionFunc func(TestingT, error, ...interface{}) bool
47
47
48
48
// PanicAssertionFunc is a common function prototype when validating a panic value. Can be useful
49
49
// for table driven tests.
50
- type PanicAssertionFunc func (t TestingT , f PanicTestFunc , msgAndArgs ... interface {}) bool
50
+ type PanicAssertionFunc = func (t TestingT , f PanicTestFunc , msgAndArgs ... interface {}) bool
51
51
52
52
// Comparison is a custom function that returns true on success and false on failure
53
53
type Comparison func () (success bool )
@@ -275,7 +275,7 @@ type labeledContent struct {
275
275
276
276
// labeledOutput returns a string consisting of the provided labeledContent. Each labeled output is appended in the following manner:
277
277
//
278
- // \t{{label}}:{{align_spaces}}\t{{content}}\n
278
+ // \t{{label}}:{{align_spaces}}\t{{content}}\n
279
279
//
280
280
// The initial carriage return is required to undo/erase any padding added by testing.T.Errorf. The "\t{{label}}:" is for the label.
281
281
// If a label is shorter than the longest label provided, padding spaces are added to make all the labels match in length. Once this
@@ -298,7 +298,7 @@ func labeledOutput(content ...labeledContent) string {
298
298
299
299
// Implements asserts that an object is implemented by the specified interface.
300
300
//
301
- // assert.Implements(t, (*MyInterface)(nil), new(MyObject))
301
+ // assert.Implements(t, (*MyInterface)(nil), new(MyObject))
302
302
func Implements (t TestingT , interfaceObject interface {}, object interface {}, msgAndArgs ... interface {}) bool {
303
303
if h , ok := t .(tHelper ); ok {
304
304
h .Helper ()
@@ -330,7 +330,7 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs
330
330
331
331
// Equal asserts that two objects are equal.
332
332
//
333
- // assert.Equal(t, 123, 123)
333
+ // assert.Equal(t, 123, 123)
334
334
//
335
335
// Pointer variable equality is determined based on the equality of the
336
336
// referenced values (as opposed to the memory addresses). Function equality
@@ -371,7 +371,7 @@ func validateEqualArgs(expected, actual interface{}) error {
371
371
372
372
// Same asserts that two pointers reference the same object.
373
373
//
374
- // assert.Same(t, ptr1, ptr2)
374
+ // assert.Same(t, ptr1, ptr2)
375
375
//
376
376
// Both arguments must be pointer variables. Pointer variable sameness is
377
377
// determined based on the equality of both type and value.
@@ -391,7 +391,7 @@ func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b
391
391
392
392
// NotSame asserts that two pointers do not reference the same object.
393
393
//
394
- // assert.NotSame(t, ptr1, ptr2)
394
+ // assert.NotSame(t, ptr1, ptr2)
395
395
//
396
396
// Both arguments must be pointer variables. Pointer variable sameness is
397
397
// determined based on the equality of both type and value.
@@ -459,7 +459,7 @@ func truncatingFormat(data interface{}) string {
459
459
// EqualValues asserts that two objects are equal or convertable to the same types
460
460
// and equal.
461
461
//
462
- // assert.EqualValues(t, uint32(123), int32(123))
462
+ // assert.EqualValues(t, uint32(123), int32(123))
463
463
func EqualValues (t TestingT , expected , actual interface {}, msgAndArgs ... interface {}) bool {
464
464
if h , ok := t .(tHelper ); ok {
465
465
h .Helper ()
@@ -479,7 +479,7 @@ func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interfa
479
479
480
480
// Exactly asserts that two objects are equal in value and type.
481
481
//
482
- // assert.Exactly(t, int32(123), int64(123))
482
+ // assert.Exactly(t, int32(123), int64(123))
483
483
func Exactly (t TestingT , expected , actual interface {}, msgAndArgs ... interface {}) bool {
484
484
if h , ok := t .(tHelper ); ok {
485
485
h .Helper ()
@@ -498,7 +498,7 @@ func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}
498
498
499
499
// NotNil asserts that the specified object is not nil.
500
500
//
501
- // assert.NotNil(t, err)
501
+ // assert.NotNil(t, err)
502
502
func NotNil (t TestingT , object interface {}, msgAndArgs ... interface {}) bool {
503
503
if ! isNil (object ) {
504
504
return true
@@ -544,7 +544,7 @@ func isNil(object interface{}) bool {
544
544
545
545
// Nil asserts that the specified object is nil.
546
546
//
547
- // assert.Nil(t, err)
547
+ // assert.Nil(t, err)
548
548
func Nil (t TestingT , object interface {}, msgAndArgs ... interface {}) bool {
549
549
if isNil (object ) {
550
550
return true
@@ -587,7 +587,7 @@ func isEmpty(object interface{}) bool {
587
587
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
588
588
// a slice or a channel with len == 0.
589
589
//
590
- // assert.Empty(t, obj)
590
+ // assert.Empty(t, obj)
591
591
func Empty (t TestingT , object interface {}, msgAndArgs ... interface {}) bool {
592
592
pass := isEmpty (object )
593
593
if ! pass {
@@ -604,9 +604,9 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
604
604
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
605
605
// a slice or a channel with len == 0.
606
606
//
607
- // if assert.NotEmpty(t, obj) {
608
- // assert.Equal(t, "two", obj[1])
609
- // }
607
+ // if assert.NotEmpty(t, obj) {
608
+ // assert.Equal(t, "two", obj[1])
609
+ // }
610
610
func NotEmpty (t TestingT , object interface {}, msgAndArgs ... interface {}) bool {
611
611
pass := ! isEmpty (object )
612
612
if ! pass {
@@ -635,7 +635,7 @@ func getLen(x interface{}) (ok bool, length int) {
635
635
// Len asserts that the specified object has specific length.
636
636
// Len also fails if the object has a type that len() not accept.
637
637
//
638
- // assert.Len(t, mySlice, 3)
638
+ // assert.Len(t, mySlice, 3)
639
639
func Len (t TestingT , object interface {}, length int , msgAndArgs ... interface {}) bool {
640
640
if h , ok := t .(tHelper ); ok {
641
641
h .Helper ()
@@ -653,7 +653,7 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{})
653
653
654
654
// True asserts that the specified value is true.
655
655
//
656
- // assert.True(t, myBool)
656
+ // assert.True(t, myBool)
657
657
func True (t TestingT , value bool , msgAndArgs ... interface {}) bool {
658
658
if ! value {
659
659
if h , ok := t .(tHelper ); ok {
@@ -668,7 +668,7 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) bool {
668
668
669
669
// False asserts that the specified value is false.
670
670
//
671
- // assert.False(t, myBool)
671
+ // assert.False(t, myBool)
672
672
func False (t TestingT , value bool , msgAndArgs ... interface {}) bool {
673
673
if value {
674
674
if h , ok := t .(tHelper ); ok {
@@ -683,7 +683,7 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) bool {
683
683
684
684
// NotEqual asserts that the specified values are NOT equal.
685
685
//
686
- // assert.NotEqual(t, obj1, obj2)
686
+ // assert.NotEqual(t, obj1, obj2)
687
687
//
688
688
// Pointer variable equality is determined based on the equality of the
689
689
// referenced values (as opposed to the memory addresses).
@@ -706,7 +706,7 @@ func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{
706
706
707
707
// NotEqualValues asserts that two objects are not equal even when converted to the same type
708
708
//
709
- // assert.NotEqualValues(t, obj1, obj2)
709
+ // assert.NotEqualValues(t, obj1, obj2)
710
710
func NotEqualValues (t TestingT , expected , actual interface {}, msgAndArgs ... interface {}) bool {
711
711
if h , ok := t .(tHelper ); ok {
712
712
h .Helper ()
@@ -765,9 +765,9 @@ func containsElement(list interface{}, element interface{}) (ok, found bool) {
765
765
// Contains asserts that the specified string, list(array, slice...) or map contains the
766
766
// specified substring or element.
767
767
//
768
- // assert.Contains(t, "Hello World", "World")
769
- // assert.Contains(t, ["Hello", "World"], "World")
770
- // assert.Contains(t, {"Hello": "World"}, "Hello")
768
+ // assert.Contains(t, "Hello World", "World")
769
+ // assert.Contains(t, ["Hello", "World"], "World")
770
+ // assert.Contains(t, {"Hello": "World"}, "Hello")
771
771
func Contains (t TestingT , s , contains interface {}, msgAndArgs ... interface {}) bool {
772
772
if h , ok := t .(tHelper ); ok {
773
773
h .Helper ()
@@ -788,9 +788,9 @@ func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bo
788
788
// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
789
789
// specified substring or element.
790
790
//
791
- // assert.NotContains(t, "Hello World", "Earth")
792
- // assert.NotContains(t, ["Hello", "World"], "Earth")
793
- // assert.NotContains(t, {"Hello": "World"}, "Earth")
791
+ // assert.NotContains(t, "Hello World", "Earth")
792
+ // assert.NotContains(t, ["Hello", "World"], "Earth")
793
+ // assert.NotContains(t, {"Hello": "World"}, "Earth")
794
794
func NotContains (t TestingT , s , contains interface {}, msgAndArgs ... interface {}) bool {
795
795
if h , ok := t .(tHelper ); ok {
796
796
h .Helper ()
@@ -811,7 +811,7 @@ func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{})
811
811
// Subset asserts that the specified list(array, slice...) contains all
812
812
// elements given in the specified subset(array, slice...).
813
813
//
814
- // assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
814
+ // assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
815
815
func Subset (t TestingT , list , subset interface {}, msgAndArgs ... interface {}) (ok bool ) {
816
816
if h , ok := t .(tHelper ); ok {
817
817
h .Helper ()
@@ -872,7 +872,7 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
872
872
// NotSubset asserts that the specified list(array, slice...) contains not all
873
873
// elements given in the specified subset(array, slice...).
874
874
//
875
- // assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
875
+ // assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
876
876
func NotSubset (t TestingT , list , subset interface {}, msgAndArgs ... interface {}) (ok bool ) {
877
877
if h , ok := t .(tHelper ); ok {
878
878
h .Helper ()
@@ -1062,7 +1062,7 @@ func didPanic(f PanicTestFunc) (didPanic bool, message interface{}, stack string
1062
1062
1063
1063
// Panics asserts that the code inside the specified PanicTestFunc panics.
1064
1064
//
1065
- // assert.Panics(t, func(){ GoCrazy() })
1065
+ // assert.Panics(t, func(){ GoCrazy() })
1066
1066
func Panics (t TestingT , f PanicTestFunc , msgAndArgs ... interface {}) bool {
1067
1067
if h , ok := t .(tHelper ); ok {
1068
1068
h .Helper ()
@@ -1078,7 +1078,7 @@ func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
1078
1078
// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
1079
1079
// the recovered panic value equals the expected panic value.
1080
1080
//
1081
- // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
1081
+ // assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
1082
1082
func PanicsWithValue (t TestingT , expected interface {}, f PanicTestFunc , msgAndArgs ... interface {}) bool {
1083
1083
if h , ok := t .(tHelper ); ok {
1084
1084
h .Helper ()
@@ -1099,7 +1099,7 @@ func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndAr
1099
1099
// panics, and that the recovered panic value is an error that satisfies the
1100
1100
// EqualError comparison.
1101
1101
//
1102
- // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
1102
+ // assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
1103
1103
func PanicsWithError (t TestingT , errString string , f PanicTestFunc , msgAndArgs ... interface {}) bool {
1104
1104
if h , ok := t .(tHelper ); ok {
1105
1105
h .Helper ()
@@ -1119,7 +1119,7 @@ func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs .
1119
1119
1120
1120
// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
1121
1121
//
1122
- // assert.NotPanics(t, func(){ RemainCalm() })
1122
+ // assert.NotPanics(t, func(){ RemainCalm() })
1123
1123
func NotPanics (t TestingT , f PanicTestFunc , msgAndArgs ... interface {}) bool {
1124
1124
if h , ok := t .(tHelper ); ok {
1125
1125
h .Helper ()
@@ -1134,7 +1134,7 @@ func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
1134
1134
1135
1135
// WithinDuration asserts that the two times are within duration delta of each other.
1136
1136
//
1137
- // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
1137
+ // assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
1138
1138
func WithinDuration (t TestingT , expected , actual time.Time , delta time.Duration , msgAndArgs ... interface {}) bool {
1139
1139
if h , ok := t .(tHelper ); ok {
1140
1140
h .Helper ()
@@ -1150,7 +1150,7 @@ func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration,
1150
1150
1151
1151
// WithinRange asserts that a time is within a time range (inclusive).
1152
1152
//
1153
- // assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
1153
+ // assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
1154
1154
func WithinRange (t TestingT , actual , start , end time.Time , msgAndArgs ... interface {}) bool {
1155
1155
if h , ok := t .(tHelper ); ok {
1156
1156
h .Helper ()
@@ -1209,7 +1209,7 @@ func toFloat(x interface{}) (float64, bool) {
1209
1209
1210
1210
// InDelta asserts that the two numerals are within delta of each other.
1211
1211
//
1212
- // assert.InDelta(t, math.Pi, 22/7.0, 0.01)
1212
+ // assert.InDelta(t, math.Pi, 22/7.0, 0.01)
1213
1213
func InDelta (t TestingT , expected , actual interface {}, delta float64 , msgAndArgs ... interface {}) bool {
1214
1214
if h , ok := t .(tHelper ); ok {
1215
1215
h .Helper ()
@@ -1382,10 +1382,10 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m
1382
1382
1383
1383
// NoError asserts that a function returned no error (i.e. `nil`).
1384
1384
//
1385
- // actualObj, err := SomeFunction()
1386
- // if assert.NoError(t, err) {
1387
- // assert.Equal(t, expectedObj, actualObj)
1388
- // }
1385
+ // actualObj, err := SomeFunction()
1386
+ // if assert.NoError(t, err) {
1387
+ // assert.Equal(t, expectedObj, actualObj)
1388
+ // }
1389
1389
func NoError (t TestingT , err error , msgAndArgs ... interface {}) bool {
1390
1390
if err != nil {
1391
1391
if h , ok := t .(tHelper ); ok {
@@ -1399,10 +1399,10 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
1399
1399
1400
1400
// Error asserts that a function returned an error (i.e. not `nil`).
1401
1401
//
1402
- // actualObj, err := SomeFunction()
1403
- // if assert.Error(t, err) {
1404
- // assert.Equal(t, expectedError, err)
1405
- // }
1402
+ // actualObj, err := SomeFunction()
1403
+ // if assert.Error(t, err) {
1404
+ // assert.Equal(t, expectedError, err)
1405
+ // }
1406
1406
func Error (t TestingT , err error , msgAndArgs ... interface {}) bool {
1407
1407
if err == nil {
1408
1408
if h , ok := t .(tHelper ); ok {
@@ -1417,8 +1417,8 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
1417
1417
// EqualError asserts that a function returned an error (i.e. not `nil`)
1418
1418
// and that it is equal to the provided error.
1419
1419
//
1420
- // actualObj, err := SomeFunction()
1421
- // assert.EqualError(t, err, expectedErrorString)
1420
+ // actualObj, err := SomeFunction()
1421
+ // assert.EqualError(t, err, expectedErrorString)
1422
1422
func EqualError (t TestingT , theError error , errString string , msgAndArgs ... interface {}) bool {
1423
1423
if h , ok := t .(tHelper ); ok {
1424
1424
h .Helper ()
@@ -1440,8 +1440,8 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte
1440
1440
// ErrorContains asserts that a function returned an error (i.e. not `nil`)
1441
1441
// and that the error contains the specified substring.
1442
1442
//
1443
- // actualObj, err := SomeFunction()
1444
- // assert.ErrorContains(t, err, expectedErrorSubString)
1443
+ // actualObj, err := SomeFunction()
1444
+ // assert.ErrorContains(t, err, expectedErrorSubString)
1445
1445
func ErrorContains (t TestingT , theError error , contains string , msgAndArgs ... interface {}) bool {
1446
1446
if h , ok := t .(tHelper ); ok {
1447
1447
h .Helper ()
@@ -1474,8 +1474,8 @@ func matchRegexp(rx interface{}, str interface{}) bool {
1474
1474
1475
1475
// Regexp asserts that a specified regexp matches a string.
1476
1476
//
1477
- // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
1478
- // assert.Regexp(t, "start...$", "it's not starting")
1477
+ // assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
1478
+ // assert.Regexp(t, "start...$", "it's not starting")
1479
1479
func Regexp (t TestingT , rx interface {}, str interface {}, msgAndArgs ... interface {}) bool {
1480
1480
if h , ok := t .(tHelper ); ok {
1481
1481
h .Helper ()
@@ -1492,8 +1492,8 @@ func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface
1492
1492
1493
1493
// NotRegexp asserts that a specified regexp does not match a string.
1494
1494
//
1495
- // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
1496
- // assert.NotRegexp(t, "^start", "it's not starting")
1495
+ // assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
1496
+ // assert.NotRegexp(t, "^start", "it's not starting")
1497
1497
func NotRegexp (t TestingT , rx interface {}, str interface {}, msgAndArgs ... interface {}) bool {
1498
1498
if h , ok := t .(tHelper ); ok {
1499
1499
h .Helper ()
@@ -1605,7 +1605,7 @@ func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) bool {
1605
1605
1606
1606
// JSONEq asserts that two JSON strings are equivalent.
1607
1607
//
1608
- // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
1608
+ // assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
1609
1609
func JSONEq (t TestingT , expected string , actual string , msgAndArgs ... interface {}) bool {
1610
1610
if h , ok := t .(tHelper ); ok {
1611
1611
h .Helper ()
@@ -1728,7 +1728,7 @@ type tHelper interface {
1728
1728
// Eventually asserts that given condition will be met in waitFor time,
1729
1729
// periodically checking target function each tick.
1730
1730
//
1731
- // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
1731
+ // assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
1732
1732
func Eventually (t TestingT , condition func () bool , waitFor time.Duration , tick time.Duration , msgAndArgs ... interface {}) bool {
1733
1733
if h , ok := t .(tHelper ); ok {
1734
1734
h .Helper ()
@@ -1761,7 +1761,7 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t
1761
1761
// Never asserts that the given condition doesn't satisfy in waitFor time,
1762
1762
// periodically checking the target function each tick.
1763
1763
//
1764
- // assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)
1764
+ // assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)
1765
1765
func Never (t TestingT , condition func () bool , waitFor time.Duration , tick time.Duration , msgAndArgs ... interface {}) bool {
1766
1766
if h , ok := t .(tHelper ); ok {
1767
1767
h .Helper ()
0 commit comments