-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangyile
committed
Dec 25, 2024
1 parent
d7658fd
commit d4a49ac
Showing
8 changed files
with
69 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
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
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,19 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func ExpectPanic(t *testing.T, run func()) { | ||
defer func() { | ||
if recoverFrom := recover(); recoverFrom != nil { | ||
t.Logf("expect panic then catch panic [%v] -> [success]", recoverFrom) | ||
return | ||
} | ||
require.Fail(t, "expect panic while not panic -> [failure]") | ||
}() | ||
|
||
run() | ||
} |
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,14 @@ | ||
package tests_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/yyle88/must/internal/tests" | ||
Check failure on line 7 in internal/tests/tests_test.go GitHub Actions / test (1.22.x)
Check failure on line 7 in internal/tests/tests_test.go GitHub Actions / test (1.23.x)
Check failure on line 7 in internal/tests/tests_test.go GitHub Actions / test (1.22.x)
|
||
) | ||
|
||
func TestExpectPanic(t *testing.T) { | ||
tests.ExpectPanic(t, func() { | ||
panic(errors.New("expect-panic")) | ||
}) | ||
} |