-
Notifications
You must be signed in to change notification settings - Fork 274
/
SPTReporter.m
174 lines (133 loc) · 3.85 KB
/
SPTReporter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
#import "SPTReporter.h"
#import "SPTDefaultReporter.h"
@interface SPTReporter ()
+ (SPTReporter *)loadSharedReporter;
@end
@implementation SPTReporter
@synthesize
runStack=_runStack
;
// ===== SHARED REPORTER ===============================================================================================
#pragma mark - Shared Reporter
+ (SPTReporter *)sharedReporter
{
static SPTReporter * sharedReporter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedReporter = [[self loadSharedReporter] retain];
});
return sharedReporter;
}
+ (SPTReporter *)loadSharedReporter
{
return [[[SPTDefaultReporter alloc] init] autorelease];
}
- (id)init
{
self = [super init];
if (self != nil)
{
self.runStack = [NSMutableArray array];
}
return self;
}
- (void)dealloc
{
self.runStack = nil;
[super dealloc];
}
// ===== SenTestObserver ===============================================================================================
#pragma mark - SenTestObserver
#define SPTSharedReporter ([SPTReporter sharedReporter])
+ (void)testSuiteDidStart:(NSNotification *) aNotification
{
[SPTSharedReporter testSuiteDidBegin:aNotification.object];
}
+ (void)testSuiteDidStop:(NSNotification *) aNotification
{
[SPTSharedReporter testSuiteDidEnd:aNotification.object];
}
+ (void)testCaseDidStart:(NSNotification *) aNotification
{
[SPTSharedReporter testCaseDidBegin:aNotification.object];
}
+ (void)testCaseDidStop:(NSNotification *) aNotification
{
[SPTSharedReporter testCaseDidEnd:aNotification.object];
}
+ (void)testCaseDidFail:(NSNotification *) aNotification
{
[SPTSharedReporter testCaseDidFail:aNotification.object];
}
// ===== RUN STACK =====================================================================================================
#pragma mark - Run Stack
- (void)pushRunStack:(SenTestRun *)run
{
[(NSMutableArray *)self.runStack addObject:run];
}
- (void)popRunStack:(SenTestRun *)run
{
NSAssert(run != nil,
@"Attempt to pop nil test run");
NSAssert([self.runStack lastObject] == run,
@"Attempt to pop test run (%@) out of order: %@",
run,
self.runStack);
[(NSMutableArray *)self.runStack removeLastObject];
}
// ===== TEST SUITE ====================================================================================================
#pragma mark - Test Suite
- (void)testSuiteDidBegin:(SenTestSuiteRun *)suiteRun
{
[self pushRunStack:suiteRun];
}
- (void)testSuiteDidEnd:(SenTestSuiteRun *)suiteRun
{
[self popRunStack:suiteRun];
}
// ===== TEST CASES ====================================================================================================
#pragma mark - Test Cases
- (void)testCaseDidBegin:(SenTestCaseRun *)testCaseRun
{
[self pushRunStack:testCaseRun];
}
- (void)testCaseDidEnd:(SenTestCaseRun *)testCaseRun
{
[self popRunStack:testCaseRun];
}
- (void)testCaseDidFail:(SenTestCaseRun *)testCaseRun
{
}
// ===== PRINTING ======================================================================================================
#pragma mark - Printing
- (void)printString:(NSString *)string
{
fprintf(stderr, "%s", [string UTF8String]);
}
- (void)printStringWithFormat:(NSString *)formatString, ...
{
va_list args;
va_start(args, formatString);
NSString * formattedString = [[NSString alloc] initWithFormat:formatString arguments:args];
va_end(args);
[self printString:formattedString];
[formattedString release];
}
- (void)printLine
{
[self printString:@"\n"];
}
- (void)printLine:(NSString *)line
{
[self printStringWithFormat:@"%@\n", line];
}
- (void)printLineWithFormat:(NSString *)formatString, ...
{
va_list args;
va_start(args, formatString);
NSString * formattedString = [[NSString alloc] initWithFormat:formatString arguments:args];
va_end(args);
[self printLine:formattedString];
[formattedString release];
}
@end