-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: verify what forbid would let through
- Loading branch information
Showing
3 changed files
with
48 additions
and
2 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
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,39 @@ | ||
package go_test | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPanicLinter(t *testing.T) { | ||
// The follow snippets of code should be allowed through by the go/lint-project.sh script. | ||
r := regexp.MustCompile(`([a-z]+)`) | ||
require.True(t, r.MatchString("abc")) | ||
|
||
var out string | ||
func() { | ||
defer func() { | ||
caught := recover() | ||
if ss, ok := caught.(string); ok { | ||
out = ss | ||
} | ||
}() | ||
require.Equal(t, "", strings.Repeat("Z", -1)) | ||
}() | ||
require.Equal(t, "strings: negative Repeat count", out) | ||
|
||
f := &foo{} | ||
f.panic("whoops") | ||
|
||
// call panic but allow it | ||
require.Panics(t, panic("bad thing")) //nolint:forbidigo | ||
} | ||
|
||
type foo struct{} | ||
|
||
func (*foo) panic(desc string) { | ||
// send PD alert or something | ||
} |