Trigger XCTestMain after application is launched
Summary: We kick off tests right after static initializer is called, which might be a bit dangerous since application might take a while to load. This ofc might cause some test failures so delaying till app is loaded would be much better Reviewed By: superb Differential Revision: D8540994 fbshipit-source-id: 3c704441c3d70635c8202fe4e1bba53e6829c798
This commit is contained in:
Родитель
ecb57d0f7a
Коммит
4c687d5991
Двоичные данные
Shims/Binaries/libMaculator.dylib
Двоичные данные
Shims/Binaries/libMaculator.dylib
Двоичный файл не отображается.
Двоичные данные
Shims/Binaries/libShimulator.dylib
Двоичные данные
Shims/Binaries/libShimulator.dylib
Двоичный файл не отображается.
|
@ -16,6 +16,14 @@
|
||||||
#import "XCTestPrivate.h"
|
#import "XCTestPrivate.h"
|
||||||
#import "FBDebugLog.h"
|
#import "FBDebugLog.h"
|
||||||
|
|
||||||
|
#include "TargetConditionals.h"
|
||||||
|
|
||||||
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#elif TARGET_OS_MAC
|
||||||
|
#import <AppKit/AppKit.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static NSString *const ShimulatorStartXCTest = @"SHIMULATOR_START_XCTEST";
|
static NSString *const ShimulatorStartXCTest = @"SHIMULATOR_START_XCTEST";
|
||||||
|
|
||||||
__attribute__((constructor)) static void XCTestMainEntryPoint()
|
__attribute__((constructor)) static void XCTestMainEntryPoint()
|
||||||
|
@ -54,6 +62,21 @@ BOOL FBLoadXCTestIfNeeded()
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FBDeployBlockWhenAppLoads(void(^mainBlock)()) {
|
||||||
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
|
NSString *notification = UIApplicationDidFinishLaunchingNotification;
|
||||||
|
#elif TARGET_OS_MAC
|
||||||
|
NSString *notification = NSApplicationDidFinishLaunchingNotification;
|
||||||
|
#endif
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserverForName:notification
|
||||||
|
object:nil
|
||||||
|
queue:[NSOperationQueue mainQueue]
|
||||||
|
usingBlock:^(NSNotification *note) {
|
||||||
|
mainBlock();
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
BOOL FBXCTestMain()
|
BOOL FBXCTestMain()
|
||||||
{
|
{
|
||||||
if (!FBLoadXCTestIfNeeded()) {
|
if (!FBLoadXCTestIfNeeded()) {
|
||||||
|
@ -98,10 +121,11 @@ BOOL FBXCTestMain()
|
||||||
NSLog(@"Failed load test bundle with error: %@", error);
|
NSLog(@"Failed load test bundle with error: %@", error);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*XCTestMain)(XCTestConfiguration *) = (void (*)(XCTestConfiguration *))FBRetrieveXCTestSymbol("_XCTestMain");
|
void (*XCTestMain)(XCTestConfiguration *) = (void (*)(XCTestConfiguration *))FBRetrieveXCTestSymbol("_XCTestMain");
|
||||||
CFRunLoopPerformBlock([NSRunLoop mainRunLoop].getCFRunLoop, kCFRunLoopCommonModes, ^{
|
FBDeployBlockWhenAppLoads(^{
|
||||||
XCTestMain(configuration);
|
CFRunLoopPerformBlock([NSRunLoop mainRunLoop].getCFRunLoop, kCFRunLoopCommonModes, ^{
|
||||||
|
XCTestMain(configuration);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче