Skip to content

Instantly share code, notes, and snippets.

@jmoody
Created January 30, 2013 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmoody/4672008 to your computer and use it in GitHub Desktop.
Save jmoody/4672008 to your computer and use it in GitHub Desktop.
a main.m file for GHUnit that fixes problems described in gh-unit issue 96 - command line tests failing for Xcode 4.5 (and 4.6) for iOS 6
#import <objc/runtime.h>
#import <objc/message.h>
@interface UIWindow (Private)
- (void) swizzled_createContext;
@end
@implementation UIWindow (Private)
- (void) swizzled_createContext {
// nop
}
@end
int main(int argc, char *argv[]) {
int retVal;
@autoreleasepool {
CFMessagePortRef portRef = NULL;
if (getenv("GHUNIT_CLI")) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
Method originalWindowCreateContext =
class_getInstanceMethod([UIWindow class],
@selector(_createContext));
#pragma clang diagnostic pop
Method swizzledWindowCreateConext =
class_getInstanceMethod([UIWindow class],
@selector(swizzled_createContext));
method_exchangeImplementations(originalWindowCreateContext,
swizzledWindowCreateConext);
portRef = CFMessagePortCreateLocal(NULL,
(CFStringRef) @"PurpleWorkspacePort",
NULL,
NULL,
NULL);
}
retVal = UIApplicationMain(argc, argv,
NSStringFromClass([UIApplication class]),
@"GHUnitIOSAppDelegate");
if (portRef != NULL) { CFRelease(portRef); }
}
return retVal;
}
@jmoody
Copy link
Author

jmoody commented Jan 30, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment