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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
9 version (Tango)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
10 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
11 import tango.io.device.File;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
12 import tango.io.stream.Lines;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
13 import tango.util.Convert;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
14 import tango.sys.Environment;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
15 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
16
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
17
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
18 else
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
19 import std.conv;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
26 Use!(void delegate (), string) describe (string message)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
27 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
28 return UnitTester.instance.describe(message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
29 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
30
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
31 Use!(void delegate (), string) it (string message)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
32 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
33 return UnitTester.instance.test(message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
34 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
35
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
36 void delegate () before ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
37 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
38 return UnitTester.instance.before;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
39 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
40
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
41 void delegate () before (void delegate () before)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
42 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
43 return UnitTester.instance.before = before;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
44 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
45
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
46 void delegate () after ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
47 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
48 return UnitTester.instance.after;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
49 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
50
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
51 void delegate () after (void delegate () after)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
52 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
53 return UnitTester.instance.after = after;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
54 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
55
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
56 void run ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
57 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
58 UnitTester.instance.run;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
59 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
60
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
61 private:
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
65 private:
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
66
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
69 Description[] descriptions;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
70 size_t lastIndex = size_t.max;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
71
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
72 void opCatAssign (Description description)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
73 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
74 descriptions ~= description;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
75 lastIndex++;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
76 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
77
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
80 last.tests ~= test;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
81 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
82
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
83 Description opIndex (size_t i)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
84 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
85 return descriptions[i];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
86 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
87
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
88 Description last ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
89 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
90 return descriptions[$ - 1];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
91 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
92
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
93 Description first ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
94 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
95 return descriptions[0];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
96 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
97
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
98 int opApply (int delegate(ref Description) dg)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
99 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
104 result = dg(desc);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
105
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
106 if (result)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
110 return result;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
111 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
112
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
113 size_t length ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
114 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
115 return descriptions.length;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
116 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
117 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
118
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
119 class Description
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
120 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
121 private
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
122 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
123 DescriptionManager descriptions;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
124 Test[] tests;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
125 Test[] failures;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
126 Test[] pending;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
127 size_t lastIndex = size_t.max;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
128 string message;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
129 void delegate () description;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
130 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
131
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
132 this (string message)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
133 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
134 this.message = message;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
135 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
136
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
137 void run ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
138 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
139 if (shouldRun)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
140 description();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
141 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
142
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
143 bool shouldRun ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
144 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
145 return description !is null;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
146 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
147 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
148
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
149 struct Test
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
150 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
151 void delegate () test;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
152 string message;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
153 AssertException exception;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
154
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
155 bool failed ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
156 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
160 bool succeeded ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
161 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
162 if (exception is null)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
163 return true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
164
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
165 return false;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
166 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
167
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
168 void run ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
169 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
170 if (!isPending)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
171 test();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
172 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
173
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
174 bool isPending ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
175 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
176 return test is null;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
177 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
178 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
179
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
180 static UnitTester instance_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
181
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
182 DescriptionManager descriptions;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
183 Description currentDescription;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
184
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
185 void delegate () before_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
186 void delegate () after_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
187
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
188 size_t numberOfFailures;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
189 size_t numberOfPending;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
190 size_t numberOfTests;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
191 size_t failureId;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
192
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
193 string defaultIndentation = " ";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
194 string indentation;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
195
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
196 static UnitTester instance ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
197 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
198 if (instance_)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
199 return instance_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
200
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
201 return instance_ = new UnitTester;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
202 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
203
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
204 Use!(void delegate (), string) describe (string message)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
205 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
206 addDescription(message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
207 Use!(void delegate (), string) use;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
208
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
209 use.args[0] = &internalDescribe;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
210 use.args[1] = message;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
211
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
212 return use;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
227 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
228 foreach (description ; descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
229 runDescription(description);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
236 restore(currentDescription) in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
237 currentDescription = description;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
238 description.run;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
239
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
240 foreach (desc ; description.descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
241 runDescription(desc);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
242
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
243 foreach (ref test ; description.tests)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
244 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
245 if (test.isPending)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
246 addPendingTest(description, test);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
247
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
248 try
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
249 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
250 execute in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
251 test.run();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
252 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
253 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
254
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
255 catch (AssertException e)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
256 handleFailure(description, test, e);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
257 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
263 return before_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
264 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
265
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
266 void delegate () before (void delegate () before)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
267 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
276 void delegate () after (void delegate () after)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
277 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
278 return after_ = after;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
279 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
280
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
283 numberOfTests++;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
284 currentDescription.tests ~= Test(null, message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
285 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
286
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
287 void addDescription (string message)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
288 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
289 if (currentDescription)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
290 currentDescription.descriptions ~= new Description(message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
291
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
292 else
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
298 numberOfPending++;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
299 description.pending ~= test;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
300 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
301
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
302 void handleFailure (Description description, ref Test test, AssertException exception)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
303 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
304 numberOfFailures++;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
305 test.exception = exception;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
309 void internalDescribe (void delegate () dg, string message)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
310 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
311 if (currentDescription)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
312 currentDescription.descriptions.last.description = dg;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
313
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
314 else
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
315 descriptions.last.description = dg;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
316 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
317
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
318 void internalTest (void delegate () dg, string message)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
319 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
320 currentDescription.tests[$ - 1] = Test(dg, message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
321 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
322
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
330 printDescription(description);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
334 failureId = 0;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
335
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
336 printPending;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
337 printFailures;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
338
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
339 print("\n", numberOfTests, " ", "test".pluralize(numberOfTests),", ", numberOfFailures, " ", "failure".pluralize(numberOfFailures));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
344 void printResultImpl (DescriptionManager descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
345 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
346 restore(indentation) in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
347 indentation ~= defaultIndentation;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
348
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
349 foreach (description ; descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
350 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
351 printDescription(description);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
352 printResultImpl(description.descriptions);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
353 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
354 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
355 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
356
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
359 println(indentation, description.message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
360
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
361 restore(indentation) in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
362 indentation ~= defaultIndentation;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
363
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
364 foreach (i, ref test ; description.tests)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
365 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
366 print(indentation, "- ", test.message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
367
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
368 if (test.isPending)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
369 print(" (PENDING: Not Yet Implemented)");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
370
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
371 if (test.failed)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
372 print(" (FAILED - ", ++failureId, ')');
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
373
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
374 println();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
375 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
376 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
377 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
378
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
379 void printPending ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
380 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
381 if (!hasPending)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
382 return;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
383
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
384 println("\nPending:");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
385
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
386 restore(indentation) in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
387 indentation ~= defaultIndentation;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
388
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
389 foreach (description ; descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
390 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
391 printPendingDescription(description);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
392 printPendingImpl(description.descriptions);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
393 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
394 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
395 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
396
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
397 void printPendingImpl (DescriptionManager descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
398 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
399 foreach (description ; descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
400 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
401 printPendingDescription(description);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
402 printPendingImpl(description.descriptions);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
403 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
404 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
405
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
406 void printPendingDescription (Description description)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
407 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
408 foreach (test ; description.pending)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
412 void printFailures ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
413 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
414 if (!hasFailures)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
415 return;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
416
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
417 println("\nFailures:");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
418
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
419 restore(indentation) in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
420 indentation ~= defaultIndentation;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
421
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
422 foreach (description ; descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
423 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
424 printFailuresDescription(description);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
425 printFailuresImpl(description.descriptions);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
426 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
427 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
428 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
429
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
432 foreach (description ; descriptions)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
433 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
434 printFailuresDescription(description);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
435 printFailuresImpl(description.descriptions);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
436 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
437 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
438
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
439 void printFailuresDescription (Description description)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
440 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
441 foreach (test ; description.failures)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
442 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
443 auto str = indentation ~ to!(string)(++failureId) ~ ") ";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
444 auto whitespace = toWhitespace(str.length);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
445
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
446 println(str, description.message, " ", test.message);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
447 println(whitespace, "# ", test.exception.file, ".d:", test.exception.line);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
448 println(whitespace, "Stack trace:");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
449 print(whitespace);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
450 test.exception.writeOut(&printStackTrace);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
456 void printStackTrace (string str)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
457 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
458 return print(str);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
459
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
460 /*if (str.find("start") < size_t.max ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
461 str.find("main") < size_t.max ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
462 str.find("rt.compiler.") < size_t.max ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
463 str.find("orange.") ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
464 str.find(":0") ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
465 str.find("_d_assert") ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
466 str.find("onAssertError") ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
467 str.find("tango.core.Exception.AssertException._ctor ") ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
468 str.find("object.") ||
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
469 str.find("tango.core.tools."))
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
470 return;*/
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
471 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
472
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
473 string readFailedTest (ref Test test, int numberOfSurroundingLines = 3)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
474 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
475 auto filename = test.exception.file.dup.replace('.', '/');
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
476
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
477 filename ~= ".d";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
478 filename = Environment.toAbsolute(filename);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
479 auto lineNumber = test.exception.line;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
480 string str;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
481 auto file = new File(filename);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
482
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
483 foreach (i, line ; new Lines!(char)(file))
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
484 if (i >= (lineNumber - 1) - numberOfSurroundingLines && i <= (lineNumber - 1) + numberOfSurroundingLines)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
485 str ~= line ~ '\n';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
486
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
487 file.close;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
488
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
489 return str;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
490 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
491
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
492 void printNumberOfPending ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
493 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
494 if (hasPending)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
495 print(", ", numberOfPending, " pending");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
496 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
497
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
498 void printSuccess ()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
499 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
500 println("All ", numberOfTests, " test".pluralize(numberOfTests), " passed successfully.");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
501 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
502
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
527 void executeImpl (void delegate () dg)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
528 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
529 auto before = this.before;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
530 auto after = this.after;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
531
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
532 if (before) before();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
533 if (dg) dg();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
534 if (after) after();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
535 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
536
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
539 string str;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
540
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
541 for (size_t i = 0; i < value; i++)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
542 str ~= ' ';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
543
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
544 return str;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
545 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
546
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
547 string pluralize (string str, int value)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
548 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
549 if (value == 1)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
550 return str;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
551
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents: 26
diff changeset
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 }