]>
Commit | Line | Data |
---|---|---|
15c0b25d AP |
1 | // +build !go1.9 |
2 | ||
3 | package testing | |
4 | ||
5 | import ( | |
6 | "fmt" | |
7 | "log" | |
8 | ) | |
9 | ||
10 | // T is the interface that mimics the standard library *testing.T. | |
11 | // | |
12 | // In unit tests you can just pass a *testing.T struct. At runtime, outside | |
13 | // of tests, you can pass in a RuntimeT struct from this package. | |
14 | type T interface { | |
15 | Error(args ...interface{}) | |
16 | Errorf(format string, args ...interface{}) | |
17 | Fail() | |
18 | FailNow() | |
19 | Failed() bool | |
20 | Fatal(args ...interface{}) | |
21 | Fatalf(format string, args ...interface{}) | |
22 | Log(args ...interface{}) | |
23 | Logf(format string, args ...interface{}) | |
24 | Name() string | |
25 | Skip(args ...interface{}) | |
26 | SkipNow() | |
27 | Skipf(format string, args ...interface{}) | |
28 | Skipped() bool | |
29 | } | |
30 | ||
31 | // RuntimeT implements T and can be instantiated and run at runtime to | |
32 | // mimic *testing.T behavior. Unlike *testing.T, this will simply panic | |
33 | // for calls to Fatal. For calls to Error, you'll have to check the errors | |
34 | // list to determine whether to exit yourself. Name and Skip methods are | |
35 | // unimplemented noops. | |
36 | type RuntimeT struct { | |
37 | failed bool | |
38 | } | |
39 | ||
40 | func (t *RuntimeT) Error(args ...interface{}) { | |
41 | log.Println(fmt.Sprintln(args...)) | |
42 | t.Fail() | |
43 | } | |
44 | ||
45 | func (t *RuntimeT) Errorf(format string, args ...interface{}) { | |
46 | log.Println(fmt.Sprintf(format, args...)) | |
47 | t.Fail() | |
48 | } | |
49 | ||
50 | func (t *RuntimeT) Fatal(args ...interface{}) { | |
51 | log.Println(fmt.Sprintln(args...)) | |
52 | t.FailNow() | |
53 | } | |
54 | ||
55 | func (t *RuntimeT) Fatalf(format string, args ...interface{}) { | |
56 | log.Println(fmt.Sprintf(format, args...)) | |
57 | t.FailNow() | |
58 | } | |
59 | ||
60 | func (t *RuntimeT) Fail() { | |
61 | t.failed = true | |
62 | } | |
63 | ||
64 | func (t *RuntimeT) FailNow() { | |
65 | panic("testing.T failed, see logs for output (if any)") | |
66 | } | |
67 | ||
68 | func (t *RuntimeT) Failed() bool { | |
69 | return t.failed | |
70 | } | |
71 | ||
72 | func (t *RuntimeT) Log(args ...interface{}) { | |
73 | log.Println(fmt.Sprintln(args...)) | |
74 | } | |
75 | ||
76 | func (t *RuntimeT) Logf(format string, args ...interface{}) { | |
77 | log.Println(fmt.Sprintf(format, args...)) | |
78 | } | |
79 | ||
80 | func (t *RuntimeT) Name() string { return "" } | |
81 | func (t *RuntimeT) Skip(args ...interface{}) {} | |
82 | func (t *RuntimeT) SkipNow() {} | |
83 | func (t *RuntimeT) Skipf(format string, args ...interface{}) {} | |
84 | func (t *RuntimeT) Skipped() bool { return false } |