Skip to content

Commit 0fb7454

Browse files
Greg Hainesfpotter
authored andcommitted
Perform all the writes in close
This fixes the bug reported in issue facebookarchive#64.
1 parent 14d28c2 commit 0fb7454

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

xctool/xctool/JUnitReporter.m

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#import "JUnitReporter.h"
22

3+
#pragma mark Constants
4+
#define kJUnitReporter_Suite_Event @"event"
5+
#define kJUnitReporter_Suite_Results @"results"
6+
37
#pragma mark Private Interface
48
@interface JUnitReporter ()
59

@@ -26,6 +30,11 @@ - (id)init
2630
if (self = [super init]) {
2731
_formatter = [[NSDateFormatter alloc] init];
2832
[_formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZ"];
33+
self.testSuites = [NSMutableArray array];
34+
self.totalTests = 0;
35+
self.totalFailures = 0;
36+
self.totalErrors = 0;
37+
self.totalTime = 0.0;
2938
}
3039
return self;
3140
}
@@ -39,15 +48,6 @@ - (void)dealloc
3948
}
4049

4150
#pragma mark Reporter
42-
- (void)beginOcunit:(NSDictionary *)event
43-
{
44-
self.testSuites = [NSMutableArray array];
45-
self.totalTests = 0;
46-
self.totalFailures = 0;
47-
self.totalErrors = 0;
48-
self.totalTime = 0.0;
49-
}
50-
5151
- (void)beginTestSuite:(NSDictionary *)event
5252
{
5353
self.testResults = [NSMutableArray array];
@@ -66,24 +66,23 @@ - (void)endTestSuite:(NSDictionary *)event
6666
self.totalErrors += [event[kReporter_EndTestSuite_UnexpectedExceptionCountKey] intValue];
6767
self.totalTime += [event[kReporter_EndTestSuite_TotalDurationKey] floatValue];
6868
[self.testSuites addObject:@{
69-
@"event": event,
70-
@"results": self.testResults
69+
kJUnitReporter_Suite_Event: event,
70+
kJUnitReporter_Suite_Results: self.testResults
7171
}];
7272
self.testResults = nil;
7373
}
7474
}
7575

76-
- (void)endOcunit:(NSDictionary *)event
76+
- (void)close
7777
{
7878
[self write:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"];
7979
[self writeWithFormat:
80-
@"<testsuites name=\"%@\" tests=\"%d\" failures=\"%d\" errors=\"%d\" time=\"%f\">\n",
81-
[self xmlEscape:event[kReporter_EndOCUnit_BundleNameKey]],
80+
@"<testsuites name=\"AllTestUnits\" tests=\"%d\" failures=\"%d\" errors=\"%d\" time=\"%f\">\n",
8281
self.totalTests, self.totalFailures, self.totalErrors, self.totalTime];
8382

8483
for (NSDictionary *testSuite in self.testSuites) {
85-
NSDictionary *suiteEvent = testSuite[@"event"];
86-
NSArray *suiteResults = testSuite[@"results"];
84+
NSDictionary *suiteEvent = testSuite[kJUnitReporter_Suite_Event];
85+
NSArray *suiteResults = testSuite[kJUnitReporter_Suite_Results];
8786
[self writeWithFormat:
8887
@"\t<testsuite name=\"%@\" tests=\"%d\" failures=\"%d\" errors=\"%d\" "
8988
@"time=\"%f\" timestamp=\"%@\">\n",
@@ -119,6 +118,7 @@ - (void)endOcunit:(NSDictionary *)event
119118
}
120119
[self write:@"</testsuites>\n"];
121120
self.testSuites = nil;
121+
[super close];
122122
}
123123

124124
#pragma mark Private Methods

0 commit comments

Comments
 (0)