diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-08-18 13:40:30 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-08-18 13:40:30 +0200 |
| commit | 5cc0f9db288ffaf44d104974707338d52530cece (patch) | |
| tree | f0ad530dd072c55c6f46dfea23af993fb31333d4 /assert/panic_test.go | |
| parent | ab5012e0083ff6623ffab78f52f9ea1120d80ffb (diff) | |
| parent | a3ccdd9f491c20771cfda343ebebd4b5d0ea6602 (diff) | |
| download | go-gg-5cc0f9db288ffaf44d104974707338d52530cece.tar.gz | |
Merge branch 'microprom'
Diffstat (limited to 'assert/panic_test.go')
| -rw-r--r-- | assert/panic_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/assert/panic_test.go b/assert/panic_test.go new file mode 100644 index 0000000..a3d6877 --- /dev/null +++ b/assert/panic_test.go @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net> +// SPDX-License-Identifier: Apache-2.0 + +package assert_test + +import ( + "testing" + + "go.xyrillian.de/gg/assert" + "go.xyrillian.de/gg/testcapture" +) + +func TestPanics(t *testing.T) { + //only testing error cases here, coverage of the happy path is provided by + //usage of assert.Panics() in actual tests of other packages + tc := testcapture.Capture(t.Context(), t.Name(), func(t assert.TestingTB) { + assert.Panics(t, func() { + // no panic + }) + }) + assert.Equal(t, tc.Outcome, testcapture.OutcomeFailed) + assert.Equal(t, tc.Messages, []testcapture.Message{ + testcapture.Log("did not panic"), + }) + + tc = testcapture.Capture(t.Context(), t.Name(), func(t assert.TestingTB) { + assert.PanicsWith[string](t, func() { + panic(42) + }) + }) + assert.Equal(t, tc.Outcome, testcapture.OutcomeFailed) + assert.Equal(t, tc.Messages, []testcapture.Message{ + testcapture.Log("panicked with incorrect type: expected string, but got int: 42"), + }) +} |
