diff --git a/Cedar.xcodeproj/project.pbxproj b/Cedar.xcodeproj/project.pbxproj index 7ad52bcd..1879b8d2 100644 --- a/Cedar.xcodeproj/project.pbxproj +++ b/Cedar.xcodeproj/project.pbxproj @@ -361,6 +361,7 @@ AE9BA627184D203000079A97 /* ConformTo.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = 5898AEAF3FE8C683E6F23C1D /* ConformTo.h */; }; AE9EAAD9178C789800CCF7DA /* CDRDefaultReporterSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEBCDD7E173ACD6700B42B58 /* CDRDefaultReporterSpec.mm */; }; AE9EAADA178C789900CCF7DA /* CDRDefaultReporterSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEBCDD7E173ACD6700B42B58 /* CDRDefaultReporterSpec.mm */; }; + AEA8962C19D0C242007D5C08 /* CDROTestRunner.m in Sources */ = {isa = PBXBuildFile; fileRef = 96EA1CA7142C6425001A78E0 /* CDROTestRunner.m */; }; AEB1A74215F304A9002E4167 /* StubbedMethod.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEB1A74115F304A9002E4167 /* StubbedMethod.mm */; }; AEB1A74315F304A9002E4167 /* StubbedMethod.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEB1A74115F304A9002E4167 /* StubbedMethod.mm */; }; AEB45A911496C8D800845D09 /* RaiseException.h in Headers */ = {isa = PBXBuildFile; fileRef = AEB45A901496C8D800845D09 /* RaiseException.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -2571,6 +2572,7 @@ E31179D6161FD937007D3CDE /* CDRSlowTestStatistics.m in Sources */, 22FB7B4416ACBB3A00012D69 /* HeadlessSimulatorWorkaround.m in Sources */, AE7F170B172730B000E1146D /* NSInvocation+Cedar.m in Sources */, + AEA8962C19D0C242007D5C08 /* CDROTestRunner.m in Sources */, 34ADD2E11921F18100B057AC /* AnyInstanceOfClassArgument.mm in Sources */, AED23E6D173D5545003D7A41 /* BeCloseTo.mm in Sources */, AE02021A17452007009A7915 /* StringifiersBase.mm in Sources */, diff --git a/OCUnitAppTests/OCUnitApplicationTestsWithSenTestingKit.m b/OCUnitAppTests/OCUnitApplicationTestsWithSenTestingKit.m index ef022875..8cf88ea9 100644 --- a/OCUnitAppTests/OCUnitApplicationTestsWithSenTestingKit.m +++ b/OCUnitAppTests/OCUnitApplicationTestsWithSenTestingKit.m @@ -1,6 +1,7 @@ #define SENTEST_IGNORE_DEPRECATION_WARNING #import #import "OCUnitAppAppDelegate.h" // should NOT be included in OCUnitAppTests target +#import "CDRXTestSuite.h" @interface ExampleApplicationTestsWithSenTestingKit : SenTestCase @end @@ -24,4 +25,18 @@ - (void)testCanLoadNibFilesFromApp { NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"DummyView" owner:nil options:nil]; STAssertEquals([[views lastObject] class], [UIView class], @"expected last view of DummyView nib to be UIView kind"); } + +- (void)testRunningCedarExamples { + SenTestSuite *defaultSuite = [SenTestSuite defaultTestSuite]; + STAssertTrue([[defaultSuite valueForKeyPath:@"tests.name"] containsObject:@"Cedar"], @"should contain a Cedar test suite"); +} + +- (void)testCallingDefaultTestSuiteMultipleTimesShouldHaveDifferentReporters { + SenTestSuite *defaultSuite1 = [SenTestSuite defaultTestSuite]; + SenTestSuite *defaultSuite2 = [SenTestSuite defaultTestSuite]; + + CDRXTestSuite *suite1 = [[defaultSuite1 valueForKey:@"tests"] lastObject]; + CDRXTestSuite *suite2 = [[defaultSuite2 valueForKey:@"tests"] lastObject]; + STAssertTrue(suite1.dispatcher != suite2.dispatcher, @"Each test suite should have its own dispatcher"); +} @end diff --git a/Source/CDRFunctions.m b/Source/CDRFunctions.m index 24833ba1..4d533d7c 100644 --- a/Source/CDRFunctions.m +++ b/Source/CDRFunctions.m @@ -393,7 +393,7 @@ static id CDRCreateXCTestSuite() { CDRReportDispatcher *dispatcher = [[[CDRReportDispatcher alloc] initWithReporters:CDRReportersToRun()] autorelease]; - [CDRXTestSuite setDispatcher:dispatcher]; + [testSuite setDispatcher:dispatcher]; NSArray *groups = CDRRootGroupsFromSpecs(specs); [dispatcher runWillStartWithGroups:groups andRandomSeed:seed]; diff --git a/Source/CDROTestRunner.m b/Source/CDROTestRunner.m index 7608c20e..b5d9950c 100644 --- a/Source/CDROTestRunner.m +++ b/Source/CDROTestRunner.m @@ -8,10 +8,8 @@ @interface CDROTestRunner () @implementation CDROTestRunner -#if !TARGET_OS_IPHONE + (void)load { CDRHijackOCUnitAndXCTestRun((IMP)CDRRunTests); } -#endif @end diff --git a/Source/iPhone/XCTest/CDRSpec+XCTestSupport.m b/Source/iPhone/XCTest/CDRSpec+XCTestSupport.m index 69ebebd7..d6ba0ca6 100644 --- a/Source/iPhone/XCTest/CDRSpec+XCTestSupport.m +++ b/Source/iPhone/XCTest/CDRSpec+XCTestSupport.m @@ -33,7 +33,7 @@ - (id)testSuiteWithRandomSeed:(unsigned int)seed dispatcher:(CDRReportDispatcher Class newXCTestSubclass = [self createTestCaseSubclass]; CDROTestNamer *namer = [[[CDROTestNamer alloc] init] autorelease]; - NSArray *examples = [self allExamples]; + NSArray *examples = [self allExamplesToRun]; NSMutableArray *testInvocations = [NSMutableArray array]; for (CDRExample *example in examples) { @@ -84,7 +84,7 @@ - (Class)createTestCaseSubclass { return newXCTestSubclass; } -- (NSArray *)allExamples { +- (NSArray *)allExamplesToRun { NSMutableArray *examples = [NSMutableArray array]; NSMutableArray *groupsQueue = [NSMutableArray arrayWithArray:self.rootGroup.examples]; while (groupsQueue.count) { diff --git a/Source/iPhone/XCTest/CDRXTestSuite.h b/Source/iPhone/XCTest/CDRXTestSuite.h index d84ebc89..5d10695e 100644 --- a/Source/iPhone/XCTest/CDRXTestSuite.h +++ b/Source/iPhone/XCTest/CDRXTestSuite.h @@ -4,7 +4,7 @@ @interface CDRXTestSuite : NSObject -+ (void)setDispatcher:(CDRReportDispatcher *)dispatcher; -+ (CDRReportDispatcher *)dispatcher; +- (void)setDispatcher:(CDRReportDispatcher *)dispatcher; +- (CDRReportDispatcher *)dispatcher; @end diff --git a/Source/iPhone/XCTest/CDRXTestSuite.m b/Source/iPhone/XCTest/CDRXTestSuite.m index 63c4835e..176e0bd3 100644 --- a/Source/iPhone/XCTest/CDRXTestSuite.m +++ b/Source/iPhone/XCTest/CDRXTestSuite.m @@ -2,18 +2,16 @@ #import "CDRReportDispatcher.h" #import -static CDRReportDispatcher *__CDR_XCTestSuiteDispatcher; +const char *CDRXDispatcherKey; @implementation CDRXTestSuite -+ (void)setDispatcher:(CDRReportDispatcher *)dispatcher { - CDRReportDispatcher *oldValue = __CDR_XCTestSuiteDispatcher; - __CDR_XCTestSuiteDispatcher = [dispatcher retain]; - [oldValue release]; +- (void)setDispatcher:(CDRReportDispatcher *)dispatcher { + objc_setAssociatedObject(self, &CDRXDispatcherKey, dispatcher, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -+ (CDRReportDispatcher *)dispatcher { - return __CDR_XCTestSuiteDispatcher; +- (CDRReportDispatcher *)dispatcher { + return objc_getAssociatedObject(self, &CDRXDispatcherKey); } - (void)performTest:(id)aRun { @@ -21,7 +19,7 @@ - (void)performTest:(id)aRun { IMP superPerformTest = class_getMethodImplementation(parentClass, @selector(performTest:)); ((void (*)(id instance, SEL cmd, id run))superPerformTest)(self, _cmd, aRun); - [__CDR_XCTestSuiteDispatcher runDidComplete]; + [[self dispatcher] runDidComplete]; } @end diff --git a/XCUnitAppTests/XCUnitApplicationTestsWithXCTest.m b/XCUnitAppTests/XCUnitApplicationTestsWithXCTest.m index 64913bdd..70b25ce3 100644 --- a/XCUnitAppTests/XCUnitApplicationTestsWithXCTest.m +++ b/XCUnitAppTests/XCUnitApplicationTestsWithXCTest.m @@ -23,4 +23,9 @@ - (void)testCanLoadNibFilesFromApp { NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"DummyView" owner:nil options:nil]; XCTAssertEqual([[views lastObject] class], [UIView class], @"expected last view of DummyView nib to be UIView kind"); } + +- (void)testRunningCedarExamples { + XCTestSuite *defaultSuite = [XCTestSuite defaultTestSuite]; + XCTAssert([[defaultSuite valueForKeyPath:@"tests.name"] containsObject:@"Cedar"]); +} @end