Browse files

Default reporter now reports stats (time taken, example count, failur…

…e count, pending count).
  • Loading branch information...
1 parent 0cfc9d4 commit 010851e26ca19969ccd33ed8db4c9152ac03ddc4 Adam Milligan committed Nov 28, 2010
Showing with 17 additions and 0 deletions.
  1. +14 −0 Source/CDRDefaultReporter.m
  2. +3 −0 Source/Headers/CDRDefaultReporter.h
View
14 Source/CDRDefaultReporter.m
@@ -7,6 +7,7 @@ - (void)printMessages:(NSArray *)messages;
- (void)startObservingExamples:(NSArray *)examples;
- (void)stopObservingExamples:(NSArray *)examples;
- (void)reportOnExample:(CDRExample *)example;
+- (void)printStats;
@end
@implementation CDRDefaultReporter
@@ -22,6 +23,7 @@ - (id)init {
- (void)dealloc {
[rootGroups_ release];
+ [startTime_ release];
[failureMessages_ release];
[pendingMessages_ release];
[super dealloc];
@@ -31,6 +33,7 @@ - (void)dealloc {
- (void)runWillStartWithGroups:(NSArray *)groups {
rootGroups_ = [groups retain];
[self startObservingExamples:rootGroups_];
+ startTime_ = [[NSDate alloc] init];
}
- (void)runDidComplete {
@@ -44,6 +47,8 @@ - (void)runDidComplete {
if ([failureMessages_ count]) {
[self printMessages:failureMessages_];
}
+
+ [self printStats];
}
- (int)result {
@@ -68,6 +73,7 @@ - (void)startObservingExamples:(NSArray *)examples {
for (id example in examples) {
if (![example hasChildren]) {
[example addObserver:self forKeyPath:@"state" options:0 context:NULL];
+ ++exampleCount_;
} else {
[self startObservingExamples:[example examples]];
}
@@ -106,6 +112,14 @@ - (void)reportOnExample:(CDRExample *)example {
}
}
+- (void)printStats {
+ printf("\nFinished in %.4f seconds\n\n", [[NSDate date] timeIntervalSinceDate:startTime_]);
+ printf("%u examples, %u failures", exampleCount_, (unsigned int)failureMessages_.count);
+ if (pendingMessages_.count) {
+ printf(", %u pending", (unsigned int)pendingMessages_.count);
+ }
+}
+
#pragma mark KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
[self reportOnExample:object];
View
3 Source/Headers/CDRDefaultReporter.h
@@ -5,6 +5,9 @@
NSMutableArray *pendingMessages_;
NSMutableArray *failureMessages_;
+
+ NSDate *startTime_;
+ unsigned int exampleCount_;
}
@end

0 comments on commit 010851e

Please sign in to comment.