Skip to content
Browse files

pulled out common functionality from CDROTestRunner and CDROTestIPhon…

…eRunner into CDROTestHelper
  • Loading branch information...
1 parent 190517f commit ff89f13eb8302f848da2e650c0befb39d6346e7f @cppforlife cppforlife committed Dec 8, 2011
View
12 Cedar.xcodeproj/project.pbxproj
@@ -34,6 +34,10 @@
96158A9F144A91C4005895CE /* OCUnitAppLogicTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 96158A9E144A91C4005895CE /* OCUnitAppLogicTests.mm */; };
96158AA2144A91DC005895CE /* DummyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 96158AA1144A91DC005895CE /* DummyModel.m */; };
96158AA3144A9210005895CE /* DummyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 96158AA1144A91DC005895CE /* DummyModel.m */; };
+ 9637852B1491D6D40059C9F6 /* CDROTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 9637852A1491D6D30059C9F6 /* CDROTestHelper.m */; };
+ 9637852C1491D6D40059C9F6 /* CDROTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 9637852A1491D6D30059C9F6 /* CDROTestHelper.m */; };
+ 9637852E1491D84F0059C9F6 /* CDROTestHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 9637852D1491D84F0059C9F6 /* CDROTestHelper.h */; };
+ 9637852F1491D84F0059C9F6 /* CDROTestHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 9637852D1491D84F0059C9F6 /* CDROTestHelper.h */; };
966E74ED145A6CA0002E8D49 /* ShouldSyntaxSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 966E74EC145A6CA0002E8D49 /* ShouldSyntaxSpec.mm */; };
966E74EE145A6CA0002E8D49 /* ShouldSyntaxSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 966E74EC145A6CA0002E8D49 /* ShouldSyntaxSpec.mm */; };
968BA92F143485F800EA40B3 /* CDROTestIPhoneRunner.h in Headers */ = {isa = PBXBuildFile; fileRef = 968BA92E143485F800EA40B3 /* CDROTestIPhoneRunner.h */; };
@@ -370,6 +374,8 @@
96158A9E144A91C4005895CE /* OCUnitAppLogicTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OCUnitAppLogicTests.mm; sourceTree = "<group>"; };
96158AA0144A91DC005895CE /* DummyModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DummyModel.h; sourceTree = "<group>"; };
96158AA1144A91DC005895CE /* DummyModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DummyModel.m; sourceTree = "<group>"; };
+ 9637852A1491D6D30059C9F6 /* CDROTestHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDROTestHelper.m; sourceTree = "<group>"; };
+ 9637852D1491D84F0059C9F6 /* CDROTestHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDROTestHelper.h; sourceTree = "<group>"; };
966E74EC145A6CA0002E8D49 /* ShouldSyntaxSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ShouldSyntaxSpec.mm; path = ../ShouldSyntaxSpec.mm; sourceTree = "<group>"; };
968BA92E143485F800EA40B3 /* CDROTestIPhoneRunner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDROTestIPhoneRunner.h; sourceTree = "<group>"; };
96A07F0813F276640021974D /* FocusedSpecs */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = FocusedSpecs; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -773,6 +779,7 @@
42064469139B44F600C85605 /* CDRTeamCityReporter.m */,
96EA1CA6142C6425001A78E0 /* CDROTestReporter.m */,
96EA1CA7142C6425001A78E0 /* CDROTestRunner.m */,
+ 9637852A1491D6D30059C9F6 /* CDROTestHelper.m */,
);
path = Source;
sourceTree = "<group>";
@@ -798,6 +805,7 @@
42064465139B44EC00C85605 /* CDRTeamCityReporter.h */,
96EA1CAC142C6449001A78E0 /* CDROTestReporter.h */,
96EA1CAD142C6449001A78E0 /* CDROTestRunner.h */,
+ 9637852D1491D84F0059C9F6 /* CDROTestHelper.h */,
);
path = Headers;
sourceTree = "<group>";
@@ -990,6 +998,7 @@
AEF33017145B6222002F93BB /* BeLessThan.h in Headers */,
AEF33021145B69DE002F93BB /* BeLTE.h in Headers */,
AE84F0DB145B70DD00769F85 /* ShouldSyntax.h in Headers */,
+ 9637852E1491D84F0059C9F6 /* CDROTestHelper.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1001,6 +1010,7 @@
42064467139B44EC00C85605 /* CDRTeamCityReporter.h in Headers */,
96EA1CAF142C6449001A78E0 /* CDROTestReporter.h in Headers */,
968BA92F143485F800EA40B3 /* CDROTestIPhoneRunner.h in Headers */,
+ 9637852F1491D84F0059C9F6 /* CDROTestHelper.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1379,6 +1389,7 @@
AE0AF57D13E9C5B200029396 /* BeInstanceOf.mm in Sources */,
96EA1CA8142C6425001A78E0 /* CDROTestReporter.m in Sources */,
96EA1CAA142C6425001A78E0 /* CDROTestRunner.m in Sources */,
+ 9637852B1491D6D40059C9F6 /* CDROTestHelper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1436,6 +1447,7 @@
AE0AF57E13E9C5B200029396 /* BeInstanceOf.mm in Sources */,
96EA1CA9142C6425001A78E0 /* CDROTestReporter.m in Sources */,
960118BC1434867E00825FFF /* CDROTestIPhoneRunner.m in Sources */,
+ 9637852C1491D6D40059C9F6 /* CDROTestHelper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
29 Source/CDROTestHelper.m
@@ -0,0 +1,29 @@
+#import "CDROTestHelper.h"
+#import <objc/runtime.h>
+
+// This is exact copy of SenTestProbe +runTests: (https://github.com/jy/SenTestingKit/blob/master/SenTestProbe.m)
+// except that it does not call exit() at the end.
+int CDRRunOCUnitTests(id self, SEL _cmd, id ignored) {
+ BOOL hasFailed = NO;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ [[NSBundle allFrameworks] makeObjectsPerformSelector:@selector(principalClass)];
+ [NSClassFromString(@"SenTestObserver") class];
+
+ id testSuite = [self performSelector:@selector(specifiedTestSuite)];
+ id runResult = [testSuite performSelector:@selector(run)];
+ hasFailed = !(BOOL)[runResult performSelector:@selector(hasSucceeded)];
+
+ [pool release];
+ return (int)hasFailed;
+}
+
+// Hijack SenTestProble runTests: class method and run our specs instead.
+// See https://github.com/jy/SenTestingKit for more information.
+void CDRHijackOCUnitRun(IMP newImplementation) {
+ Class senTestProbeClass = objc_getClass("SenTestProbe");
+ if (senTestProbeClass) {
+ Class senTestProbeMetaClass = objc_getMetaClass("SenTestProbe");
+ class_replaceMethod(senTestProbeMetaClass, @selector(runTests:), newImplementation, "v@:@");
+ }
+}
View
26 Source/CDROTestRunner.m
@@ -1,23 +1,11 @@
#import "CDROTestRunner.h"
+#import "CDROTestHelper.h"
#import "CDRFunctions.h"
-#import <objc/runtime.h>
@implementation CDROTestRunner
-int runOCUnitTests(id self, SEL _cmd, id ignored) {
- BOOL hasFailed = NO;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- [[NSBundle allFrameworks] makeObjectsPerformSelector:@selector(principalClass)];
- // [SenTestObserver class];
- hasFailed = !(BOOL)[[[self performSelector:@selector(specifiedTestSuite)] performSelector:@selector(run)] performSelector:@selector(hasSucceeded)];
- [pool release];
-
- return (int)hasFailed;
-}
-
-void runTests(id self, SEL _cmd, id ignored) {
- int exitStatus = runOCUnitTests(self, _cmd, ignored);
+void CDRRunTests(id self, SEL _cmd, id ignored) {
+ int exitStatus = CDRRunOCUnitTests(self, _cmd, ignored);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -39,14 +27,8 @@ void runTests(id self, SEL _cmd, id ignored) {
exit(exitStatus);
}
-// Hijack SenTestProble runTests: class method and run our specs instead.
-// See https://github.com/jy/SenTestingKit for more information.
+ (void)load {
- Class senTestProbeClass = objc_getClass("SenTestProbe");
- if (senTestProbeClass) {
- Class senTestProbeMetaClass = objc_getMetaClass("SenTestProbe");
- class_replaceMethod(senTestProbeMetaClass, @selector(runTests:), (IMP)runTests, "v@:@");
- }
+ CDRHijackOCUnitRun((IMP)CDRRunTests);
}
@end
View
4 Source/Headers/CDROTestHelper.h
@@ -0,0 +1,4 @@
+#import <Foundation/Foundation.h>
+
+int CDRRunOCUnitTests(id self, SEL _cmd, id ignored);
+void CDRHijackOCUnitRun(IMP newImplementation);
View
27 Source/iPhone/CDROTestIPhoneRunner.m
@@ -1,5 +1,6 @@
#import <UIKit/UIKit.h>
#import "CDROTestIPhoneRunner.h"
+#import "CDROTestHelper.h"
#import "CedarApplicationDelegate.h"
#import "CDRFunctions.h"
#import <objc/runtime.h>
@@ -10,7 +11,7 @@
@implementation NSBundle (MainBundleHijack)
static NSBundle *mainBundle__ = nil;
-NSBundle *mainBundle(id self, SEL _cmd) {
+NSBundle *CDRMainBundle(id self, SEL _cmd) {
return mainBundle__;
}
@@ -27,7 +28,7 @@ + (void)load {
if ([[bundle bundlePath] hasSuffix:@".octest"]) {
mainBundle__ = [bundle retain];
Class nsBundleMetaClass = objc_getMetaClass("NSBundle");
- class_replaceMethod(nsBundleMetaClass, @selector(mainBundle), (IMP)mainBundle, "v@:");
+ class_replaceMethod(nsBundleMetaClass, @selector(mainBundle), (IMP)CDRMainBundle, "v@:");
}
}
[pool drain];
@@ -38,20 +39,8 @@ + (void)load {
@implementation CDROTestIPhoneRunner
-int runOCUnitTests(id self, SEL _cmd, id ignored) {
- BOOL hasFailed = NO;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- [[NSBundle allFrameworks] makeObjectsPerformSelector:@selector(principalClass)];
- // [SenTestObserver class];
- hasFailed = !(BOOL)[[[self performSelector:@selector(specifiedTestSuite)] performSelector:@selector(run)] performSelector:@selector(hasSucceeded)];
- [pool release];
-
- return (int)hasFailed;
-}
-
-void runTests(id self, SEL _cmd, id ignored) {
- int exitStatus = runOCUnitTests(self, _cmd, ignored);
+void CDRRunTests(id self, SEL _cmd, id ignored) {
+ int exitStatus = CDRRunOCUnitTests(self, _cmd, ignored);
if ([UIApplication sharedApplication]) {
BOOL isCedarApp = [[UIApplication sharedApplication] isKindOfClass:[CedarApplication class]];
@@ -73,11 +62,7 @@ void runTests(id self, SEL _cmd, id ignored) {
}
+ (void)load {
- Class senTestProbeClass = objc_getClass("SenTestProbe");
- if (senTestProbeClass) {
- Class senTestProbeMetaClass = objc_getMetaClass("SenTestProbe");
- class_replaceMethod(senTestProbeMetaClass, @selector(runTests:), (IMP)runTests, "v@:@");
- }
+ CDRHijackOCUnitRun((IMP)CDRRunTests);
}
@end

0 comments on commit ff89f13

Please sign in to comment.
Something went wrong with that request. Please try again.