@@ -21,12 +21,12 @@ package checkers
21
21
22
22
// Zero detects situations like
23
23
//
24
- // assert.Equal(t, 0, count)
24
+ // assert.Equal(t, 0, count)
25
25
// assert.Equal(t, nil, userObj)
26
26
//
27
27
// and requires
28
28
//
29
- // assert.Zero(t, count)
29
+ // assert.Zero(t, count)
30
30
// assert.Zero(t, userObj)
31
31
type Zero struct {}
32
32
@@ -41,8 +41,8 @@ The above code is enough to satisfy the `checkers.Checker` interface.
41
41
42
42
The earlier the checker is in [ the registry] ( internal/checkers/checkers_registry.go ) , the more priority it is.
43
43
44
- For example, the ` zero ` checker takes precedence over the ` expected-actual ` or ` empty ` ,
45
- because its check is more "narrow" and when you fix the warning from ` zero ` ,
44
+ For example, the ` zero ` checker takes precedence over the ` expected-actual ` or ` empty ` ,
45
+ because its check is more "narrow" and when you fix the warning from ` zero ` ,
46
46
the rest of the checkers will become irrelevant.
47
47
48
48
``` go
89
89
90
90
### 7) Implement the checker
91
91
92
- ` Zero ` is an example of [ checkers.RegularChecker] ( ./internal/checkers/checker.go ) because it works with "general"
92
+ ` Zero ` is an example of [ checkers.RegularChecker] ( ./internal/checkers/checker.go ) because it works with "general"
93
93
assertion call. For more complex checkers, use the [ checkers.AdvancedChecker] ( ./internal/checkers/checker.go ) interface.
94
94
95
95
If the checker turns out to be too “fat”, then you can omit some obviously rare combinations,
@@ -130,7 +130,6 @@ Describe a new checker in [checkers section](./README.md#checkers).
130
130
- [ float-compare] ( #float-compare )
131
131
- [ http-const] ( #http-const )
132
132
- [ http-sugar] ( #http-sugar )
133
- - [ negative-positive] ( #negative-positive )
134
133
- [ no-fmt-mess] ( #no-fmt-mess )
135
134
- [ require-len] ( #require-len )
136
135
- [ suite-run] ( #suite-run )
@@ -229,7 +228,7 @@ func (s *ServiceIntegrationSuite) TearDownTest() {
229
228
assert.GreaterOrEqual (t, a, 42.42 )
230
229
assert.Less (t, a, 42.42 )
231
230
assert.LessOrEqual (t, a, 42.42 )
232
-
231
+
233
232
assert.True (t, a != 42.42 ) // assert.False(t, a == 42.42)
234
233
assert.True (t, a > 42.42 ) // assert.False(t, a <= 42.42)
235
234
assert.True (t, a >= 42.42 ) // assert.False(t, a < 42.42)
@@ -283,7 +282,7 @@ And similar idea for `assert.InEpsilonSlice` / `assert.InDeltaSlice`.
283
282
``` go
284
283
❌ assert.HTTPStatusCode (t,
285
284
handler, http.MethodGet , " /index" , nil , http.StatusOK )
286
- assert.HTTPStatusCode (t,
285
+ assert.HTTPStatusCode (t,
287
286
handler, http.MethodGet , " /admin" , nil , http.StatusNotFound )
288
287
assert.HTTPStatusCode (t,
289
288
handler, http.MethodGet , " /oauth" , nil , http.StatusFound )
@@ -300,23 +299,6 @@ And similar idea for `assert.InEpsilonSlice` / `assert.InDeltaSlice`.
300
299
301
300
---
302
301
303
- ### negative-positive
304
-
305
- ``` go
306
- ❌ assert.Less (t, val, 0 )
307
- assert.Greater (t, val, 0 )
308
-
309
- ✅ assert.Negative (t, val)
310
- assert.Positive (t, val)
311
- ```
312
-
313
- ** Autofix** : true. <br >
314
- ** Enabled by default** : maybe? <br >
315
- ** Reason** : More appropriate ` testify ` API with clearer failure message. <br >
316
- ** Related issues** : [ #76 ] ( https://github.com/Antonboom/testifylint/issues/76 )
317
-
318
- ---
319
-
320
302
### no-fmt-mess
321
303
322
304
** Autofix** : true. <br >
@@ -330,7 +312,7 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})
330
312
func Equalf(t TestingT, expected interface{}, actual interface {}, msg string , args ...interface {}) bool
331
313
```
332
314
333
- The f-functions [ were added a long time ago] ( https://github.com/stretchr/testify/pull/356 ) to eliminate
315
+ The f-functions [ were added a long time ago] ( https://github.com/stretchr/testify/pull/356 ) to eliminate
334
316
` govet ` [ complain] ( https://go.googlesource.com/tools/+/refs/heads/release-branch.go1.12/go/analysis/passes/printf/printf.go?pli=1#506 ) .
335
317
336
318
This introduces some inconsistency into the test code, and the next strategies are seen for the checker:
@@ -343,7 +325,7 @@ This will make it easier to migrate to [v2](https://github.com/stretchr/testify/
343
325
344
326
But it doesn't look like a "go way" and the ` govet ` won't be happy.
345
327
346
- 2 ) IMHO, a more appropriate option is to disallow the use of ` msgAndArgs ` in non-f assertions. Look at
328
+ 2 ) IMHO, a more appropriate option is to disallow the use of ` msgAndArgs ` in non-f assertions. Look at
347
329
[ the comment] ( https://github.com/stretchr/testify/issues/1089#issuecomment-1695059265 ) .
348
330
349
331
But there will be no non-stylistic benefits from the checker in this case (depends on the view of API in ` v2 ` ).
@@ -357,7 +339,7 @@ assert.Error(t, err, fmt.Sprintf("Profile %s should not be valid", test.profile)
357
339
358
340
### require-len
359
341
360
- The main idea: if code contains array/slice indexing,
342
+ The main idea: if code contains array/slice indexing,
361
343
then before that there must be a length constraint through ` require ` .
362
344
363
345
``` go
@@ -383,7 +365,7 @@ func (s *Suite) TestSomething() {
383
365
// ...
384
366
assert.Equal (t, " gopher" , result)
385
367
})
386
-
368
+
387
369
✅
388
370
s.Run (" subtest1" , func () {
389
371
// ...
0 commit comments