aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/mitchellh/go-testing-interface/testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mitchellh/go-testing-interface/testing.go')
-rw-r--r--vendor/github.com/mitchellh/go-testing-interface/testing.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/go-testing-interface/testing.go b/vendor/github.com/mitchellh/go-testing-interface/testing.go
new file mode 100644
index 0000000..204afb4
--- /dev/null
+++ b/vendor/github.com/mitchellh/go-testing-interface/testing.go
@@ -0,0 +1,84 @@
1// +build !go1.9
2
3package testing
4
5import (
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.
14type 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.
36type RuntimeT struct {
37 failed bool
38}
39
40func (t *RuntimeT) Error(args ...interface{}) {
41 log.Println(fmt.Sprintln(args...))
42 t.Fail()
43}
44
45func (t *RuntimeT) Errorf(format string, args ...interface{}) {
46 log.Println(fmt.Sprintf(format, args...))
47 t.Fail()
48}
49
50func (t *RuntimeT) Fatal(args ...interface{}) {
51 log.Println(fmt.Sprintln(args...))
52 t.FailNow()
53}
54
55func (t *RuntimeT) Fatalf(format string, args ...interface{}) {
56 log.Println(fmt.Sprintf(format, args...))
57 t.FailNow()
58}
59
60func (t *RuntimeT) Fail() {
61 t.failed = true
62}
63
64func (t *RuntimeT) FailNow() {
65 panic("testing.T failed, see logs for output (if any)")
66}
67
68func (t *RuntimeT) Failed() bool {
69 return t.failed
70}
71
72func (t *RuntimeT) Log(args ...interface{}) {
73 log.Println(fmt.Sprintln(args...))
74}
75
76func (t *RuntimeT) Logf(format string, args ...interface{}) {
77 log.Println(fmt.Sprintf(format, args...))
78}
79
80func (t *RuntimeT) Name() string { return "" }
81func (t *RuntimeT) Skip(args ...interface{}) {}
82func (t *RuntimeT) SkipNow() {}
83func (t *RuntimeT) Skipf(format string, args ...interface{}) {}
84func (t *RuntimeT) Skipped() bool { return false }