/
CDRTeamCityReporter.m
71 lines (60 loc) · 3.14 KB
/
CDRTeamCityReporter.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
//For information on TeamCity messages see: http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity
#import "CDRTeamCityReporter.h"
#import "CDRExample.h"
#import "CDRExampleGroup.h"
@implementation CDRTeamCityReporter
- (NSString *)escapeText:(NSString *)text{
NSString *tmp = text;
tmp = [text stringByReplacingOccurrencesOfString:@"|" withString:@"||"];
tmp = [tmp stringByReplacingOccurrencesOfString:@"'" withString:@"|'"];
tmp = [tmp stringByReplacingOccurrencesOfString:@"\n" withString:@"|n"];
tmp = [tmp stringByReplacingOccurrencesOfString:@"\r" withString:@"|r"];
tmp = [tmp stringByReplacingOccurrencesOfString:@"[" withString:@"|["];
tmp = [tmp stringByReplacingOccurrencesOfString:@"]" withString:@"|]"];
return tmp;
}
- (NSString *)startedMessageForExample:(CDRExample *)example{
return [NSString stringWithFormat:@"##teamcity[testStarted name='%@']", [self escapeText:example.fullText]];
}
- (NSString *)finishedMessageForExample:(CDRExample *)example{
return [NSString stringWithFormat:@"##teamcity[testFinished name='%@']", [self escapeText:example.fullText]];
}
- (NSString *)pendingMessageForExample:(CDRExample *)example{
return [NSString stringWithFormat:@"##teamcity[testIgnored name='%@']", [self escapeText:example.fullText]];
}
- (NSString *)skippedMessageForExample:(CDRExample *)example{
return [NSString stringWithFormat:@"##teamcity[testIgnored name='%@']", [self escapeText:example.fullText]];
}
- (NSString *)failureMessageForExample:(CDRExample *)example{
return [NSString stringWithFormat:@"##teamcity[testFailed name='%@' message='%@']",
[self escapeText:example.fullText],
[self escapeText:example.message]];
}
- (void)reportOnExample:(CDRExample *)example {
switch (example.state) {
case CDRExampleStatePassed:
printf("%s\n%s\n",
[[self startedMessageForExample:example] cStringUsingEncoding:NSUTF8StringEncoding],
[[self finishedMessageForExample:example] cStringUsingEncoding:NSUTF8StringEncoding]);
break;
case CDRExampleStatePending:
printf("%s\n", [[self pendingMessageForExample:example] cStringUsingEncoding:NSUTF8StringEncoding]);
[pendingMessages_ addObject:[super pendingMessageForExample:example]];
break;
case CDRExampleStateSkipped:
printf("%s\n", [[self skippedMessageForExample:example] cStringUsingEncoding:NSUTF8StringEncoding]);
[skippedMessages_ addObject:[super skippedMessageForExample:example]];
break;
case CDRExampleStateError:
case CDRExampleStateFailed:
printf("%s\n%s\n%s\n",
[[self startedMessageForExample:example] cStringUsingEncoding:NSUTF8StringEncoding],
[[self failureMessageForExample:example] cStringUsingEncoding:NSUTF8StringEncoding],
[[self finishedMessageForExample:example] cStringUsingEncoding:NSUTF8StringEncoding]);
[failureMessages_ addObject:[super failureMessageForExample:example]];
break;
default:
break;
}
}
@end