Skip to content

Commit 6b7bd9b

Browse files
authored
error-is-as: support NotErrorAs (#219)
* Upgrade testdata to v1.10.0 of testify * self-review fixes * Add new assertions * error-is-as: support NotErrorAs
1 parent d76db50 commit 6b7bd9b

File tree

12 files changed

+487
-14
lines changed

12 files changed

+487
-14
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,13 @@ assert.NoError(t, err, errSentinel)
317317
assert.True(t, errors.Is(err, errSentinel))
318318
assert.False(t, errors.Is(err, errSentinel))
319319
assert.True(t, errors.As(err, &target))
320+
assert.False(t, errors.As(err, &target))
320321

321322
322323
assert.ErrorIs(t, err, errSentinel)
323324
assert.NotErrorIs(t, err, errSentinel)
324325
assert.ErrorAs(t, err, &target)
326+
assert.NotErrorAs(t, err, &target)
325327
```
326328

327329
**Autofix**: partially. <br>

analyzer/testdata/src/checkers-default/error-is-as/error_is_as_test.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analyzer/testdata/src/checkers-default/error-is-as/error_is_as_test.go.golden

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func TestErrorIsAsChecker(t *testing.T) {
3535
assert.NotErrorIsf(t, err, errSentinel, "msg with args %d %s", 42, "42") // want "error-is-as: use assert\\.NotErrorIsf"
3636
assert.ErrorAs(t, err, &target) // want "error-is-as: use assert\\.ErrorAs"
3737
assert.ErrorAsf(t, err, &target, "msg with args %d %s", 42, "42") // want "error-is-as: use assert\\.ErrorAsf"
38+
assert.NotErrorAs(t, err, &target) // want "error-is-as: use assert\\.NotErrorAs"
39+
assert.NotErrorAsf(t, err, &target, "msg with args %d %s", 42, "42") // want "error-is-as: use assert\\.NotErrorAsf"
3840
}
3941

4042
// Valid.
@@ -78,5 +80,13 @@ func TestErrorIsAsChecker(t *testing.T) {
7880
assert.ErrorAsf(t, err, &target, "msg")
7981
assert.ErrorAsf(t, err, &target, "msg with arg %d", 42)
8082
assert.ErrorAsf(t, err, &target, "msg with args %d %s", 42, "42")
83+
84+
assert.NotErrorAs(t, err, &target)
85+
assert.NotErrorAs(t, err, &target, "msg")
86+
assert.NotErrorAs(t, err, &target, "msg with arg %d", 42)
87+
assert.NotErrorAs(t, err, &target, "msg with args %d %s", 42, "42")
88+
assert.NotErrorAsf(t, err, &target, "msg")
89+
assert.NotErrorAsf(t, err, &target, "msg with arg %d", 42)
90+
assert.NotErrorAsf(t, err, &target, "msg with args %d %s", 42, "42")
8191
}
8292
}

analyzer/testdata/src/checkers-default/formatter/formatter_test.go

+90
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analyzer/testdata/src/checkers-default/formatter/formatter_test.go.golden

+90
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,46 @@ func TestFormatterChecker_AllAssertions(t *testing.T) {
180180
assert.FileExistsf(t, "", "msg")
181181
assert.FileExistsf(t, "", "msg with arg", 42) // want "formatter: assert\\.FileExistsf call has arguments but no formatting directives"
182182
assert.FileExistsf(t, "", "msg with arg %d", 42)
183+
assert.Greater(t, nil, nil)
184+
assert.Greater(t, nil, nil, "msg")
185+
assert.Greaterf(t, nil, nil, "msg")
186+
assert.Greaterf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.Greaterf call has arguments but no formatting directives"
187+
assert.Greaterf(t, nil, nil, "msg with arg %d", 42)
188+
assert.GreaterOrEqual(t, nil, nil)
189+
assert.GreaterOrEqual(t, nil, nil, "msg")
190+
assert.GreaterOrEqualf(t, nil, nil, "msg")
191+
assert.GreaterOrEqualf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.GreaterOrEqualf call has arguments but no formatting directives"
192+
assert.GreaterOrEqualf(t, nil, nil, "msg with arg %d", 42)
193+
assert.HTTPBodyContains(t, nil, "", "", nil, "")
194+
assert.HTTPBodyContains(t, nil, "", "", nil, "", "msg")
195+
assert.HTTPBodyContainsf(t, nil, "", "", nil, "", "msg")
196+
assert.HTTPBodyContainsf(t, nil, "", "", nil, "", "msg with arg", 42) // want "formatter: assert\\.HTTPBodyContainsf call has arguments but no formatting directives"
197+
assert.HTTPBodyContainsf(t, nil, "", "", nil, "", "msg with arg %d", 42)
198+
assert.HTTPBodyNotContains(t, nil, "", "", nil, "")
199+
assert.HTTPBodyNotContains(t, nil, "", "", nil, "", "msg")
200+
assert.HTTPBodyNotContainsf(t, nil, "", "", nil, "", "msg")
201+
assert.HTTPBodyNotContainsf(t, nil, "", "", nil, "", "msg with arg", 42) // want "formatter: assert\\.HTTPBodyNotContainsf call has arguments but no formatting directives"
202+
assert.HTTPBodyNotContainsf(t, nil, "", "", nil, "", "msg with arg %d", 42)
203+
assert.HTTPError(t, nil, "", "", nil)
204+
assert.HTTPError(t, nil, "", "", nil, "msg")
205+
assert.HTTPErrorf(t, nil, "", "", nil, "msg")
206+
assert.HTTPErrorf(t, nil, "", "", nil, "msg with arg", 42) // want "formatter: assert\\.HTTPErrorf call has arguments but no formatting directives"
207+
assert.HTTPErrorf(t, nil, "", "", nil, "msg with arg %d", 42)
208+
assert.HTTPRedirect(t, nil, "", "", nil)
209+
assert.HTTPRedirect(t, nil, "", "", nil, "msg")
210+
assert.HTTPRedirectf(t, nil, "", "", nil, "msg")
211+
assert.HTTPRedirectf(t, nil, "", "", nil, "msg with arg", 42) // want "formatter: assert\\.HTTPRedirectf call has arguments but no formatting directives"
212+
assert.HTTPRedirectf(t, nil, "", "", nil, "msg with arg %d", 42)
213+
assert.HTTPStatusCode(t, nil, "", "", nil, 200)
214+
assert.HTTPStatusCode(t, nil, "", "", nil, 200, "msg")
215+
assert.HTTPStatusCodef(t, nil, "", "", nil, 200, "msg")
216+
assert.HTTPStatusCodef(t, nil, "", "", nil, 200, "msg with arg", 42) // want "formatter: assert\\.HTTPStatusCodef call has arguments but no formatting directives"
217+
assert.HTTPStatusCodef(t, nil, "", "", nil, 200, "msg with arg %d", 42)
218+
assert.HTTPSuccess(t, nil, "", "", nil)
219+
assert.HTTPSuccess(t, nil, "", "", nil, "msg")
220+
assert.HTTPSuccessf(t, nil, "", "", nil, "msg")
221+
assert.HTTPSuccessf(t, nil, "", "", nil, "msg with arg", 42) // want "formatter: assert\\.HTTPSuccessf call has arguments but no formatting directives"
222+
assert.HTTPSuccessf(t, nil, "", "", nil, "msg with arg %d", 42)
183223
assert.Implements(t, nil, nil)
184224
assert.Implements(t, nil, nil, "msg")
185225
assert.Implementsf(t, nil, nil, "msg")
@@ -210,6 +250,26 @@ func TestFormatterChecker_AllAssertions(t *testing.T) {
210250
assert.InEpsilonSlicef(t, nil, nil, 0., "msg")
211251
assert.InEpsilonSlicef(t, nil, nil, 0., "msg with arg", 42) // want "formatter: assert\\.InEpsilonSlicef call has arguments but no formatting directives"
212252
assert.InEpsilonSlicef(t, nil, nil, 0., "msg with arg %d", 42)
253+
assert.IsDecreasing(t, nil)
254+
assert.IsDecreasing(t, nil, "msg")
255+
assert.IsDecreasingf(t, nil, "msg")
256+
assert.IsDecreasingf(t, nil, "msg with arg", 42) // want "formatter: assert\\.IsDecreasingf call has arguments but no formatting directives"
257+
assert.IsDecreasingf(t, nil, "msg with arg %d", 42)
258+
assert.IsIncreasing(t, nil)
259+
assert.IsIncreasing(t, nil, "msg")
260+
assert.IsIncreasingf(t, nil, "msg")
261+
assert.IsIncreasingf(t, nil, "msg with arg", 42) // want "formatter: assert\\.IsIncreasingf call has arguments but no formatting directives"
262+
assert.IsIncreasingf(t, nil, "msg with arg %d", 42)
263+
assert.IsNonDecreasing(t, nil)
264+
assert.IsNonDecreasing(t, nil, "msg")
265+
assert.IsNonDecreasingf(t, nil, "msg")
266+
assert.IsNonDecreasingf(t, nil, "msg with arg", 42) // want "formatter: assert\\.IsNonDecreasingf call has arguments but no formatting directives"
267+
assert.IsNonDecreasingf(t, nil, "msg with arg %d", 42)
268+
assert.IsNonIncreasing(t, nil)
269+
assert.IsNonIncreasing(t, nil, "msg")
270+
assert.IsNonIncreasingf(t, nil, "msg")
271+
assert.IsNonIncreasingf(t, nil, "msg with arg", 42) // want "formatter: assert\\.IsNonIncreasingf call has arguments but no formatting directives"
272+
assert.IsNonIncreasingf(t, nil, "msg with arg %d", 42)
213273
assert.IsType(t, nil, nil)
214274
assert.IsType(t, nil, nil, "msg")
215275
assert.IsTypef(t, nil, nil, "msg")
@@ -225,6 +285,21 @@ func TestFormatterChecker_AllAssertions(t *testing.T) {
225285
assert.Lenf(t, nil, 0, "msg")
226286
assert.Lenf(t, nil, 0, "msg with arg", 42) // want "formatter: assert\\.Lenf call has arguments but no formatting directives"
227287
assert.Lenf(t, nil, 0, "msg with arg %d", 42)
288+
assert.Less(t, nil, nil)
289+
assert.Less(t, nil, nil, "msg")
290+
assert.Lessf(t, nil, nil, "msg")
291+
assert.Lessf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.Lessf call has arguments but no formatting directives"
292+
assert.Lessf(t, nil, nil, "msg with arg %d", 42)
293+
assert.LessOrEqual(t, nil, nil)
294+
assert.LessOrEqual(t, nil, nil, "msg")
295+
assert.LessOrEqualf(t, nil, nil, "msg")
296+
assert.LessOrEqualf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.LessOrEqualf call has arguments but no formatting directives"
297+
assert.LessOrEqualf(t, nil, nil, "msg with arg %d", 42)
298+
assert.Negative(t, 0)
299+
assert.Negative(t, 0, "msg")
300+
assert.Negativef(t, 0, "msg")
301+
assert.Negativef(t, 0, "msg with arg", 42) // want "formatter: assert\\.Negativef call has arguments but no formatting directives"
302+
assert.Negativef(t, 0, "msg with arg %d", 42)
228303
assert.Never(t, nil, 0, 0)
229304
assert.Never(t, nil, 0, 0, "msg")
230305
assert.Neverf(t, nil, 0, 0, "msg")
@@ -255,6 +330,11 @@ func TestFormatterChecker_AllAssertions(t *testing.T) {
255330
assert.NotContainsf(t, nil, nil, "msg")
256331
assert.NotContainsf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.NotContainsf call has arguments but no formatting directives"
257332
assert.NotContainsf(t, nil, nil, "msg with arg %d", 42)
333+
assert.NotElementsMatch(t, nil, nil)
334+
assert.NotElementsMatch(t, nil, nil, "msg")
335+
assert.NotElementsMatchf(t, nil, nil, "msg")
336+
assert.NotElementsMatchf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.NotElementsMatchf call has arguments but no formatting directives"
337+
assert.NotElementsMatchf(t, nil, nil, "msg with arg %d", 42)
258338
assert.NotEmpty(t, nil)
259339
assert.NotEmpty(t, nil, "msg")
260340
assert.NotEmptyf(t, nil, "msg")
@@ -270,11 +350,21 @@ func TestFormatterChecker_AllAssertions(t *testing.T) {
270350
assert.NotEqualValuesf(t, nil, nil, "msg")
271351
assert.NotEqualValuesf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.NotEqualValuesf call has arguments but no formatting directives"
272352
assert.NotEqualValuesf(t, nil, nil, "msg with arg %d", 42)
353+
assert.NotErrorAs(t, nil, nil)
354+
assert.NotErrorAs(t, nil, nil, "msg")
355+
assert.NotErrorAsf(t, nil, nil, "msg")
356+
assert.NotErrorAsf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.NotErrorAsf call has arguments but no formatting directives"
357+
assert.NotErrorAsf(t, nil, nil, "msg with arg %d", 42)
273358
assert.NotErrorIs(t, nil, nil)
274359
assert.NotErrorIs(t, nil, nil, "msg")
275360
assert.NotErrorIsf(t, nil, nil, "msg")
276361
assert.NotErrorIsf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.NotErrorIsf call has arguments but no formatting directives"
277362
assert.NotErrorIsf(t, nil, nil, "msg with arg %d", 42)
363+
assert.NotImplements(t, nil, nil)
364+
assert.NotImplements(t, nil, nil, "msg")
365+
assert.NotImplementsf(t, nil, nil, "msg")
366+
assert.NotImplementsf(t, nil, nil, "msg with arg", 42) // want "formatter: assert\\.NotImplementsf call has arguments but no formatting directives"
367+
assert.NotImplementsf(t, nil, nil, "msg with arg %d", 42)
278368
assert.NotNil(t, nil)
279369
assert.NotNil(t, nil, "msg")
280370
assert.NotNilf(t, nil, "msg")

0 commit comments

Comments
 (0)