BOOL FBXCTestMain()

in Shims/Shimulator/TestLoadingShim/FBXCTestMain.m [99:149]


BOOL FBXCTestMain()
{
  if (!FBLoadXCTestIfNeeded()) {
    exit(TestShimExitCodeXCTestFailedLoading);
  }
  NSString *configurationPath = NSProcessInfo.processInfo.environment[@"XCTestConfigurationFilePath"];
  if (!configurationPath) {
    NSLog(@"Failed to load XCTest as XCTestConfigurationFilePath environment variable is empty");
    return NO;
  }
  NSError *error;
  NSData *data = [NSData dataWithContentsOfFile:configurationPath options:0 error:&error];
  if (!data) {
    NSLog(@"Failed to load data of %@ due to %@", configurationPath, error);
    return NO;
  }
  XCTestConfiguration *configuration = nil;
  if([NSKeyedUnarchiver respondsToSelector:@selector(xct_unarchivedObjectOfClass:fromData:)]){
    configuration = (XCTestConfiguration *)[NSKeyedUnarchiver xct_unarchivedObjectOfClass:NSClassFromString(@"XCTestConfiguration") fromData:data];
  } else {
    configuration = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  }
  if (!configuration) {
    NSLog(@"Loaded XCTestConfiguration is nil");
    return NO;
  }

  NSURL *testBundleURL = configuration.testBundleURL;
  if (!testBundleURL) {
    NSLog(@"XCTestConfiguration has no test bundle URL value");
    return NO;
  }

  NSBundle *testBundle = [NSBundle bundleWithURL:testBundleURL];
  if (!testBundle) {
    NSLog(@"Failed to open test bundle from %@", testBundleURL);
    return NO;
  }

  if (![testBundle loadAndReturnError:&error]) {
    NSLog(@"Failed load test bundle with error: %@", error);
    return NO;
  }
  void (*XCTestMain)(XCTestConfiguration *) = (void (*)(XCTestConfiguration *))FBRetrieveXCTestSymbol("_XCTestMain");
  FBDeployBlockWhenAppLoads(^{
    CFRunLoopPerformBlock([NSRunLoop mainRunLoop].getCFRunLoop, kCFRunLoopCommonModes, ^{
      XCTestMain(configuration);
    });
  });
  return YES;
}