-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanic_test.go
More file actions
67 lines (57 loc) · 1.45 KB
/
panic_test.go
File metadata and controls
67 lines (57 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package test_test
import (
"runtime"
"testing"
. "github.com/blugnu/test"
"github.com/blugnu/test/matchers/panics"
"github.com/blugnu/test/opt"
"github.com/blugnu/test/test"
)
func TestNilPanic(t *testing.T) {
With(t)
result := NilPanic()
Expect(result).To(Equal(panics.Expected{R: &runtime.PanicNilError{}}))
}
func TestPanic(t *testing.T) {
With(t)
Run(HelperTests([]HelperScenario{
{Scenario: "with no args",
Act: func() {
result := Panic()
Expect(result).To(Equal(panics.Expected{}))
},
},
{Scenario: "with nil arg",
Act: func() {
result := Panic(nil)
Expect(result).To(Equal(panics.Expected{R: opt.NoPanicExpected(true)}))
},
},
{Scenario: "with non-nil arg",
Act: func() {
result := Panic("some string")
Expect(result).To(Equal(panics.Expected{R: "some string"}))
},
},
{Scenario: "with multiple args",
Act: func() {
result := Panic("one", "two")
Expect(result).To(Equal(panics.Expected{}))
},
Assert: func(result *R) {
result.ExpectInvalid("Panic: expected at most one argument, got 2")
},
},
}...))
}
func ExamplePanic() {
test.Example()
// a stack trace is included by default, but is disabled for this
// example to avoid breaking the example output
defer Expect(Panic("some string")).DidOccur(opt.NoStackTrace())
panic("some other string")
// Output:
// unexpected panic:
// expected : string("some string")
// recovered: string("some other string")
}