From 2c913e3e83e5ab6dc8453798dc09f38044a1aa89 Mon Sep 17 00:00:00 2001 From: Ravi Kumar Mandala <3135049+ravimandala@users.noreply.github.com> Date: Thu, 31 Oct 2019 13:11:41 -0700 Subject: [PATCH] Fail if bp binary is not found adjacent to bluepill and also some refactoring (#380) Do not look for `bp` binary on `PATH` and simply fail if it is not found adjacent to `bluepill` binary. Also did some refactoring, cleanup and improvements like... 1. Moved a helper method to utils 2. Enhancing error messages and better error handling 3. Fixing asserts in tests 4. Renaming variables --- bluepill/src/BPApp.m | 32 ++++++------- bluepill/src/BPPacker.m | 22 ++++----- bluepill/src/BPReportCollector.m | 3 +- bluepill/src/BPRunner.h | 5 +- bluepill/src/BPRunner.m | 71 ++++++++++------------------- bluepill/src/main.m | 16 ++++--- bluepill/tests/BPAppTests.m | 11 +++-- bluepill/tests/BPIntegrationTests.m | 6 +++ bluepill/tests/BPPackerTests.m | 9 ++-- bp/src/BPConfiguration.m | 6 +-- bp/src/BPConstants.h | 1 + bp/src/BPSimulator.m | 59 +++++++++++------------- bp/src/BPUtils.h | 21 +++++++-- bp/src/BPUtils.m | 33 +++++++++++--- bp/src/BPXCTestFile.h | 2 +- bp/src/BPXCTestFile.m | 1 - bp/src/Bluepill.m | 10 ++-- bp/src/SimulatorHelper.h | 1 + 18 files changed, 157 insertions(+), 152 deletions(-) diff --git a/bluepill/src/BPApp.m b/bluepill/src/BPApp.m index 893e9c6f..0cfbd553 100644 --- a/bluepill/src/BPApp.m +++ b/bluepill/src/BPApp.m @@ -67,7 +67,7 @@ @implementation BPApp andXcodePath:(NSString *)xcodePath withError:(NSError *__autoreleasing *)errPtr { - NSMutableArray *allTests = [[NSMutableArray alloc] init]; + NSMutableArray *allXCTestFiles = [[NSMutableArray alloc] init]; NSUInteger errorCount = 0; for (NSString *key in xcTestRunDict) { if ([key isEqualToString:@"__xctestrun_metadata__"]) { @@ -83,39 +83,39 @@ @implementation BPApp errorCount++; continue; } - [allTests addObject:xcTestFile]; + [allXCTestFiles addObject:xcTestFile]; } if (errorCount) { BP_SET_ERROR(errPtr, @"Failed to load some test bundles"); return nil; } - return allTests; + return allXCTestFiles; } + (instancetype)appWithConfig:(BPConfiguration *)config withError:(NSError *__autoreleasing *)errPtr { BPApp *app = [[BPApp alloc] init]; - NSMutableArray *allTests = [[NSMutableArray alloc] init]; - + NSMutableArray *allXCTestFiles = [[NSMutableArray alloc] init]; if (config.xcTestRunDict) { NSAssert(config.xcTestRunPath, @""); [BPUtils printInfo:INFO withString:@"Using xctestrun configuration"]; NSArray *loadedTests = [BPApp testsFromXCTestRunDict:config.xcTestRunDict - andXCTestRunPath:config.xcTestRunPath + andXCTestRunPath:config.xcTestRunPath andXcodePath:config.xcodePath withError:errPtr]; if (loadedTests == nil) { return nil; } - [allTests addObjectsFromArray:loadedTests]; + [allXCTestFiles addObjectsFromArray:loadedTests]; } else if (config.appBundlePath) { NSAssert(config.appBundlePath, @"no app bundle and no xctestrun file"); - [allTests addObjectsFromArray:[BPApp testsFromAppBundle:config.appBundlePath - andTestBundlePath:config.testBundlePath - andUITargetAppPath:config.testRunnerAppPath - withError:errPtr]]; + [BPUtils printInfo:WARNING withString:@"Using broken configuration, consider using .xctestrun files"]; + [allXCTestFiles addObjectsFromArray:[BPApp testsFromAppBundle:config.appBundlePath + andTestBundlePath:config.testBundlePath + andUITargetAppPath:config.testRunnerAppPath + withError:errPtr]]; } else { BP_SET_ERROR(errPtr, @"xctestrun file must be given, see usage."); return nil; @@ -126,8 +126,8 @@ + (instancetype)appWithConfig:(BPConfiguration *)config BPXCTestFile *testFile = [BPXCTestFile BPXCTestFileFromXCTestBundle:testBundle andHostAppBundle:config.appBundlePath andUITargetAppPath:config.testRunnerAppPath - withError:errPtr]; - [allTests addObject:testFile]; + withError:errPtr]; + [allXCTestFiles addObject:testFile]; } } @@ -135,12 +135,12 @@ + (instancetype)appWithConfig:(BPConfiguration *)config for (NSString *testBundle in config.additionalUnitTestBundles) { BPXCTestFile *testFile = [BPXCTestFile BPXCTestFileFromXCTestBundle:testBundle andHostAppBundle:config.testRunnerAppPath - withError:errPtr]; - [allTests addObject:testFile]; + withError:errPtr]; + [allXCTestFiles addObject:testFile]; } } - app.testBundles = allTests; + app.testBundles = allXCTestFiles; return app; } diff --git a/bluepill/src/BPPacker.m b/bluepill/src/BPPacker.m index 23e59b22..ef5f74a3 100644 --- a/bluepill/src/BPPacker.m +++ b/bluepill/src/BPPacker.m @@ -7,8 +7,9 @@ // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -#import "BPPacker.h" +#import "bp/src/BPXCTestFile.h" #import "bp/src/BPUtils.h" +#import "BPPacker.h" @implementation BPPacker @@ -56,7 +57,7 @@ @implementation BPPacker } } } - + NSUInteger testsPerGroup = MAX(1, totalTests / numBundles); NSMutableArray *bundles = [[NSMutableArray alloc] init]; for (BPXCTestFile *xctFile in sortedXCTestFiles) { @@ -107,10 +108,13 @@ @implementation BPPacker } // load the config file - NSDictionary *testTimes = [self loadConfigFile:config.testTimeEstimatesJsonFile withError:errPtr]; - if ((errPtr && *errPtr) || !testTimes) { + NSDictionary *testTimes = [BPUtils loadSimpleJsonFile:config.testTimeEstimatesJsonFile withError:errPtr]; + if (errPtr && *errPtr) { [BPUtils printInfo:ERROR withString:@"%@", [*errPtr localizedDescription]]; return NULL; + } else if (!testTimes) { + [BPUtils printInfo:ERROR withString:@"Invalid test execution time data"]; + return NULL; } NSMutableDictionary *estimatedTimesByTestFilePath = [[NSMutableDictionary alloc] init]; @@ -161,14 +165,4 @@ @implementation BPPacker return sortedBundles; } -+ (NSDictionary *)loadConfigFile:(NSString *)file withError:(NSError **)errPtr{ - NSData *data = [NSData dataWithContentsOfFile:file - options:NSDataReadingMappedIfSafe - error:errPtr]; - if (!data) return nil; - - return [NSJSONSerialization JSONObjectWithData:data - options:kNilOptions - error:errPtr]; -} @end diff --git a/bluepill/src/BPReportCollector.m b/bluepill/src/BPReportCollector.m index c767d37c..718d5ae1 100644 --- a/bluepill/src/BPReportCollector.m +++ b/bluepill/src/BPReportCollector.m @@ -59,8 +59,7 @@ + (void)collectReportsFromPath:(NSString *)reportsPath NSNumber *isDirectory = nil; if (![url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) { [BPUtils printInfo:ERROR withString:@"Failed to get resource from url %@", url]; - } - else if (![isDirectory boolValue]) { + } else if (![isDirectory boolValue]) { if ([[url pathExtension] isEqualToString:@"xml"]) { [BPUtils printInfo:DEBUGINFO withString:@"JUnit collecting: %@", [url path]]; NSString *path = [url path]; diff --git a/bluepill/src/BPRunner.h b/bluepill/src/BPRunner.h index ab77beff..f5e7b953 100644 --- a/bluepill/src/BPRunner.h +++ b/bluepill/src/BPRunner.h @@ -16,7 +16,7 @@ @property (nonatomic, strong) BPConfiguration *config; @property (nonatomic, strong) NSString *bpExecutable; @property (nonatomic, strong) NSMutableArray *nsTaskList; -@property (nonatomic, strong) NSMutableDictionary* testHostForSimUDID; +@property (nonatomic, strong) NSDictionary *testHostSimTemplates; /*! * @discussion get a BPRunnner to run tests @@ -40,11 +40,12 @@ andNumber:(NSUInteger)number andDevice:(NSString *)deviceID andCompletionBlock:(void (^)(NSTask * ))block; + /** @discussion start running tests @return 1: test failures 0: pass -1: failed to run tests */ - (int)runWithBPXCTestFiles:(NSArray*)xcTestFiles; -- (void) interrupt; +- (void) interrupt; @end diff --git a/bluepill/src/BPRunner.m b/bluepill/src/BPRunner.m index 09f77db4..a8ba6604 100644 --- a/bluepill/src/BPRunner.m +++ b/bluepill/src/BPRunner.m @@ -7,23 +7,23 @@ // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -#import "BPRunner.h" -#import "BPPacker.h" -#import "bp/src/BPUtils.h" -#include -#include -#include -#include -#include -#include -#include #import -#import "bp/src/BPSimulator.h" #import "bp/src/BPCreateSimulatorHandler.h" +#import "bp/src/BPSimulator.h" +#import "bp/src/BPStats.h" #import "bp/src/BPUtils.h" #import "bp/src/BPWaitTimer.h" #import "bp/src/SimulatorHelper.h" -#import "bp/src/BPStats.h" +#import "BPPacker.h" +#import "BPRunner.h" + +#include +#include +#include +#include +#include +#include +#include static int volatile interrupted = 0; @@ -59,33 +59,12 @@ @implementation BPRunner + (instancetype)BPRunnerWithConfig:(BPConfiguration *)config withBpPath:(NSString *)bpPath { BPRunner *runner = [[BPRunner alloc] init]; - runner.testHostForSimUDID = [[NSMutableDictionary alloc] init]; + runner.testHostSimTemplates = [[NSMutableDictionary alloc] init]; runner.config = config; - // Find the `bp` binary. - - if (bpPath) { - runner.bpExecutable = bpPath; - } else { - NSString *argv0 = [[[NSProcessInfo processInfo] arguments] objectAtIndex:0]; - NSString *bp = [[argv0 stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"bp"]; - if (![[NSFileManager defaultManager] isExecutableFileAtPath:bp]) { - // Search the PATH for a bp executable - BOOL foundIt = false; - NSString *path = [[[NSProcessInfo processInfo] environment] objectForKey:@"PATH"]; - for (NSString *dir in [path componentsSeparatedByString:@":"]) { - bp = [dir stringByAppendingPathComponent:@"bp"]; - if ([[NSFileManager defaultManager] isExecutableFileAtPath:bp]) { - foundIt = true; - break; - } - } - if (!foundIt) { - fprintf(stderr, "ERROR: I couldn't find the `bp` executable anywhere.\n" - "Please put it somewhere in your PATH. (Ideally next to `bluepill`.\n"); - return nil; - } - } - runner.bpExecutable = bp; + runner.bpExecutable = bpPath ?: [BPUtils findExecutablePath:@"bp"]; + if (!runner.bpExecutable) { + fprintf(stderr, "ERROR: Unable to find bp executable.\n"); + return nil; } return runner; } @@ -115,7 +94,7 @@ - (NSTask *)newTaskWithBundle:(BPXCTestFile *)bundle cfg.environmentVariables = bundle.environmentVariables; } if (self.config.cloneSimulator) { - cfg.templateSimUDID = self.testHostForSimUDID[bundle.testHostPath]; + cfg.templateSimUDID = self.testHostSimTemplates[bundle.testHostPath]; } NSError *err; NSString *tmpFileName = [NSString stringWithFormat:@"%@/bluepill-%u-config", @@ -175,11 +154,10 @@ - (NSRunningApplication *)openSimulatorAppWithConfiguration:(BPConfiguration *)c NSWorkspaceLaunchAndHide; //launch Simulator.app without booting a simulator NSDictionary *configuration = @{NSWorkspaceLaunchConfigurationArguments:@[@"-StartLastDeviceOnLaunch",@"0"]}; - NSRunningApplication *app = [[NSWorkspace sharedWorkspace] - launchApplicationAtURL:simulatorURL - options:launchOptions - configuration:configuration - error:errPtr]; + NSRunningApplication *app = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:simulatorURL + options:launchOptions + configuration:configuration + error:errPtr]; if (!app) { [BPUtils printInfo:ERROR withString:@"Launch Simulator.app returned error: %@", [*errPtr localizedDescription]]; return nil; @@ -203,7 +181,6 @@ - (int)runWithBPXCTestFiles:(NSArray *)xcTestFiles { if (sigaction(SIGHUP, &new_action, NULL) != 0) { [BPUtils printInfo:ERROR withString:@"Could not install SIGHUP handler: %s", strerror(errno)]; } - BPSimulator *bpSimulator = [BPSimulator simulatorWithConfiguration:self.config]; NSUInteger numSims = [self.config.numSims intValue]; [BPUtils printInfo:INFO withString:@"This is Bluepill %s", [BPUtils version]]; @@ -220,8 +197,8 @@ - (int)runWithBPXCTestFiles:(NSArray *)xcTestFiles { numSims = bundles.count; } if (self.config.cloneSimulator) { - self.testHostForSimUDID = [bpSimulator createSimulatorAndInstallAppWithBundles:xcTestFiles]; - if ([self.testHostForSimUDID count] == 0) { + self.testHostSimTemplates = [bpSimulator createSimulatorAndInstallAppWithBundles:xcTestFiles]; + if ([self.testHostSimTemplates count] == 0) { return 1; } } diff --git a/bluepill/src/main.m b/bluepill/src/main.m index ae1f66d6..2ba283de 100644 --- a/bluepill/src/main.m +++ b/bluepill/src/main.m @@ -8,15 +8,15 @@ // WITHOUT WARRANTIES OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. #import -#import "BPApp.h" +#import +#import #import "bp/src/BPConfiguration.h" -#import "BPRunner.h" -#import "bp/src/BPUtils.h" #import "bp/src/BPStats.h" +#import "bp/src/BPUtils.h" #import "bp/src/BPWriter.h" +#import "BPApp.h" #import "BPReportCollector.h" -#import -#import +#import "BPRunner.h" #include #include @@ -88,7 +88,7 @@ int main(int argc, char * argv[]) { NSError *err = nil; if (![config processOptionsWithError:&err] || ![config validateConfigWithError:&err]) { - fprintf(stderr, "%s: invalid configuration\n\t%s\n", + fprintf(stderr, "%s: Invalid configuration\n\t%s\n", basename(argv[0]), [[err localizedDescription] UTF8String]); exit(1); } @@ -111,6 +111,10 @@ int main(int argc, char * argv[]) { [[BPStats sharedStats] endTimer:@"Normalizing Configuration" withResult:@"INFO"]; // start a runner and let it fly BPRunner *runner = [BPRunner BPRunnerWithConfig:normalizedConfig withBpPath:nil]; + if (!runner) { + fprintf(stderr, "ERROR: Unable to create Bluepill Runner.\n"); + exit(1); + } rc = [runner runWithBPXCTestFiles:app.testBundles]; if (config.outputDirectory) { // write the stats diff --git a/bluepill/tests/BPAppTests.m b/bluepill/tests/BPAppTests.m index 5a715385..467978dc 100644 --- a/bluepill/tests/BPAppTests.m +++ b/bluepill/tests/BPAppTests.m @@ -8,12 +8,12 @@ // WITHOUT WARRANTIES OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. #import -#import "bp/tests/BPTestHelper.h" -#import "bp/src/BPConfiguration.h" #import "bluepill/src/BPApp.h" +#import "bp/src/BPConfiguration.h" #import "bp/src/BPXCTestFile.h" #import "bp/src/BPUtils.h" #import "bp/src/BPConstants.h" +#import "bp/tests/BPTestHelper.h" @interface BPAppTests : XCTestCase @property (nonatomic, strong) BPConfiguration* config; @@ -23,7 +23,7 @@ @implementation BPAppTests - (void)setUp { [super setUp]; - + NSString *hostApplicationPath = [BPTestHelper sampleAppPath]; NSString *testBundlePath = [BPTestHelper sampleAppNegativeTestsBundlePath]; self.config = [BPConfiguration new]; @@ -44,14 +44,15 @@ - (void)tearDown { - (void)testAppWithAppBundlePathNoError { NSError *error; self.config.testBundlePath = nil; - BPApp *app = [BPApp appWithConfig:self.config withError:nil]; + self.config.appBundlePath = [BPTestHelper sampleAppPath]; + BPApp *app = [BPApp appWithConfig:self.config withError:&error]; XCTAssertNil(error); XCTAssert(app.testBundles.count > 2); } - (void)testAppWithOnlyTestBundlePath { NSError *error; - BPApp *app = [BPApp appWithConfig:self.config withError:nil]; + BPApp *app = [BPApp appWithConfig:self.config withError:&error]; XCTAssertNil(error); XCTAssert(app.testBundles.count == 1); BPXCTestFile *testBundle = app.testBundles[0]; diff --git a/bluepill/tests/BPIntegrationTests.m b/bluepill/tests/BPIntegrationTests.m index c77e5c94..dda021af 100644 --- a/bluepill/tests/BPIntegrationTests.m +++ b/bluepill/tests/BPIntegrationTests.m @@ -57,6 +57,7 @@ - (void)testOneBPInstance { NSString *bpPath = [BPTestHelper bpExecutablePath]; BPRunner *runner = [BPRunner BPRunnerWithConfig:self.config withBpPath:bpPath]; + XCTAssert(runner != nil); int rc = [runner runWithBPXCTestFiles:app.testBundles]; XCTAssert(rc == 0, @"Wanted 0, got %d", rc); XCTAssert([runner.nsTaskList count] == 0); @@ -72,6 +73,7 @@ - (void)testTwoBPInstances { NSString *bpPath = [BPTestHelper bpExecutablePath]; BPRunner *runner = [BPRunner BPRunnerWithConfig:self.config withBpPath:bpPath]; + XCTAssert(runner != nil); int rc = [runner runWithBPXCTestFiles:app.testBundles]; XCTAssert(rc == 0); XCTAssert([runner.nsTaskList count] == 0); @@ -90,6 +92,7 @@ - (void)testClonedSimulators { NSString *bpPath = [BPTestHelper bpExecutablePath]; BPRunner *runner = [BPRunner BPRunnerWithConfig:self.config withBpPath:bpPath]; + XCTAssert(runner != nil); int rc = [runner runWithBPXCTestFiles:app.testBundles]; XCTAssert(rc == 0); XCTAssert([runner.nsTaskList count] == 0); @@ -112,6 +115,7 @@ - (void)testTwoBPInstancesWithUITests { NSString *bpPath = [BPTestHelper bpExecutablePath]; BPRunner *runner = [BPRunner BPRunnerWithConfig:self.config withBpPath:bpPath]; + XCTAssert(runner != nil); int rc = [runner runWithBPXCTestFiles:app.testBundles]; XCTAssert(rc == 0); XCTAssert([runner.nsTaskList count] == 0); @@ -129,6 +133,7 @@ - (void)testTwoBPInstancesWithXCTestRunFile { BPApp *app = [BPApp appWithConfig:self.config withError:&err]; NSString *bpPath = [BPTestHelper bpExecutablePath]; BPRunner *runner = [BPRunner BPRunnerWithConfig:self.config withBpPath:bpPath]; + XCTAssert(runner != nil); int rc = [runner runWithBPXCTestFiles:app.testBundles]; XCTAssert(app.testBundles[1].skipTestIdentifiers.count == 8); XCTAssert(rc != 0); // this runs tests that fail @@ -142,6 +147,7 @@ - (void)testTwoBPInstancesTestCaseFail { withError:&err]; NSString *bpPath = [BPTestHelper bpExecutablePath]; BPRunner *runner = [BPRunner BPRunnerWithConfig:self.config withBpPath:bpPath]; + XCTAssert(runner != nil); int rc = [runner runWithBPXCTestFiles:app.testBundles]; XCTAssert(rc != 0); XCTAssert([runner.nsTaskList count] == 0); diff --git a/bluepill/tests/BPPackerTests.m b/bluepill/tests/BPPackerTests.m index f9ee0e57..720da5c7 100644 --- a/bluepill/tests/BPPackerTests.m +++ b/bluepill/tests/BPPackerTests.m @@ -7,12 +7,12 @@ // #import -#import "bp/tests/BPTestHelper.h" -#import "bp/src/BPConfiguration.h" -#import "bp/src/BPUtils.h" #import "bluepill/src/BPRunner.h" #import "bluepill/src/BPApp.h" #import "bluepill/src/BPPacker.h" +#import "bp/tests/BPTestHelper.h" +#import "bp/src/BPConfiguration.h" +#import "bp/src/BPUtils.h" #import "bp/src/BPXCTestFile.h" #import "bp/src/BPConstants.h" @@ -50,9 +50,9 @@ - (void)testPackingWithXctFileContainingSkipTestIdentifiers { self.config.testBundlePath = [BPTestHelper sampleAppBalancingTestsBundlePath]; self.config.numSims = @2; BPApp *app = [BPApp appWithConfig:self.config withError:nil]; + XCTAssert(app != nil); app.testBundles[0].skipTestIdentifiers = @[@"BPSampleAppTests/testCase000", @"BPSampleAppTests/testCase001"]; - XCTAssert(app != nil); NSArray *bundles; bundles = [BPPacker packTests:app.testBundles configuration:self.config andError:nil]; for (BPXCTestFile *file in app.testBundles) { @@ -65,6 +65,7 @@ - (void)testPackingProvidesBalancedBundles { self.config.testBundlePath = [BPTestHelper sampleAppBalancingTestsBundlePath]; self.config.numSims = @8; BPApp *app = [BPApp appWithConfig:self.config withError:nil]; + XCTAssert(app != nil); NSMutableArray *testCasesToSkip = [NSMutableArray new]; for (BPXCTestFile *xctFile in app.testBundles) { [testCasesToSkip addObjectsFromArray:xctFile.allTestCases]; diff --git a/bp/src/BPConfiguration.m b/bp/src/BPConfiguration.m index da65f28b..b2068c96 100644 --- a/bp/src/BPConfiguration.m +++ b/bp/src/BPConfiguration.m @@ -79,7 +79,7 @@ typedef NS_OPTIONS(NSUInteger, BPOptionType) { {'o', "output-dir", BP_MASTER | BP_SLAVE, NO, NO, required_argument, NULL, BP_VALUE | BP_PATH, "outputDirectory", "Directory where to put output log files (bluepill only)."}, {'j', "test-time-estimates-json", BP_MASTER, NO, NO, required_argument, NULL, BP_VALUE | BP_PATH, "testTimeEstimatesJsonFile", - "Directory where Bluepill looks for input files with test execution time estimates (bluepill only)."}, + "Path of the input file with test execution time estimates."}, {'r', "runtime", BP_MASTER | BP_SLAVE, NO, NO, required_argument, BP_DEFAULT_RUNTIME, BP_VALUE, "runtime", "What runtime to use."}, {'x', "exclude", BP_MASTER | BP_SLAVE, NO, NO, required_argument, NULL, BP_LIST, "testCasesToSkip", @@ -273,8 +273,7 @@ - (void)printConfig { atomically:NO encoding:NSUTF8StringEncoding error:&err]) { - fprintf(stderr, "Could not write config to file %s\nERROR: %s\n", - [self.configOutputFile UTF8String], [[err localizedDescription] UTF8String]); + [BPUtils printInfo:ERROR withString:@"Could not write config to file %s\nERROR: %s\n", [self.configOutputFile UTF8String], [[err localizedDescription] UTF8String]]; } } @@ -659,7 +658,6 @@ - (BOOL)validateConfigWithError:(NSError *__autoreleasing *)errPtr { return NO; } } - if (self.screenshotsDirectory) { if ([[NSFileManager defaultManager] fileExistsAtPath:self.screenshotsDirectory isDirectory:&isdir]) { if (!isdir) { diff --git a/bp/src/BPConstants.h b/bp/src/BPConstants.h index fcb88fc1..922392a2 100644 --- a/bp/src/BPConstants.h +++ b/bp/src/BPConstants.h @@ -15,6 +15,7 @@ #define BP_DAEMON_PROTOCOL_VERSION 26 #define BP_DEFAULT_XCODE_VERSION "11.1" #define BP_MAX_PROCESSES_PERCENT 0.75 +#define BP_TM_PROTOCOL_VERSION 17 extern NSString * const kCFBundleIdentifier; diff --git a/bp/src/BPSimulator.m b/bp/src/BPSimulator.m index c0f2c53e..4f8cee3c 100644 --- a/bp/src/BPSimulator.m +++ b/bp/src/BPSimulator.m @@ -7,19 +7,19 @@ // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -#import "BPSimulator.h" -#import "SimulatorHelper.h" -#import "BPConfiguration.h" -#import "BPConstants.h" -#import "BPTreeParser.h" -#import "BPUtils.h" #import #import +#import "BPConfiguration.h" +#import "BPConstants.h" +#import "BPCreateSimulatorHandler.h" +#import "BPSimulator.h" #import "BPTestBundleConnection.h" #import "BPTestDaemonConnection.h" +#import "BPTreeParser.h" +#import "BPUtils.h" #import "BPWaitTimer.h" -#import "BPCreateSimulatorHandler.h" #import "PrivateHeaders/CoreSimulator/CoreSimulator.h" +#import "SimulatorHelper.h" @interface BPSimulator() @@ -40,7 +40,7 @@ + (instancetype)simulatorWithConfiguration:(BPConfiguration *)config { } - (NSMutableDictionary *)createSimulatorAndInstallAppWithBundles:(NSArray*)testBundles { - NSMutableDictionary* testHostForSimUDID = [[NSMutableDictionary alloc] init]; + NSMutableDictionary* testHostSimTemplates = [[NSMutableDictionary alloc] init]; NSString *simulatorUDIDString = nil; NSError *error = nil; if (self.config.appBundlePath) { @@ -50,7 +50,7 @@ - (NSMutableDictionary *)createSimulatorAndInstallAppWithBundles:(NSArray*) dict ++ (instancetype)BPXCTestFileFromDictionary:(NSDictionary*)dict withTestRoot:(NSString *)testRoot andXcodePath:(NSString *)xcodePath andError:(NSError **)errPtr; diff --git a/bp/src/BPXCTestFile.m b/bp/src/BPXCTestFile.m index 942c07a5..ea7136bb 100644 --- a/bp/src/BPXCTestFile.m +++ b/bp/src/BPXCTestFile.m @@ -98,7 +98,6 @@ + (instancetype)BPXCTestFileFromXCTestBundle:(NSString *)path [testClass addTestCase:[[BPTestCase alloc] initWithName:parts[1]]]; } - xcTestFile.testClasses = [NSArray arrayWithArray:allClasses]; return xcTestFile; } diff --git a/bp/src/Bluepill.m b/bp/src/Bluepill.m index 5fbaa223..ac88364f 100644 --- a/bp/src/Bluepill.m +++ b/bp/src/Bluepill.m @@ -209,10 +209,9 @@ - (void)createContext { BPXCTestFile *xctTestFile = [BPXCTestFile BPXCTestFileFromXCTestBundle:context.config.testBundlePath andHostAppBundle:testHostPath withError:&error]; - NSAssert(xctTestFile != nil, @"Failed to load testcases from %@", [error localizedDescription]); + NSAssert(xctTestFile != nil, @"Failed to load testcases from: %@; Error: %@", context.config.testBundlePath, [error localizedDescription]); context.config.allTestCases = [[NSArray alloc] initWithArray: xctTestFile.allTestCases]; - context.attemptNumber = self.retries + 1; self.context = context; // Store the context on self so that it's accessible to the interrupt handler in the loop } @@ -230,10 +229,9 @@ - (void)setupExecutionWithContext:(BPExecutionContext *)context { NSError *err; NSString *tmpFileName = [BPUtils mkstemp:[NSString stringWithFormat:@"%@/%lu-bp-stdout-%u", NSTemporaryDirectory(), context.attemptNumber, getpid()] withError:&err]; - simulatorLogPath = tmpFileName; - if (!tmpFileName) { - simulatorLogPath = [NSString stringWithFormat:@"/tmp/%lu-simulator.log", context.attemptNumber]; - [BPUtils printInfo:ERROR withString:@"ERROR: %@\nLeaving log in %@", [err localizedDescription], simulatorLogPath]; + simulatorLogPath = tmpFileName? tmpFileName : [NSString stringWithFormat:@"/tmp/%lu-simulator.log", context.attemptNumber]; + if (err) { + [BPUtils printInfo:ERROR withString:@"Error: %@\nLeaving log in %@", [err localizedDescription], simulatorLogPath]; } } diff --git a/bp/src/SimulatorHelper.h b/bp/src/SimulatorHelper.h index ae730a18..a17227f6 100644 --- a/bp/src/SimulatorHelper.h +++ b/bp/src/SimulatorHelper.h @@ -33,6 +33,7 @@ /*! * @discussion get the path of the environment configuration file + * @param config the configuration object * @return return the path to the test configuration file. */ + (NSString *)testEnvironmentWithConfiguration:(BPConfiguration *)config;