@@ -20,6 +20,8 @@ import (
20
20
"testing"
21
21
)
22
22
23
+ const expectFile = "pkg/log/bug_test.go"
24
+
23
25
func TestWarnOn (t * testing.T ) {
24
26
tw := & testWriter {}
25
27
e := GoogleEmitter {Writer : & Writer {Next : tw }}
@@ -33,104 +35,84 @@ func TestWarnOn(t *testing.T) {
33
35
34
36
testCases := map [string ]func (t * testing.T ){
35
37
"testConditionControlsPrint" : func (t * testing.T ) {
36
- WARN_ON ( false )
38
+ BugTraceback ( nil )
37
39
if len (tw .lines ) > 0 {
38
- t .Errorf ("WARN_ON printed when it shouldn't have" )
40
+ t .Errorf ("BugTraceback printed when it shouldn't have" )
39
41
}
40
42
41
- WARN_ON ( true )
43
+ BugTraceback ( fmt . Errorf ( "error" ) )
42
44
if len (tw .lines ) == 0 {
43
- t .Errorf ("WARN_ON didn't print anything when it should have" )
45
+ t .Errorf ("BugTraceback didn't print anything when it should have" )
44
46
}
45
47
},
46
48
"testStringFormat" : func (t * testing.T ) {
47
- expectFile := "pkg/log/warn_on_test.go"
48
- // Don't try to match the line to make this test less
49
- // brittle to somebody accidentally sneezing on this file.
50
- expectStr := strings .SplitN (warnFmtStr , "%" , 2 )[0 ]
51
-
52
- WARN_ON (true )
53
-
54
- if len (tw .lines ) == 0 {
55
- t .Errorf ("WARN_ON didn't print anything when it should have" )
56
- }
57
- if ! strings .Contains (tw .lines [0 ], expectFile ) {
58
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectFile , tw .lines [0 ])
59
- }
60
- if ! strings .Contains (tw .lines [0 ], expectStr ) {
61
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectStr , tw .lines [0 ])
62
- }
63
- },
64
- "testCustomFormat" : func (t * testing.T ) {
65
- expectFile := "pkg/log/warn_on_test.go"
66
49
expectStr1 := strings .SplitN (warnFmtStr , "%" , 2 )[0 ]
67
50
expectStr2 := "This is just a test warning"
68
- WARN ( true , "This is just a test warning" )
51
+ BugTracebackf ( "This is just a test warning: %s" , "with another string " )
69
52
70
53
if len (tw .lines ) == 0 {
71
- t .Errorf ("WARN_ON didn't print anything when it should have" )
54
+ t .Errorf ("BugTracebackf didn't print anything when it should have" )
72
55
}
73
56
if ! strings .Contains (tw .lines [0 ], expectFile ) {
74
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectFile , tw .lines [0 ])
57
+ t .Errorf ("BugTracebackf didn't contain expected output, expected: '%s', got: '%s'" , expectFile , tw .lines [0 ])
75
58
}
76
59
if ! strings .Contains (tw .lines [0 ], expectStr1 ) {
77
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectStr1 , tw .lines [0 ])
60
+ t .Errorf ("BugTracebackf didn't contain expected output, expected: '%s', got: '%s'" , expectStr1 , tw .lines [0 ])
78
61
}
79
62
if ! strings .Contains (tw .lines [0 ], expectStr2 ) {
80
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectStr2 , tw .lines [0 ])
63
+ t .Errorf ("BugTracebackf didn't contain expected output, expected: '%s', got: '%s'" , expectStr2 , tw .lines [0 ])
81
64
}
82
65
},
83
66
"testWarnErr" : func (t * testing.T ) {
84
- expectFile := "pkg/log/warn_on_test.go"
85
67
expectStr1 := strings .SplitN (warnFmtStr , "%" , 2 )[0 ]
86
68
expectStr2 := "My little error string"
87
69
var err error
88
- WARN_ERR (err )
70
+ BugTraceback (err )
89
71
if len (tw .lines ) > 0 {
90
- t .Errorf ("WARN_ON printed when it shouldn't have" )
72
+ t .Errorf ("BugTraceback printed when it shouldn't have" )
91
73
}
92
74
93
75
err = fmt .Errorf ("My little error string" )
94
- WARN_ERR (err )
76
+ BugTraceback (err )
95
77
if len (tw .lines ) == 0 {
96
- t .Errorf ("WARN_ON didn't print anything when it should have" )
78
+ t .Errorf ("BugTraceback didn't print anything when it should have" )
97
79
}
98
80
if ! strings .Contains (tw .lines [0 ], expectFile ) {
99
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectFile , tw .lines [0 ])
81
+ t .Errorf ("BugTraceback didn't contain expected output, expected: '%s', got: '%s'" , expectFile , tw .lines [0 ])
100
82
}
101
83
if ! strings .Contains (tw .lines [0 ], expectStr1 ) {
102
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectStr1 , tw .lines [0 ])
84
+ t .Errorf ("BugTraceback didn't contain expected output, expected: '%s', got: '%s'" , expectStr1 , tw .lines [0 ])
103
85
}
104
86
if ! strings .Contains (tw .lines [0 ], expectStr2 ) {
105
- t .Errorf ("WARN_ON didn't contain expected output, expected: '%s', got: '%s'" , expectStr2 , tw .lines [0 ])
87
+ t .Errorf ("BugTraceback didn't contain expected output, expected: '%s', got: '%s'" , expectStr2 , tw .lines [0 ])
106
88
}
107
89
},
108
90
"testWarnOnceOnlyPrintsOnce" : func (t * testing.T ) {
109
91
testHelperFunc := func () {
110
- WARN_ON_ONCE ( true )
92
+ BugTracebackfOnce ( "error" )
111
93
}
112
94
113
95
testHelperFunc ()
114
96
if len (tw .lines ) == 0 {
115
- t .Errorf ("WarnOnOnce didn't print anything when it should have" )
97
+ t .Errorf ("BugTracebackfOnce didn't print anything when it should have" )
116
98
}
117
99
tw .clear ()
118
100
119
101
testHelperFunc ()
120
102
if len (tw .lines ) > 0 {
121
- t .Errorf ("WarnOnOnce printed out a warning a second time when it shouldn't have" )
103
+ t .Errorf ("BugTracebackfOnce printed out a warning a second time when it shouldn't have" )
122
104
}
123
105
},
124
106
"testWarnOnceDoesntClobberOthers" : func (t * testing.T ) {
125
- WARN_ON_ONCE ( true )
107
+ BugTracebackfOnce ( "error" )
126
108
if len (tw .lines ) == 0 {
127
- t .Errorf ("First WarnOnOnce didn't print anything when it should have" )
109
+ t .Errorf ("First BugTracebackfOnce didn't print anything when it should have" )
128
110
}
129
111
tw .clear ()
130
112
131
- WARN_ON_ONCE ( true )
113
+ BugTracebackfOnce ( "error" )
132
114
if len (tw .lines ) == 0 {
133
- t .Errorf ("Second WarnOnOnce didn't print anything when it should have" )
115
+ t .Errorf ("Second BugTracebackfOnce didn't print anything when it should have" )
134
116
}
135
117
},
136
118
}
0 commit comments