-
Notifications
You must be signed in to change notification settings - Fork 36
/
panic_test.go
63 lines (48 loc) · 3.14 KB
/
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
55
56
57
58
59
60
61
62
63
package assertions
import (
"errors"
"fmt"
)
func (this *AssertionsFixture) TestShouldPanic() {
this.fail(so(func() {}, ShouldPanic, 1), "This assertion requires exactly 0 comparison values (you provided 1).")
this.fail(so(func() {}, ShouldPanic, 1, 2, 3), "This assertion requires exactly 0 comparison values (you provided 3).")
this.fail(so(1, ShouldPanic), shouldUseVoidNiladicFunction)
this.fail(so(func(i int) {}, ShouldPanic), shouldUseVoidNiladicFunction)
this.fail(so(func() int { panic("hi") }, ShouldPanic), shouldUseVoidNiladicFunction)
this.fail(so(func() {}, ShouldPanic), shouldHavePanicked)
this.pass(so(func() { panic("hi") }, ShouldPanic))
}
func (this *AssertionsFixture) TestShouldNotPanic() {
this.fail(so(func() {}, ShouldNotPanic, 1), "This assertion requires exactly 0 comparison values (you provided 1).")
this.fail(so(func() {}, ShouldNotPanic, 1, 2, 3), "This assertion requires exactly 0 comparison values (you provided 3).")
this.fail(so(1, ShouldNotPanic), shouldUseVoidNiladicFunction)
this.fail(so(func(i int) {}, ShouldNotPanic), shouldUseVoidNiladicFunction)
this.fail(so(func() { panic("hi") }, ShouldNotPanic), fmt.Sprintf(shouldNotHavePanicked, "hi"))
this.pass(so(func() {}, ShouldNotPanic))
}
func (this *AssertionsFixture) TestShouldPanicWith() {
this.fail(so(func() {}, ShouldPanicWith), "This assertion requires exactly 1 comparison values (you provided 0).")
this.fail(so(func() {}, ShouldPanicWith, 1, 2, 3), "This assertion requires exactly 1 comparison values (you provided 3).")
this.fail(so(1, ShouldPanicWith, 1), shouldUseVoidNiladicFunction)
this.fail(so(func(i int) {}, ShouldPanicWith, "hi"), shouldUseVoidNiladicFunction)
this.fail(so(func() {}, ShouldPanicWith, "bye"), shouldHavePanicked)
this.fail(so(func() { panic("hi") }, ShouldPanicWith, "bye"), "bye|hi|Expected func() to panic with 'bye' (but it panicked with 'hi')!")
this.fail(so(func() { panic(errInner) }, ShouldPanicWith, errOuter), "outer inner|inner|Expected func() to panic with 'outer inner' (but it panicked with 'inner')!")
this.pass(so(func() { panic("hi") }, ShouldPanicWith, "hi"))
this.pass(so(func() { panic(errOuter) }, ShouldPanicWith, errInner))
}
func (this *AssertionsFixture) TestShouldNotPanicWith() {
this.fail(so(func() {}, ShouldNotPanicWith), "This assertion requires exactly 1 comparison values (you provided 0).")
this.fail(so(func() {}, ShouldNotPanicWith, 1, 2, 3), "This assertion requires exactly 1 comparison values (you provided 3).")
this.fail(so(1, ShouldNotPanicWith, 1), shouldUseVoidNiladicFunction)
this.fail(so(func(i int) {}, ShouldNotPanicWith, "hi"), shouldUseVoidNiladicFunction)
this.fail(so(func() { panic("hi") }, ShouldNotPanicWith, "hi"), "Expected func() NOT to panic with 'hi' (but it did)!")
this.fail(so(func() { panic(errOuter) }, ShouldNotPanicWith, errInner), "Expected func() NOT to panic with 'inner' (but it did)!")
this.pass(so(func() {}, ShouldNotPanicWith, "bye"))
this.pass(so(func() { panic("hi") }, ShouldNotPanicWith, "bye"))
this.pass(so(func() { panic(errInner) }, ShouldNotPanicWith, errOuter))
}
var (
errInner = errors.New("inner")
errOuter = fmt.Errorf("outer %w", errInner)
)