Mercurial > projects > orange
annotate orange/test/UnitTester.d @ 33:4fea56a5849f experimental
Now both internal and external pointers work.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 31 Jul 2011 17:56:44 +0200 |
parents | fc315d786f24 |
children | 511d1ef4e299 |
rev | line source |
---|---|
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
1 /** |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
2 * Copyright: Copyright (c) 2010 Jacob Carlborg. All rights reserved. |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
3 * Authors: Jacob Carlborg |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
4 * Version: Initial created: Oct 17, 2010 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
6 */ |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
7 module orange.test.UnitTester; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
8 |
27 | 9 version (Tango) |
10 { | |
11 import tango.io.device.File; | |
12 import tango.io.stream.Lines; | |
13 import tango.util.Convert; | |
14 import tango.sys.Environment; | |
15 } | |
16 | |
17 | |
18 else | |
19 import std.conv; | |
20 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
21 import tango.core.Exception; |
27 | 22 import tango.io.FilePath; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
23 import orange.core._; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
24 import orange.util._; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
25 |
27 | 26 Use!(void delegate (), string) describe (string message) |
27 { | |
28 return UnitTester.instance.describe(message); | |
29 } | |
30 | |
31 Use!(void delegate (), string) it (string message) | |
32 { | |
33 return UnitTester.instance.test(message); | |
34 } | |
35 | |
36 void delegate () before () | |
37 { | |
38 return UnitTester.instance.before; | |
39 } | |
40 | |
41 void delegate () before (void delegate () before) | |
42 { | |
43 return UnitTester.instance.before = before; | |
44 } | |
45 | |
46 void delegate () after () | |
47 { | |
48 return UnitTester.instance.after; | |
49 } | |
50 | |
51 void delegate () after (void delegate () after) | |
52 { | |
53 return UnitTester.instance.after = after; | |
54 } | |
55 | |
56 void run () | |
57 { | |
58 UnitTester.instance.run; | |
59 } | |
60 | |
61 private: | |
62 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
63 class UnitTester |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
64 { |
27 | 65 private: |
66 | |
67 struct DescriptionManager | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
68 { |
27 | 69 Description[] descriptions; |
70 size_t lastIndex = size_t.max; | |
71 | |
72 void opCatAssign (Description description) | |
73 { | |
74 descriptions ~= description; | |
75 lastIndex++; | |
76 } | |
77 | |
78 void opCatAssign (Test test) | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
79 { |
27 | 80 last.tests ~= test; |
81 } | |
82 | |
83 Description opIndex (size_t i) | |
84 { | |
85 return descriptions[i]; | |
86 } | |
87 | |
88 Description last () | |
89 { | |
90 return descriptions[$ - 1]; | |
91 } | |
92 | |
93 Description first () | |
94 { | |
95 return descriptions[0]; | |
96 } | |
97 | |
98 int opApply (int delegate(ref Description) dg) | |
99 { | |
100 int result = 0; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
101 |
27 | 102 foreach (desc ; descriptions) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
103 { |
27 | 104 result = dg(desc); |
105 | |
106 if (result) | |
107 return result; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
108 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
109 |
27 | 110 return result; |
111 } | |
112 | |
113 size_t length () | |
114 { | |
115 return descriptions.length; | |
116 } | |
117 } | |
118 | |
119 class Description | |
120 { | |
121 private | |
122 { | |
123 DescriptionManager descriptions; | |
124 Test[] tests; | |
125 Test[] failures; | |
126 Test[] pending; | |
127 size_t lastIndex = size_t.max; | |
128 string message; | |
129 void delegate () description; | |
130 } | |
131 | |
132 this (string message) | |
133 { | |
134 this.message = message; | |
135 } | |
136 | |
137 void run () | |
138 { | |
139 if (shouldRun) | |
140 description(); | |
141 } | |
142 | |
143 bool shouldRun () | |
144 { | |
145 return description !is null; | |
146 } | |
147 } | |
148 | |
149 struct Test | |
150 { | |
151 void delegate () test; | |
152 string message; | |
153 AssertException exception; | |
154 | |
155 bool failed () | |
156 { | |
157 return !succeeded; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
158 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
159 |
27 | 160 bool succeeded () |
161 { | |
162 if (exception is null) | |
163 return true; | |
164 | |
165 return false; | |
166 } | |
167 | |
168 void run () | |
169 { | |
170 if (!isPending) | |
171 test(); | |
172 } | |
173 | |
174 bool isPending () | |
175 { | |
176 return test is null; | |
177 } | |
178 } | |
179 | |
180 static UnitTester instance_; | |
181 | |
182 DescriptionManager descriptions; | |
183 Description currentDescription; | |
184 | |
185 void delegate () before_; | |
186 void delegate () after_; | |
187 | |
188 size_t numberOfFailures; | |
189 size_t numberOfPending; | |
190 size_t numberOfTests; | |
191 size_t failureId; | |
192 | |
193 string defaultIndentation = " "; | |
194 string indentation; | |
195 | |
196 static UnitTester instance () | |
197 { | |
198 if (instance_) | |
199 return instance_; | |
200 | |
201 return instance_ = new UnitTester; | |
202 } | |
203 | |
204 Use!(void delegate (), string) describe (string message) | |
205 { | |
206 addDescription(message); | |
207 Use!(void delegate (), string) use; | |
208 | |
209 use.args[0] = &internalDescribe; | |
210 use.args[1] = message; | |
211 | |
212 return use; | |
213 } | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
214 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
215 Use!(void delegate (), string) test (string message) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
216 { |
27 | 217 addTest(message); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
218 Use!(void delegate (), string) use; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
219 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
220 use.args[0] = &internalTest; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
221 use.args[1] = message; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
222 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
223 return use; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
224 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
225 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
226 void run () |
27 | 227 { |
228 foreach (description ; descriptions) | |
229 runDescription(description); | |
230 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
231 printResult; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
232 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
233 |
27 | 234 void runDescription (Description description) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
235 { |
27 | 236 restore(currentDescription) in { |
237 currentDescription = description; | |
238 description.run; | |
239 | |
240 foreach (desc ; description.descriptions) | |
241 runDescription(desc); | |
242 | |
243 foreach (ref test ; description.tests) | |
244 { | |
245 if (test.isPending) | |
246 addPendingTest(description, test); | |
247 | |
248 try | |
249 { | |
250 execute in { | |
251 test.run(); | |
252 }; | |
253 } | |
254 | |
255 catch (AssertException e) | |
256 handleFailure(description, test, e); | |
257 } | |
258 }; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
259 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
260 |
27 | 261 void delegate () before () |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
262 { |
27 | 263 return before_; |
264 } | |
265 | |
266 void delegate () before (void delegate () before) | |
267 { | |
268 return before_ = before; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
269 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
270 |
27 | 271 void delegate () after () |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
272 { |
27 | 273 return after_; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
274 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
275 |
27 | 276 void delegate () after (void delegate () after) |
277 { | |
278 return after_ = after; | |
279 } | |
280 | |
281 void addTest (string message) | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
282 { |
27 | 283 numberOfTests++; |
284 currentDescription.tests ~= Test(null, message); | |
285 } | |
286 | |
287 void addDescription (string message) | |
288 { | |
289 if (currentDescription) | |
290 currentDescription.descriptions ~= new Description(message); | |
291 | |
292 else | |
293 descriptions ~= new Description(message); | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
294 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
295 |
27 | 296 void addPendingTest (Description description, ref Test test) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
297 { |
27 | 298 numberOfPending++; |
299 description.pending ~= test; | |
300 } | |
301 | |
302 void handleFailure (Description description, ref Test test, AssertException exception) | |
303 { | |
304 numberOfFailures++; | |
305 test.exception = exception; | |
306 description.failures ~= test; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
307 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
308 |
27 | 309 void internalDescribe (void delegate () dg, string message) |
310 { | |
311 if (currentDescription) | |
312 currentDescription.descriptions.last.description = dg; | |
313 | |
314 else | |
315 descriptions.last.description = dg; | |
316 } | |
317 | |
318 void internalTest (void delegate () dg, string message) | |
319 { | |
320 currentDescription.tests[$ - 1] = Test(dg, message); | |
321 } | |
322 | |
323 void printResult () | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
324 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
325 if (isAllTestsSuccessful) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
326 return printSuccess(); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
327 |
27 | 328 foreach (description ; descriptions) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
329 { |
27 | 330 printDescription(description); |
331 printResultImpl(description.descriptions); | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
332 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
333 |
27 | 334 failureId = 0; |
335 | |
336 printPending; | |
337 printFailures; | |
338 | |
339 print("\n", numberOfTests, " ", "test".pluralize(numberOfTests),", ", numberOfFailures, " ", "failure".pluralize(numberOfFailures)); | |
340 printNumberOfPending; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
341 println(); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
342 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
343 |
27 | 344 void printResultImpl (DescriptionManager descriptions) |
345 { | |
346 restore(indentation) in { | |
347 indentation ~= defaultIndentation; | |
348 | |
349 foreach (description ; descriptions) | |
350 { | |
351 printDescription(description); | |
352 printResultImpl(description.descriptions); | |
353 } | |
354 }; | |
355 } | |
356 | |
357 void printDescription (Description description) | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
358 { |
27 | 359 println(indentation, description.message); |
360 | |
361 restore(indentation) in { | |
362 indentation ~= defaultIndentation; | |
363 | |
364 foreach (i, ref test ; description.tests) | |
365 { | |
366 print(indentation, "- ", test.message); | |
367 | |
368 if (test.isPending) | |
369 print(" (PENDING: Not Yet Implemented)"); | |
370 | |
371 if (test.failed) | |
372 print(" (FAILED - ", ++failureId, ')'); | |
373 | |
374 println(); | |
375 } | |
376 }; | |
377 } | |
378 | |
379 void printPending () | |
380 { | |
381 if (!hasPending) | |
382 return; | |
383 | |
384 println("\nPending:"); | |
385 | |
386 restore(indentation) in { | |
387 indentation ~= defaultIndentation; | |
388 | |
389 foreach (description ; descriptions) | |
390 { | |
391 printPendingDescription(description); | |
392 printPendingImpl(description.descriptions); | |
393 } | |
394 }; | |
395 } | |
396 | |
397 void printPendingImpl (DescriptionManager descriptions) | |
398 { | |
399 foreach (description ; descriptions) | |
400 { | |
401 printPendingDescription(description); | |
402 printPendingImpl(description.descriptions); | |
403 } | |
404 } | |
405 | |
406 void printPendingDescription (Description description) | |
407 { | |
408 foreach (test ; description.pending) | |
409 println(indentation, description.message, " ", test.message, "\n", indentation, indentation, "# Not Yet Implemented"); | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
410 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
411 |
27 | 412 void printFailures () |
413 { | |
414 if (!hasFailures) | |
415 return; | |
416 | |
417 println("\nFailures:"); | |
418 | |
419 restore(indentation) in { | |
420 indentation ~= defaultIndentation; | |
421 | |
422 foreach (description ; descriptions) | |
423 { | |
424 printFailuresDescription(description); | |
425 printFailuresImpl(description.descriptions); | |
426 } | |
427 }; | |
428 } | |
429 | |
430 void printFailuresImpl (DescriptionManager descriptions) | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
431 { |
27 | 432 foreach (description ; descriptions) |
433 { | |
434 printFailuresDescription(description); | |
435 printFailuresImpl(description.descriptions); | |
436 } | |
437 } | |
438 | |
439 void printFailuresDescription (Description description) | |
440 { | |
441 foreach (test ; description.failures) | |
442 { | |
443 auto str = indentation ~ to!(string)(++failureId) ~ ") "; | |
444 auto whitespace = toWhitespace(str.length); | |
445 | |
446 println(str, description.message, " ", test.message); | |
447 println(whitespace, "# ", test.exception.file, ".d:", test.exception.line); | |
448 println(whitespace, "Stack trace:"); | |
449 print(whitespace); | |
450 test.exception.writeOut(&printStackTrace); | |
451 println(); | |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
452 println(readFailedTest(test)); |
27 | 453 } |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
454 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
455 |
27 | 456 void printStackTrace (string str) |
457 { | |
458 return print(str); | |
459 | |
460 /*if (str.find("start") < size_t.max || | |
461 str.find("main") < size_t.max || | |
462 str.find("rt.compiler.") < size_t.max || | |
463 str.find("orange.") || | |
464 str.find(":0") || | |
465 str.find("_d_assert") || | |
466 str.find("onAssertError") || | |
467 str.find("tango.core.Exception.AssertException._ctor ") || | |
468 str.find("object.") || | |
469 str.find("tango.core.tools.")) | |
470 return;*/ | |
471 } | |
472 | |
473 string readFailedTest (ref Test test, int numberOfSurroundingLines = 3) | |
474 { | |
475 auto filename = test.exception.file.dup.replace('.', '/'); | |
476 | |
477 filename ~= ".d"; | |
478 filename = Environment.toAbsolute(filename); | |
479 auto lineNumber = test.exception.line; | |
480 string str; | |
481 auto file = new File(filename); | |
482 | |
483 foreach (i, line ; new Lines!(char)(file)) | |
484 if (i >= (lineNumber - 1) - numberOfSurroundingLines && i <= (lineNumber - 1) + numberOfSurroundingLines) | |
485 str ~= line ~ '\n'; | |
486 | |
487 file.close; | |
488 | |
489 return str; | |
490 } | |
491 | |
492 void printNumberOfPending () | |
493 { | |
494 if (hasPending) | |
495 print(", ", numberOfPending, " pending"); | |
496 } | |
497 | |
498 void printSuccess () | |
499 { | |
500 println("All ", numberOfTests, " test".pluralize(numberOfTests), " passed successfully."); | |
501 } | |
502 | |
503 bool isAllTestsSuccessful () | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
504 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
505 return !hasPending && !hasFailures; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
506 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
507 |
27 | 508 bool hasPending () |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
509 { |
27 | 510 return numberOfPending > 0; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
511 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
512 |
27 | 513 bool hasFailures () |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
514 { |
27 | 515 return numberOfFailures > 0; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
516 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
517 |
27 | 518 Use!(void delegate ()) execute () |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
519 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
520 Use!(void delegate ()) use; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
521 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
522 use.args[0] = &executeImpl; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
523 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
524 return use; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
525 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
526 |
27 | 527 void executeImpl (void delegate () dg) |
528 { | |
529 auto before = this.before; | |
530 auto after = this.after; | |
531 | |
532 if (before) before(); | |
533 if (dg) dg(); | |
534 if (after) after(); | |
535 } | |
536 | |
537 string toWhitespace (size_t value) | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
538 { |
27 | 539 string str; |
540 | |
541 for (size_t i = 0; i < value; i++) | |
542 str ~= ' '; | |
543 | |
544 return str; | |
545 } | |
546 | |
547 string pluralize (string str, int value) | |
548 { | |
549 if (value == 1) | |
550 return str; | |
551 | |
552 return str ~ "s"; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
553 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
554 } |