| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package oglematchers_test |
| 17 |
|
| 18 |
import ( |
| 19 |
"fmt" |
| 20 |
"log" |
| 21 |
"testing" |
| 22 |
|
| 23 |
. "github.com/jacobsa/oglematchers" |
| 24 |
. "github.com/jacobsa/ogletest" |
| 25 |
) |
| 26 |
|
| 27 |
func TestPanickingTest(t *testing.T) { RunTests(t) } |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
func someFuncThatPanics() { |
| 34 |
panic("Panic in someFuncThatPanics") |
| 35 |
} |
| 36 |
|
| 37 |
type PanickingTest struct { |
| 38 |
} |
| 39 |
|
| 40 |
func init() { RegisterTestSuite(&PanickingTest{}) } |
| 41 |
|
| 42 |
func (t *PanickingTest) TearDown() { |
| 43 |
fmt.Println("TearDown running.") |
| 44 |
} |
| 45 |
|
| 46 |
func (t *PanickingTest) ExplicitPanic() { |
| 47 |
panic("Panic in ExplicitPanic") |
| 48 |
} |
| 49 |
|
| 50 |
func (t *PanickingTest) ExplicitPanicInHelperFunction() { |
| 51 |
someFuncThatPanics() |
| 52 |
} |
| 53 |
|
| 54 |
func (t *PanickingTest) NilPointerDerefence() { |
| 55 |
var p *int |
| 56 |
log.Println(*p) |
| 57 |
} |
| 58 |
|
| 59 |
func (t *PanickingTest) ZzzSomeOtherTest() { |
| 60 |
ExpectThat(17, Equals(17.0)) |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
type SetUpPanicTest struct { |
| 68 |
} |
| 69 |
|
| 70 |
func init() { RegisterTestSuite(&SetUpPanicTest{}) } |
| 71 |
|
| 72 |
func (t *SetUpPanicTest) SetUp(ti *TestInfo) { |
| 73 |
fmt.Println("SetUp about to panic.") |
| 74 |
panic("Panic in SetUp") |
| 75 |
} |
| 76 |
|
| 77 |
func (t *SetUpPanicTest) TearDown() { |
| 78 |
fmt.Println("TearDown running.") |
| 79 |
} |
| 80 |
|
| 81 |
func (t *SetUpPanicTest) SomeTestCase() { |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
type TearDownPanicTest struct { |
| 89 |
} |
| 90 |
|
| 91 |
func init() { RegisterTestSuite(&TearDownPanicTest{}) } |
| 92 |
|
| 93 |
func (t *TearDownPanicTest) TearDown() { |
| 94 |
fmt.Println("TearDown about to panic.") |
| 95 |
panic("Panic in TearDown") |
| 96 |
} |
| 97 |
|
| 98 |
func (t *TearDownPanicTest) SomeTestCase() { |
| 99 |
} |