-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from Antonboom/fixes/require-error-bool-expr
require-error: ignore assertion in bool expr
- Loading branch information
Showing
5 changed files
with
82 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
analyzer/testdata/src/require-error-skip-logic/issue79_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package requireerrorskiplogic | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func assertRegexpError1(regexp any) assert.ErrorAssertionFunc { | ||
return func(t assert.TestingT, got error, msg ...any) bool { | ||
if h, ok := t.(interface{ Helper() }); ok { | ||
h.Helper() | ||
} | ||
return assert.Error(t, got, msg...) && assert.Regexp(t, regexp, got.Error(), msg...) | ||
} | ||
} | ||
|
||
func assertRegexpError2(regexp any) assert.ErrorAssertionFunc { | ||
return func(t assert.TestingT, got error, msg ...any) bool { | ||
if h, ok := t.(interface{ Helper() }); ok { | ||
h.Helper() | ||
} | ||
assert.Error(t, got, msg...) // want "require-error: for error assertions use require" | ||
return assert.Regexp(t, regexp, got.Error(), msg...) | ||
} | ||
} | ||
|
||
func assertRegexpError3(regexp any) assert.ErrorAssertionFunc { | ||
return func(t assert.TestingT, got error, msg ...any) bool { | ||
if h, ok := t.(interface{ Helper() }); ok { | ||
h.Helper() | ||
} | ||
return assert.Error(t, got, msg...) && | ||
(assert.Regexp(t, regexp, got.Error(), msg...) || | ||
assert.ErrorContains(t, got, "failed to")) | ||
} | ||
} | ||
|
||
func requireRegexpError1(regexp any) require.ErrorAssertionFunc { | ||
return func(t require.TestingT, got error, msg ...any) { | ||
if h, ok := t.(interface{ Helper() }); ok { | ||
h.Helper() | ||
} | ||
assert.Error(t, got, msg...) // want "require-error: for error assertions use require" | ||
assert.Regexp(t, regexp, got.Error(), msg...) | ||
} | ||
} | ||
|
||
func requireRegexpError2(regexp any) require.ErrorAssertionFunc { | ||
return func(t require.TestingT, got error, msg ...any) { | ||
if h, ok := t.(interface{ Helper() }); ok { | ||
h.Helper() | ||
} | ||
require.Error(t, got, msg...) | ||
assert.Regexp(t, regexp, got.Error(), msg...) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters