Permalink
Browse files

Merge remote-tracking branch 'onsi/permutable_tests'

  • Loading branch information...
2 parents 2d2a77b + ccf84a8 commit 292825db9e2b39ac7ad67ba15563d70e880a6249 @cppforlife cppforlife committed Oct 16, 2012
@@ -35,10 +35,11 @@ - (void)dealloc {
}
#pragma mark Public interface
-- (void)runWillStartWithGroups:(NSArray *)groups {
+- (void)runWillStartWithGroups:(NSArray *)groups andRandomSeed:(unsigned int)seed {
rootGroups_ = [groups retain];
[self startObservingExamples:rootGroups_];
startTime_ = [[NSDate alloc] init];
+ printf("Running With Random Seed: %i\n\n", seed);
}
- (void)runDidComplete {
View
@@ -162,17 +162,44 @@ void CDRMarkFocusedExamplesInSpecs(NSArray *specs) {
return groups;
}
+NSArray *CDRPermuteSpecClassesWithSeed(NSArray *unsortedSpecClasses, unsigned int seed) {
+ srand(seed);
+ NSArray *sortedSpecClasses = [unsortedSpecClasses sortedArrayWithOptions:0 usingComparator:^NSComparisonResult(Class class1, Class class2) {
+ return [NSStringFromClass(class1) compare:NSStringFromClass(class2)];
+ }];
+ NSMutableArray *permutedSpecClasses = [sortedSpecClasses mutableCopy];
+ for (int i = 0 ; i < sortedSpecClasses.count ; i++) {
+ [permutedSpecClasses exchangeObjectAtIndex:i
+ withObjectAtIndex:rand() % sortedSpecClasses.count];
+ }
+ return permutedSpecClasses;
+}
+
+unsigned int CDRGetRandomSeed() {
+ unsigned int seed = time(NULL) % 100000 + 2;
+ if (getenv("CEDAR_RANDOM_SEED")) {
+ seed = [[NSString stringWithUTF8String:getenv("CEDAR_RANDOM_SEED")] intValue];
+ }
+ return seed;
+}
+
int runSpecsWithCustomExampleReporters(NSArray *reporters) {
@autoreleasepool {
CDRDefineSharedExampleGroups();
CDRDefineGlobalBeforeAndAfterEachBlocks();
NSArray *specClasses = CDRSpecClassesToRun();
- NSArray *specs = CDRSpecsFromSpecClasses(specClasses);
+ unsigned int seed = CDRGetRandomSeed();
+ NSArray *permutedSpecClasses = CDRPermuteSpecClassesWithSeed(specClasses, seed);
+ NSArray *specs = CDRSpecsFromSpecClasses(permutedSpecClasses);
CDRMarkFocusedExamplesInSpecs(specs);
NSArray *groups = CDRRootGroupsFromSpecs(specs);
- [reporters makeObjectsPerformSelector:@selector(runWillStartWithGroups:) withObject:groups];
+
+ for (id<CDRExampleReporter> reporter in reporters) {
+ [reporter runWillStartWithGroups:groups andRandomSeed:seed];
+ }
+
[groups makeObjectsPerformSelector:@selector(run)];
int result = 0;
@@ -2,7 +2,7 @@
@protocol CDRExampleReporter <NSObject>
-- (void)runWillStartWithGroups:(NSArray *)groups;
+- (void)runWillStartWithGroups:(NSArray *)groups andRandomSeed:(unsigned int)seed;
- (void)runDidComplete;
- (int)result;
@@ -37,7 +37,7 @@ - (void)pushRootSpecStatusController:(NSArray *)groups {
}
#pragma mark CDRExampleReporter
-- (void)runWillStartWithGroups:(NSArray *)groups {
+- (void)runWillStartWithGroups:(NSArray *)groups andRandomSeed:(unsigned int)seed {
// The specs run on a background thread, so callbacks from the runner will
// arrive on that thread. We need to push the event to the main thread in
// order to update the UI.

0 comments on commit 292825d

Please sign in to comment.