-
Notifications
You must be signed in to change notification settings - Fork 4
/
exit_test.go
50 lines (40 loc) · 1.04 KB
/
exit_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
package check
import (
"fmt"
"os"
"testing"
)
func ExampleExit() {
Exitf(OK, "Everything is fine - value=%d", 42)
// Output: [OK] - Everything is fine - value=42
// would exit with code 0
}
func ExampleExitf() {
Exitf(OK, "Everything is fine - value=%d", 42)
// Output: [OK] - Everything is fine - value=42
// would exit with code 0
}
func ExampleExitRaw() {
ExitRaw(OK, "Everything is fine")
// Output: [OK] - Everything is fine
// would exit with code 0
}
func ExampleExitError() {
err := fmt.Errorf("connection to %s has been timed out", "localhost:12345")
ExitError(err)
// Output: [UNKNOWN] - connection to localhost:12345 has been timed out (*errors.errorString)
// would exit with code 3
}
func ExampleCatchPanic() {
defer CatchPanic()
panic("something bad happened")
// Output: [UNKNOWN] - Golang encountered a panic: something bad happened
// would exit with code 3
}
func TestMain(m *testing.M) {
// disable actual exit
AllowExit = false
// disable stack trace for the example
PrintStack = false
os.Exit(m.Run())
}