Skip to content

Commit

Permalink
Support sidecar applications (#438)
Browse files Browse the repository at this point in the history
* Support Depenedencies

* Make dependencies an optional field in the test plan
  • Loading branch information
bogo authored Apr 21, 2020
1 parent 1cad980 commit 4f0384b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions bluepill/src/BPRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ - (NSTask *)newTaskWithBundle:(BPXCTestFile *)bundle
} else {
cfg.environmentVariables = bundle.environmentVariables;
}
cfg.dependencies = bundle.dependencies;
if (self.config.cloneSimulator) {
cfg.templateSimUDID = self.testHostSimTemplates[bundle.testHostPath];
}
Expand Down
2 changes: 2 additions & 0 deletions bp/src/BPConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@property (nonatomic, strong) NSString *testHost;
@property (nonatomic, strong) NSDictionary<NSString *, NSString *> *environment;
@property (nonatomic, strong) NSDictionary<NSString *, NSString *> *arguments;
@property (nonatomic, strong) NSDictionary<NSString *, NSString *> *dependencies;
@property (nonatomic, strong) NSString *testBundlePath;
@property (nonatomic, strong) NSString *testHostBundleIdentifier;
@property (nonatomic, strong) NSString *uiTargetAppPath;
Expand Down Expand Up @@ -106,6 +107,7 @@ typedef NS_ENUM(NSInteger, BPProgram) {
@property (nonatomic, strong) NSArray<NSString *> *commandLineArguments; // command line arguments for the app
@property (nonatomic, strong) NSDictionary<NSString *, NSString *> *environmentVariables;
@property (nonatomic, strong) NSDictionary<NSString *, BPTestPlan *> *tests;
@property (nonatomic, strong) NSDictionary<NSString *, NSString *> *dependencies;

// Media Assets
@property (nonatomic, strong) NSArray<NSString *> *videoPaths; // The videos to be pushed into each simulator.
Expand Down
9 changes: 8 additions & 1 deletion bp/src/BPConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ - (nonnull id)copyWithZone:(nullable NSZone *)zone {
BPTestPlan *c = [[BPTestPlan alloc] init];
c.arguments = [self.arguments copy];
c.environment = [self.environment copy];
c.dependencies = [self.dependencies copy];
c.testBundlePath = [self.testBundlePath copy];
c.testHost = [self.testHost copy];
return c;
Expand Down Expand Up @@ -332,6 +333,9 @@ - (NSString *)configString {
if (self.environmentVariables) {
[dict setValue:self.environmentVariables forKey:@"environmentVariables"];
}
if (self.dependencies) {
[dict setValue:self.dependencies forKey:@"dependencies"];
}
if ([NSJSONSerialization isValidJSONObject:dict]) {
NSError *err;
NSData *json = [NSJSONSerialization dataWithJSONObject:dict
Expand Down Expand Up @@ -377,6 +381,7 @@ - (id)mutableCopyWithZone:(NSZone *)zone {
newConfig.xcTestRunDict = self.xcTestRunDict;
newConfig.commandLineArguments = self.commandLineArguments;
newConfig.environmentVariables = self.environmentVariables;
newConfig.dependencies = self.dependencies;
newConfig.tests = self.tests;

return newConfig;
Expand Down Expand Up @@ -522,9 +527,10 @@ - (BOOL)loadConfigFile:(NSString *)file withError:(NSError **)errPtr{
BP_SET_ERROR(errPtr, @"Number of simulators set to %lu but there cannot be fewer than one simulator.", self.numSims.integerValue);
return NO;
}
// Pull out two keys that are undocumented but needed for supporting xctest
// Pull out three keys that are undocumented but needed for supporting xctest
self.commandLineArguments = [configDict objectForKey:@"commandLineArguments"];
self.environmentVariables = [configDict objectForKey:@"environmentVariables"];
self.dependencies = [configDict objectForKey:@"dependencies"];

return YES;
}
Expand Down Expand Up @@ -555,6 +561,7 @@ - (BOOL)loadTestPlan:(NSString *)file withError:(NSError **)errPtr{
plan.uiTargetAppPath = [planDictionary objectForKey:@"ui_target_app_path"];
plan.environment = [planDictionary objectForKey:@"environment"];
plan.arguments = [planDictionary objectForKey:@"arguments"];
plan.dependencies = [planDictionary objectForKey:@"dependencies"];

if (![plan isValid:errPtr]) {
BP_SET_ERROR(errPtr, @"Invalid BPTestPlan configuration: %@", plan);
Expand Down
1 change: 1 addition & 0 deletions bp/src/BPXCTestFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@property (nonatomic, strong) NSString *UITargetAppPath;
@property (nonatomic, strong) NSArray<NSString *> *skipTestIdentifiers;
@property (nonatomic, strong) NSNumber *estimatedExecutionTime;
@property (nonatomic, strong) NSDictionary <NSString *, NSString *> *dependencies;

// All test classes in the test bundle
@property (nonatomic, strong) NSArray *testClasses;
Expand Down
13 changes: 13 additions & 0 deletions bp/src/BPXCTestFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "BPConstants.h"
#import "BPTestClass.h"
#import "BPUtils.h"
#import "SimulatorHelper.h"

@implementation BPXCTestFile

Expand Down Expand Up @@ -162,6 +163,16 @@ + (instancetype)BPXCTestFileFromDictionary:(NSDictionary *)dict
if (skipTestIdentifiers) {
xcTestFile.skipTestIdentifiers = [[NSArray alloc] initWithArray:skipTestIdentifiers];
}
NSArray<NSString *> *dependencies = [dict objectForKey:@"DependentProductPaths"];
if (dependencies) {
NSMutableDictionary <NSString *, NSString *> *dependenciesWithBundleIDs = [NSMutableDictionary dictionary];
for (NSString *dependency in dependencies) {
NSString *expandedDependency = [dependency stringByReplacingOccurrencesOfString:TESTROOT withString:testRoot];
NSString *bundleID = [SimulatorHelper bundleIdForPath:expandedDependency];
dependenciesWithBundleIDs[bundleID] = expandedDependency;
}
xcTestFile.dependencies = dependenciesWithBundleIDs;
}
return xcTestFile;
}

Expand All @@ -176,6 +187,7 @@ + (instancetype)BPXCTestFileFromBPTestPlan:(BPTestPlan*)testPlan
withError:errPtr];
xcTestFile.name = name;
xcTestFile.environmentVariables = testPlan.environment;
xcTestFile.dependencies = testPlan.dependencies;

NSMutableArray<NSString *> *args = [[NSMutableArray alloc] initWithCapacity:testPlan.arguments.count * 2];
for (NSString *key in xcTestFile.commandLineArguments) {
Expand Down Expand Up @@ -231,6 +243,7 @@ - (id)copyWithZone:(NSZone *)zone {
copy.testClasses = self.testClasses;
copy.commandLineArguments = self.commandLineArguments;
copy.environmentVariables = self.environmentVariables;
copy.dependencies = self.dependencies;
copy.testHostPath = self.testHostPath;
copy.testHostBundleIdentifier = self.testHostBundleIdentifier;
copy.testBundlePath= self.testBundlePath;
Expand Down
2 changes: 1 addition & 1 deletion bp/src/SimulatorHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ + (NSString *)testEnvironmentWithConfiguration:(BPConfiguration *)config {
testHostPath = config.appBundlePath;

NSString *bundleID = [self bundleIdForPath:config.appBundlePath];
xctConfig.testApplicationDependencies = @{bundleID: config.appBundlePath};
xctConfig.testApplicationDependencies = config.dependencies.count > 0 ? config.dependencies : @{bundleID: config.appBundlePath};

if (config.testRunnerAppPath) {
xctConfig.targetApplicationBundleID = bundleID;
Expand Down

0 comments on commit 4f0384b

Please sign in to comment.