100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
} @finally {
OFFreeMemory(methods);
}
[tests makeImmutable];
return tests;
}
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
OFSet OF_GENERIC(Class) *testClasses = [self testClasses];
size_t numSucceeded = 0, numFailed = 0;
[OFStdOut writeFormat: @"Running %zu test case(s)\n",
testClasses.count];
for (Class class in testClasses) {
[OFStdOut writeFormat: @"Running tests in %@\n", class];
for (OFValue *test in [self testsInClass: class]) {
void *pool = objc_autoreleasePoolPush();
bool failed = false;
OTTestCase *instance;
[OFStdOut setForegroundColor: [OFColor yellow]];
[OFStdOut writeFormat:
@"-[%@ %s]: ",
class, sel_getName(test.pointerValue)];
instance = [[[class alloc] init] autorelease];
@try {
[instance setUp];
[instance performSelector: test.pointerValue];
} @catch (OTAssertionFailedException *e) {
/*
* If an assertion fails during -[setUp], don't
* run the test.
* If an assertion fails during a test, abort
* the test.
*/
[OFStdOut setForegroundColor: [OFColor red]];
[OFStdOut writeFormat:
@"\r-[%@ %s]: failed\n",
class, sel_getName(test.pointerValue)];
[OFStdOut writeLine: e.description];
failed = true;
}
@try {
[instance tearDown];
} @catch (OTAssertionFailedException *e) {
/*
* If an assertion fails during -[tearDown],
* abort the tear down.
*/
if (!failed) {
[OFStdOut setForegroundColor:
[OFColor red]];
[OFStdOut writeFormat:
@"\r-[%@ %s]: failed\n",
class,
sel_getName(test.pointerValue)];
[OFStdOut writeLine: e.description];
failed = true;
}
}
if (!failed) {
[OFStdOut setForegroundColor: [OFColor green]];
[OFStdOut writeFormat:
@"\r-[%@ %s]: ok\n",
class, sel_getName(test.pointerValue)];
numSucceeded++;
} else
numFailed++;
[OFStdOut reset];
objc_autoreleasePoolPop(pool);
}
}
[OFStdOut writeFormat: @"%zu test(s) succeeded, %zu test(s) failed.\n",
numSucceeded, numFailed];
[OFApplication terminateWithStatus: (int)numFailed];
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
<
<
<
|
>
>
|
<
<
<
<
<
<
|
|
>
>
>
>
<
<
<
|
|
>
>
<
<
>
>
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
} @finally {
OFFreeMemory(methods);
}
[tests makeImmutable];
return tests;
}
- (void)printStatusForTest: (SEL)test
inClass: (Class)class
status: (int)status
description: (OFString *)description
{
switch (status) {
case 0:
[OFStdOut setForegroundColor: [OFColor olive]];
[OFStdOut writeFormat: @"-[%@ ", class];
[OFStdOut setForegroundColor: [OFColor yellow]];
[OFStdOut writeFormat: @"%s", sel_getName(test)];
[OFStdOut setForegroundColor: [OFColor olive]];
[OFStdOut writeString: @"]: "];
break;
case 1:
[OFStdOut setForegroundColor: [OFColor green]];
[OFStdOut writeFormat: @"\r-[%@ ", class];
[OFStdOut setForegroundColor: [OFColor lime]];
[OFStdOut writeFormat: @"%s", sel_getName(test)];
[OFStdOut setForegroundColor: [OFColor green]];
[OFStdOut writeLine: @"]: ok"];
break;
case 2:
[OFStdOut setForegroundColor: [OFColor maroon]];
[OFStdOut writeFormat: @"\r-[%@ ", class];
[OFStdOut setForegroundColor: [OFColor red]];
[OFStdOut writeFormat: @"%s", sel_getName(test)];
[OFStdOut setForegroundColor: [OFColor maroon]];
[OFStdOut writeLine: @"]: failed"];
[OFStdOut writeLine: description];
break;
}
[OFStdOut reset];
}
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
OFSet OF_GENERIC(Class) *testClasses = [self testClasses];
size_t numSucceeded = 0, numFailed = 0;
[OFStdOut writeFormat: @"Running %zu test case(s)\n",
testClasses.count];
for (Class class in testClasses) {
[OFStdOut setForegroundColor: [OFColor teal]];
[OFStdOut writeFormat: @"Running tests in %@\n", class];
[OFStdOut reset];
for (OFValue *test in [self testsInClass: class]) {
void *pool = objc_autoreleasePoolPush();
bool failed = false;
OTTestCase *instance;
[self printStatusForTest: test.pointerValue
inClass: class
status: 0
description: nil];
instance = [[[class alloc] init] autorelease];
@try {
[instance setUp];
[instance performSelector: test.pointerValue];
} @catch (OTAssertionFailedException *e) {
/*
* If an assertion fails during -[setUp], don't
* run the test.
* If an assertion fails during a test, abort
* the test.
*/
[self printStatusForTest: test.pointerValue
inClass: class
status: 2
description: e.description];
failed = true;
}
@try {
[instance tearDown];
} @catch (OTAssertionFailedException *e) {
/*
* If an assertion fails during -[tearDown],
* abort the tear down.
*/
if (!failed) {
SEL selector = test.pointerValue;
OFString *description = e.description;
[self printStatusForTest: selector
inClass: class
status: 2
description: description];
failed = true;
}
}
if (!failed) {
[self printStatusForTest: test.pointerValue
inClass: class
status: 1
description: nil];
numSucceeded++;
} else
numFailed++;
objc_autoreleasePoolPop(pool);
}
}
[OFStdOut setForegroundColor: [OFColor purple]];
[OFStdOut writeFormat: @"%zu test(s) succeeded, %zu test(s) failed.\n",
numSucceeded, numFailed];
[OFStdOut reset];
[OFApplication terminateWithStatus: (int)numFailed];
}
@end
|