@@ -105,6 +105,7 @@ https://golangci-lint.run/usage/linters/#testifylint
105
105
| [ require-error] ( #require-error ) | ✅ | ❌ |
106
106
| [ suite-dont-use-pkg] ( #suite-dont-use-pkg ) | ✅ | ✅ |
107
107
| [ suite-extra-assert-call] ( #suite-extra-assert-call ) | ✅ | ✅ |
108
+ | [ suite-subtest-run] ( #suite-subtest-run ) | ✅ | ❌ |
108
109
| [ suite-thelper] ( #suite-thelper ) | ❌ | ✅ |
109
110
| [ useless-assert] ( #useless-assert ) | ✅ | ❌ |
110
111
@@ -443,8 +444,8 @@ but did not take into account its package, thereby reacting to everything that i
443
444
``` go
444
445
// isPrint records the unformatted-print functions.
445
446
var isPrint = map [string ]bool {
446
- " error" : true ,
447
- " fatal" : true ,
447
+ " error" : true ,
448
+ " fatal" : true ,
448
449
// ...
449
450
}
450
451
```
@@ -456,8 +457,8 @@ in Go 1.10 after a related [issue](https://github.com/golang/go/issues/22936):
456
457
``` go
457
458
// isPrint records the print functions.
458
459
var isPrint = map [string ]bool {
459
- " fmt.Errorf" : true ,
460
- " fmt.Fprint" : true ,
460
+ " fmt.Errorf" : true ,
461
+ " fmt.Fprint" : true ,
461
462
// ...
462
463
}
463
464
```
@@ -672,8 +673,8 @@ Also, to minimize false positives, `require-error` ignores:
672
673
import " github.com/stretchr/testify/assert"
673
674
674
675
func (s *MySuite ) TestSomething () {
675
- ❌ assert.Equal (s.T (), 42 , value)
676
- ✅ s.Equal (42 , value)
676
+ ❌ assert.Equal (s.T (), 42 , value)
677
+ ✅ s.Equal (42 , value)
677
678
}
678
679
```
679
680
@@ -689,24 +690,24 @@ By default, the checker wants you to remove unnecessary `Assert()` calls:
689
690
690
691
``` go
691
692
func (s *MySuite ) TestSomething () {
692
- ❌ s.Assert ().Equal (42 , value)
693
- ✅ s.Equal (42 , value)
693
+ ❌ s.Assert ().Equal (42 , value)
694
+ ✅ s.Equal (42 , value)
694
695
}
695
696
```
696
697
697
698
But sometimes, on the contrary, people want consistency with ` s.Assert() ` and ` s.Require() ` :
698
699
699
700
``` go
700
701
func (s *MySuite ) TestSomething () {
701
- // ...
702
+ // ...
702
703
703
- ❌
704
- s.Require ().NoError (err)
705
- s.Equal (42 , value)
704
+ ❌
705
+ s.Require ().NoError (err)
706
+ s.Equal (42 , value)
706
707
707
- ✅
708
- s.Require ().NoError (err)
709
- s.Assert ().Equal (42 , value)
708
+ ✅
709
+ s.Require ().NoError (err)
710
+ s.Assert ().Equal (42 , value)
710
711
}
711
712
```
712
713
@@ -718,18 +719,49 @@ You can enable such behavior through `--suite-extra-assert-call.mode=require`.
718
719
719
720
---
720
721
722
+ ### suite-subtest-run
723
+
724
+ ``` go
725
+ func (s *MySuite ) TestSomething () {
726
+ ❌
727
+ s.T ().Run (" subtest" , func (t *testing.T ) {
728
+ assert.Equal (t, 42 , result)
729
+ })
730
+
731
+ ✅
732
+ s.Run (" subtest" , func () {
733
+ s.Equal (42 , result)
734
+ })
735
+ }
736
+ ```
737
+
738
+ ** Autofix** : false. <br >
739
+ ** Enabled by default** : true. <br >
740
+ ** Reason** : Protection from undefined behavior.
741
+
742
+ According to ` testify ` [ documentation] ( https://pkg.go.dev/github.com/stretchr/testify/suite#Suite.Run ) , ` s.Run ` should
743
+ be used for running subtests. This call (among other things) initializes the suite with a fresh instance of ` t ` and
744
+ protects tests from undefined behavior (such as data races).
745
+
746
+ Autofix is disabled because in the most cases it requires rewriting the assertions in the subtest and can leads to dead
747
+ code.
748
+
749
+ The checker is especially useful in combination with [ suite-dont-use-pkg] ( #suite-dont-use-pkg ) .
750
+
751
+ ---
752
+
721
753
### suite-thelper
722
754
723
755
``` go
724
756
❌
725
757
func (s *RoomSuite ) assertRoomRound (roundID RoundID ) {
726
- s.Equal (roundID, s.getRoom ().CurrentRound .ID )
758
+ s.Equal (roundID, s.getRoom ().CurrentRound .ID )
727
759
}
728
760
729
761
✅
730
762
func (s *RoomSuite ) assertRoomRound (roundID RoundID ) {
731
- s.T ().Helper ()
732
- s.Equal (roundID, s.getRoom ().CurrentRound .ID )
763
+ s.T ().Helper ()
764
+ s.Equal (roundID, s.getRoom ().CurrentRound .ID )
733
765
}
734
766
```
735
767
0 commit comments