]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/mitchellh/go-testing-interface/testing_go19.go
07fbcb581aa43bea13be5f7831ecca8263455471
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / mitchellh / go-testing-interface / testing_go19.go
1 // +build go1.9
2
3 // NOTE: This is a temporary copy of testing.go for Go 1.9 with the addition
4 // of "Helper" to the T interface. Go 1.9 at the time of typing is in RC
5 // and is set for release shortly. We'll support this on master as the default
6 // as soon as 1.9 is released.
7
8 package testing
9
10 import (
11 "fmt"
12 "log"
13 )
14
15 // T is the interface that mimics the standard library *testing.T.
16 //
17 // In unit tests you can just pass a *testing.T struct. At runtime, outside
18 // of tests, you can pass in a RuntimeT struct from this package.
19 type T interface {
20 Error(args ...interface{})
21 Errorf(format string, args ...interface{})
22 Fatal(args ...interface{})
23 Fatalf(format string, args ...interface{})
24 Fail()
25 FailNow()
26 Failed() bool
27 Helper()
28 Log(args ...interface{})
29 Logf(format string, args ...interface{})
30 }
31
32 // RuntimeT implements T and can be instantiated and run at runtime to
33 // mimic *testing.T behavior. Unlike *testing.T, this will simply panic
34 // for calls to Fatal. For calls to Error, you'll have to check the errors
35 // list to determine whether to exit yourself.
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) Helper() {}
73
74 func (t *RuntimeT) Log(args ...interface{}) {
75 log.Println(fmt.Sprintln(args...))
76 }
77
78 func (t *RuntimeT) Logf(format string, args ...interface{}) {
79 log.Println(fmt.Sprintf(format, args...))
80 }