Debian Codegraph @

test_cases/failing.test.go

raw symbols SCIP
1 // Copyright 2011 Aaron Jacobs. All Rights Reserved.
2 // Author: [email protected] (Aaron Jacobs)
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 package oglematchers_test
17
18 import (
19 "fmt"
20 "testing"
21
22 . "github.com/jacobsa/oglematchers"
23 . "github.com/jacobsa/ogletest"
24 )
25
26 func TestFailingTest(t *testing.T) { RunTests(t) }
27
28 ////////////////////////////////////////////////////////////////////////
29 // Usual failures
30 ////////////////////////////////////////////////////////////////////////
31
32 type FailingTest struct {
33 }
34
35 var _ TearDownInterface = &FailingTest{}
36 var _ TearDownTestSuiteInterface = &FailingTest{}
37
38 func init() { RegisterTestSuite(&FailingTest{}) }
39
40 func (t *FailingTest) TearDown() {
41 fmt.Println("TearDown running.")
42 }
43
44 func (t *FailingTest) TearDownTestSuite() {
45 fmt.Println("TearDownTestSuite running.")
46 }
47
48 func (t *FailingTest) PassingMethod() {
49 }
50
51 func (t *FailingTest) Equals() {
52 ExpectThat(17, Equals(17.5))
53 ExpectThat(17, Equals("taco"))
54 }
55
56 func (t *FailingTest) LessThan() {
57 ExpectThat(18, LessThan(17))
58 ExpectThat(18, LessThan("taco"))
59 }
60
61 func (t *FailingTest) HasSubstr() {
62 ExpectThat("taco", HasSubstr("ac"))
63 ExpectThat(17, HasSubstr("ac"))
64 }
65
66 func (t *FailingTest) ExpectWithUserErrorMessages() {
67 ExpectThat(17, Equals(19), "foo bar: %d", 112)
68 ExpectEq(17, 17.5, "foo bar: %d", 112)
69 ExpectLe(17, 16.9, "foo bar: %d", 112)
70 ExpectLt(17, 16.9, "foo bar: %d", 112)
71 ExpectGe(17, 17.1, "foo bar: %d", 112)
72 ExpectGt(17, "taco", "foo bar: %d", 112)
73 ExpectNe(17, 17.0, "foo bar: %d", 112)
74 ExpectFalse(true, "foo bar: %d", 112)
75 ExpectTrue(false, "foo bar: %d", 112)
76 }
77
78 func (t *FailingTest) AssertWithUserErrorMessages() {
79 AssertThat(17, Equals(19), "foo bar: %d", 112)
80 }
81
82 func (t *FailingTest) ExpectationAliases() {
83 ExpectEq(17, 17.5)
84 ExpectEq("taco", 17.5)
85
86 ExpectLe(17, 16.9)
87 ExpectLt(17, 16.9)
88 ExpectLt(17, "taco")
89
90 ExpectGe(17, 17.1)
91 ExpectGt(17, 17.1)
92 ExpectGt(17, "taco")
93
94 ExpectNe(17, 17.0)
95 ExpectNe(17, "taco")
96
97 ExpectFalse(true)
98 ExpectFalse("taco")
99
100 ExpectTrue(false)
101 ExpectTrue("taco")
102 }
103
104 func (t *FailingTest) AssertThatFailure() {
105 AssertThat(17, Equals(19))
106 panic("Shouldn't get here.")
107 }
108
109 func (t *FailingTest) AssertEqFailure() {
110 AssertEq(19, 17)
111 panic("Shouldn't get here.")
112 }
113
114 func (t *FailingTest) AssertNeFailure() {
115 AssertNe(19, 19)
116 panic("Shouldn't get here.")
117 }
118
119 func (t *FailingTest) AssertLeFailure() {
120 AssertLe(19, 17)
121 panic("Shouldn't get here.")
122 }
123
124 func (t *FailingTest) AssertLtFailure() {
125 AssertLt(19, 17)
126 panic("Shouldn't get here.")
127 }
128
129 func (t *FailingTest) AssertGeFailure() {
130 AssertGe(17, 19)
131 panic("Shouldn't get here.")
132 }
133
134 func (t *FailingTest) AssertGtFailure() {
135 AssertGt(17, 19)
136 panic("Shouldn't get here.")
137 }
138
139 func (t *FailingTest) AssertTrueFailure() {
140 AssertTrue("taco")
141 panic("Shouldn't get here.")
142 }
143
144 func (t *FailingTest) AssertFalseFailure() {
145 AssertFalse("taco")
146 panic("Shouldn't get here.")
147 }
148
149 func (t *FailingTest) AddFailureRecord() {
150 r := FailureRecord{
151 FileName: "foo.go",
152 LineNumber: 17,
153 Error: "taco\nburrito",
154 }
155
156 AddFailureRecord(r)
157 }
158
159 func (t *FailingTest) AddFailure() {
160 AddFailure("taco")
161 AddFailure("burrito: %d", 17)
162 }
163
164 func (t *FailingTest) AddFailureThenAbortTest() {
165 AddFailure("enchilada")
166 AbortTest()
167 fmt.Println("Shouldn't get here.")
168 }
169
170 ////////////////////////////////////////////////////////////////////////
171 // Expectation failure during SetUp
172 ////////////////////////////////////////////////////////////////////////
173
174 type ExpectFailDuringSetUpTest struct {
175 }
176
177 func init() { RegisterTestSuite(&ExpectFailDuringSetUpTest{}) }
178
179 func (t *ExpectFailDuringSetUpTest) SetUp(i *TestInfo) {
180 ExpectFalse(true)
181 }
182
183 func (t *ExpectFailDuringSetUpTest) TearDown() {
184 fmt.Println("TearDown running.")
185 }
186
187 func (t *ExpectFailDuringSetUpTest) PassingMethod() {
188 fmt.Println("Method running.")
189 }
190
191 ////////////////////////////////////////////////////////////////////////
192 // Assertion failure during SetUp
193 ////////////////////////////////////////////////////////////////////////
194
195 type AssertFailDuringSetUpTest struct {
196 }
197
198 func init() { RegisterTestSuite(&AssertFailDuringSetUpTest{}) }
199
200 func (t *AssertFailDuringSetUpTest) SetUp(i *TestInfo) {
201 AssertFalse(true)
202 }
203
204 func (t *AssertFailDuringSetUpTest) TearDown() {
205 fmt.Println("TearDown running.")
206 }
207
208 func (t *AssertFailDuringSetUpTest) PassingMethod() {
209 fmt.Println("Method running.")
210 }
211
212 ////////////////////////////////////////////////////////////////////////
213 // Expectation failure during TearDown
214 ////////////////////////////////////////////////////////////////////////
215
216 type ExpectFailDuringTearDownTest struct {
217 }
218
219 func init() { RegisterTestSuite(&ExpectFailDuringTearDownTest{}) }
220
221 func (t *ExpectFailDuringTearDownTest) SetUp(i *TestInfo) {
222 fmt.Println("SetUp running.")
223 }
224
225 func (t *ExpectFailDuringTearDownTest) TearDown() {
226 ExpectFalse(true)
227 }
228
229 func (t *ExpectFailDuringTearDownTest) PassingMethod() {
230 fmt.Println("Method running.")
231 }
232
233 ////////////////////////////////////////////////////////////////////////
234 // Assertion failure during TearDown
235 ////////////////////////////////////////////////////////////////////////
236
237 type AssertFailDuringTearDownTest struct {
238 }
239
240 func init() { RegisterTestSuite(&AssertFailDuringTearDownTest{}) }
241
242 func (t *AssertFailDuringTearDownTest) SetUp(i *TestInfo) {
243 fmt.Println("SetUp running.")
244 }
245
246 func (t *AssertFailDuringTearDownTest) TearDown() {
247 AssertFalse(true)
248 }
249
250 func (t *AssertFailDuringTearDownTest) PassingMethod() {
251 fmt.Println("Method running.")
252 }