generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panic_test.go
54 lines (42 loc) · 955 Bytes
/
panic_test.go
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
package marshalkit_test
import (
"errors"
. "github.com/dogmatiq/marshalkit"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("func Recover()", func() {
It("recoveres from marshaling related panics", func() {
var err error
func() {
defer Recover(&err)
panic(PanicSentinel{errors.New("<error>")})
}()
Expect(err).To(MatchError("<error>"))
})
It("does not recover from unrelated panics", func() {
var value any
func() {
defer func() {
value = recover()
}()
func() (err error) {
defer Recover(&err)
panic("<value>") // not a MustPanicSentinel
}()
}()
Expect(value).To(Equal("<value>"))
})
It("does not panic when no panic occurs", func() {
err := func() (err error) {
defer Recover(&err)
return nil
}()
Expect(err).ShouldNot(HaveOccurred())
})
It("panics when passed a nil pointer", func() {
Expect(func() {
Recover(nil)
}).To(Panic())
})
})