Skip to content

Commit

Permalink
Detect tests that panic
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Aug 9, 2024
1 parent 7ea90f1 commit 5994a31
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/compare/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ func matchErrorRegexCheck(msg string) Check {
}
}

const ExpectedPanic = "Expected Error Test Case"

// TestCompareRun ensures that Run command calls the right actions
// and returns the expected error.
func TestCompareRun(t *testing.T) {
Expand Down Expand Up @@ -345,10 +347,13 @@ func TestCompareRun(t *testing.T) {
cmdutil.BehaviorOnFatal(func(str string, code int) {
errorStr := fmt.Sprintf("%s\nerror code:%d\n", testutils.RemoveInconsistentInfo(t, str), code)
test.checks.Err.check(t, test, mode, errorStr)
panic("Expected Error Test Case")
panic(ExpectedPanic)
})
defer func() {
_ = recover()
r := recover()
if s, ok := r.(string); r != nil && (!ok || s != ExpectedPanic) {
t.Fatalf("test paniced: %v", r)
}
test.checks.Out.check(t, test, mode, testutils.RemoveInconsistentInfo(t, out.String()))
}()
cmd.Run(cmd, []string{})
Expand Down

0 comments on commit 5994a31

Please sign in to comment.