Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Define common test environment in one place.
Browse files Browse the repository at this point in the history
  • Loading branch information
ExtremeMan committed May 29, 2015
1 parent 58a23ab commit 5244f8c
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 74 deletions.
26 changes: 15 additions & 11 deletions xctool/xctool/OCUnitIOSAppTestQueryRunner.m
Expand Up @@ -25,18 +25,22 @@ @implementation OCUnitIOSAppTestQueryRunner
- (NSTask *)createTaskForQuery
{
NSString *version = [_buildSettings[Xcode_SDK_NAME] stringByReplacingOccurrencesOfString:@"iphonesimulator" withString:@""];
NSMutableDictionary *environment = IOSTestEnvironment(_buildSettings);
[environment addEntriesFromDictionary:@{
@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath() stringByAppendingPathComponent:@"otest-query-lib-ios.dylib"],
// The test bundle that we want to query from, as loaded by otest-query-lib-ios.dylib.
@"OtestQueryBundlePath" : [self bundlePath],
@"__CFPREFERENCES_AVOID_DAEMON" : @"YES",
}];

return CreateTaskForSimulatorExecutable(_buildSettings[Xcode_SDK_NAME],
[self cpuType],
version,
[self testHostPath],
@[],
@{@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath() stringByAppendingPathComponent:@"otest-query-lib-ios.dylib"],
// The test bundle that we want to query from, as loaded by otest-query-lib-ios.dylib.
@"OtestQueryBundlePath" : [self bundlePath],
@"__CFPREFERENCES_AVOID_DAEMON" : @"YES",
@"DYLD_FALLBACK_FRAMEWORK_PATH" : IOSTestFrameworkDirectories()
});
return CreateTaskForSimulatorExecutable(
_buildSettings[Xcode_SDK_NAME],
[self cpuType],
version,
[self testHostPath],
@[],
environment
);
}

@end
26 changes: 15 additions & 11 deletions xctool/xctool/OCUnitIOSLogicTestQueryRunner.m
Expand Up @@ -25,18 +25,22 @@ @implementation OCUnitIOSLogicTestQueryRunner
- (NSTask *)createTaskForQuery
{
NSString *version = [_buildSettings[Xcode_SDK_NAME] stringByReplacingOccurrencesOfString:@"iphonesimulator" withString:@""];
NSMutableDictionary *environment = IOSTestEnvironment(_buildSettings);
[environment addEntriesFromDictionary:@{
@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath() stringByAppendingPathComponent:@"otest-query-lib-ios.dylib"],
// The test bundle that we want to query from, as loaded by otest-query-lib-ios.dylib.
@"OtestQueryBundlePath" : [self bundlePath],
@"__CFPREFERENCES_AVOID_DAEMON" : @"YES",
}];

return CreateTaskForSimulatorExecutable(_buildSettings[Xcode_SDK_NAME],
[self cpuType],
version,
[XCToolLibExecPath() stringByAppendingPathComponent:@"otest-query-ios"],
@[],
@{@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath() stringByAppendingPathComponent:@"otest-query-lib-ios.dylib"],
// The test bundle that we want to query from, as loaded by otest-query-lib-ios.dylib.
@"OtestQueryBundlePath" : [self bundlePath],
@"__CFPREFERENCES_AVOID_DAEMON" : @"YES",
@"DYLD_FALLBACK_FRAMEWORK_PATH" : IOSTestFrameworkDirectories()
});
return CreateTaskForSimulatorExecutable(
_buildSettings[Xcode_SDK_NAME],
[self cpuType],
version,
[XCToolLibExecPath() stringByAppendingPathComponent:@"otest-query-ios"],
@[],
environment
);
}

@end
4 changes: 1 addition & 3 deletions xctool/xctool/OCUnitIOSLogicTestRunner.m
Expand Up @@ -51,11 +51,9 @@ - (NSTask *)otestTaskWithTestBundle:(NSString *)testBundlePath
}

// adding custom xctool environment variables
[env addEntriesFromDictionary:IOSTestEnvironment(_buildSettings)];
[env addEntriesFromDictionary:@{
@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath() stringByAppendingPathComponent:@"otest-shim-ios.dylib"],
@"DYLD_FRAMEWORK_PATH" : _buildSettings[Xcode_BUILT_PRODUCTS_DIR],
@"DYLD_FALLBACK_FRAMEWORK_PATH" : IOSTestFrameworkDirectories(),
@"DYLD_LIBRARY_PATH" : _buildSettings[Xcode_BUILT_PRODUCTS_DIR],
@"NSUnbufferedIO" : @"YES",
}];

Expand Down
20 changes: 9 additions & 11 deletions xctool/xctool/OCUnitOSXAppTestQueryRunner.m
Expand Up @@ -24,21 +24,19 @@ @implementation OCUnitOSXAppTestQueryRunner

- (NSTask *)createTaskForQuery
{
NSString *builtProductsDir = _buildSettings[Xcode_BUILT_PRODUCTS_DIR];
NSMutableDictionary *environment = OSXTestEnvironment(_buildSettings);
[environment addEntriesFromDictionary:@{
@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath() stringByAppendingPathComponent:@"otest-query-lib-osx.dylib"],
// The test bundle that we want to query from, as loaded by otest-query-lib-osx.dylib.
@"OtestQueryBundlePath" : [self bundlePath],
@"OBJC_DISABLE_GC" : @"YES",
@"__CFPREFERENCES_AVOID_DAEMON" : @"YES",
}];

NSTask *task = CreateTaskInSameProcessGroup();
[task setLaunchPath:[self testHostPath]];
[task setArguments:@[]];
[task setEnvironment:@{@"DYLD_INSERT_LIBRARIES" : [XCToolLibPath() stringByAppendingPathComponent:@"otest-query-lib-osx.dylib"],
// The test bundle that we want to query from, as loaded by otest-query-lib-osx.dylib.
@"OtestQueryBundlePath" : [self bundlePath],
@"DYLD_FRAMEWORK_PATH" : builtProductsDir,
@"DYLD_LIBRARY_PATH" : builtProductsDir,
@"DYLD_FALLBACK_FRAMEWORK_PATH" : OSXTestFrameworkDirectories(),
@"NSUnbufferedIO" : @"YES",
@"OBJC_DISABLE_GC" : @"YES",
@"__CFPREFERENCES_AVOID_DAEMON" : @"YES",
}];
[task setEnvironment:environment];

return task;
}
Expand Down
26 changes: 13 additions & 13 deletions xctool/xctool/OCUnitOSXAppTestRunner.m
Expand Up @@ -47,23 +47,23 @@ - (void)runTestsAndFeedOutputTo:(void (^)(NSString *))outputLineBlock
return;
}

NSArray *libraries = @[[XCToolLibPath() stringByAppendingPathComponent:@"otest-shim-osx.dylib"],
[XcodeDeveloperDirPath() stringByAppendingPathComponent:@"Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection"],
];
NSArray *libraries = @[
[XCToolLibPath() stringByAppendingPathComponent:@"otest-shim-osx.dylib"],
[XcodeDeveloperDirPath() stringByAppendingPathComponent:@"Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection"],
];

NSMutableDictionary *environment = OSXTestEnvironment(_buildSettings);
[environment addEntriesFromDictionary:@{
@"DYLD_INSERT_LIBRARIES" : [libraries componentsJoinedByString:@":"],
@"OBJC_DISABLE_GC" : !_garbageCollection ? @"YES" : @"NO",
@"XCInjectBundle" : [_buildSettings[Xcode_BUILT_PRODUCTS_DIR] stringByAppendingPathComponent:_buildSettings[Xcode_FULL_PRODUCT_NAME]],
@"XCInjectBundleInto" : testHostPath,
}];

NSTask *task = CreateTaskInSameProcessGroup();
[task setLaunchPath:testHostPath];
[task setArguments:[self testArguments]];
[task setEnvironment:[self otestEnvironmentWithOverrides:@{
@"DYLD_INSERT_LIBRARIES" : [libraries componentsJoinedByString:@":"],
@"DYLD_FRAMEWORK_PATH" : _buildSettings[Xcode_BUILT_PRODUCTS_DIR],
@"DYLD_LIBRARY_PATH" : _buildSettings[Xcode_BUILT_PRODUCTS_DIR],
@"DYLD_FALLBACK_FRAMEWORK_PATH" : OSXTestFrameworkDirectories(),
@"NSUnbufferedIO" : @"YES",
@"OBJC_DISABLE_GC" : !_garbageCollection ? @"YES" : @"NO",
@"XCInjectBundle" : [_buildSettings[Xcode_BUILT_PRODUCTS_DIR] stringByAppendingPathComponent:_buildSettings[Xcode_FULL_PRODUCT_NAME]],
@"XCInjectBundleInto" : testHostPath,
}]];
[task setEnvironment:[self otestEnvironmentWithOverrides:environment]];
// For OSX test bundles only, Xcode will chdir to the project's directory.
NSString *projectDir = _buildSettings[Xcode_PROJECT_DIR];
if (projectDir) {
Expand Down
23 changes: 10 additions & 13 deletions xctool/xctool/OCUnitOSXLogicTestQueryRunner.m
Expand Up @@ -36,24 +36,21 @@ - (void)prepareToRunQuery

- (NSTask *)createTaskForQuery
{
NSString *builtProductsDir = _buildSettings[Xcode_BUILT_PRODUCTS_DIR];

NSTask *task = CreateTaskInSameProcessGroup();
[task setLaunchPath:[XCToolLibExecPath() stringByAppendingPathComponent:@"otest-query-osx"]];
[task setArguments:@[ [self bundlePath] ]];
[task setEnvironment:@{
// Specifying `NSArgumentDomain` forces XCTest/SenTestingKit frameworks to use values
// of otest-query-osx `NSUserDefaults` which are changed in otest-query to manipulate
// mentioned frameworks behaviour.
NSMutableDictionary *environment = OSXTestEnvironment(_buildSettings);
[environment addEntriesFromDictionary:@{
// Specifying `NSArgumentDomain` forces XCTest/SenTestingKit frameworks to use values
// of otest-query-osx `NSUserDefaults` which are changed in otest-query to manipulate
// mentioned frameworks behaviour.
@"NSArgumentDomain" : @"otest-query-osx",
@"DYLD_FRAMEWORK_PATH" : builtProductsDir,
@"DYLD_LIBRARY_PATH" : builtProductsDir,
@"DYLD_FALLBACK_FRAMEWORK_PATH" : OSXTestFrameworkDirectories(),
@"NSUnbufferedIO" : @"YES",
@"OBJC_DISABLE_GC" : @"YES",
@"__CFPREFERENCES_AVOID_DAEMON" : @"YES",
}];

NSTask *task = CreateTaskInSameProcessGroup();
[task setLaunchPath:[XCToolLibExecPath() stringByAppendingPathComponent:@"otest-query-osx"]];
[task setArguments:@[ [self bundlePath] ]];
[task setEnvironment:environment];

return task;
}

Expand Down
11 changes: 5 additions & 6 deletions xctool/xctool/OCUnitOSXLogicTestRunner.m
Expand Up @@ -26,12 +26,11 @@ @implementation OCUnitOSXLogicTestRunner

- (NSDictionary *)environmentOverrides
{
return @{@"DYLD_FRAMEWORK_PATH" : _buildSettings[Xcode_BUILT_PRODUCTS_DIR],
@"DYLD_LIBRARY_PATH" : _buildSettings[Xcode_BUILT_PRODUCTS_DIR],
@"DYLD_FALLBACK_FRAMEWORK_PATH" : OSXTestFrameworkDirectories(),
@"NSUnbufferedIO" : @"YES",
@"OBJC_DISABLE_GC" : !_garbageCollection ? @"YES" : @"NO",
};
NSMutableDictionary *environment = OSXTestEnvironment(_buildSettings);
[environment addEntriesFromDictionary:@{
@"OBJC_DISABLE_GC" : !_garbageCollection ? @"YES" : @"NO",
}];
return environment;
}

- (NSTask *)otestTaskWithTestBundle:(NSString *)testBundlePath
Expand Down
12 changes: 6 additions & 6 deletions xctool/xctool/SimulatorWrapper/SimulatorInfo.m
Expand Up @@ -97,18 +97,18 @@ - (NSDictionary *)simulatorLaunchEnvironment
NSString *ideBundleInjectionLibPath = @"/../../Library/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection";
NSString *testBundlePath = [NSString stringWithFormat:@"%@/%@", _buildSettings[Xcode_BUILT_PRODUCTS_DIR], _buildSettings[Xcode_FULL_PRODUCT_NAME]];

return @{
@"DYLD_FALLBACK_FRAMEWORK_PATH" : IOSTestFrameworkDirectories(),
@"DYLD_FRAMEWORK_PATH" : _buildSettings[Xcode_TARGET_BUILD_DIR] ?: @"",
@"DYLD_LIBRARY_PATH" : _buildSettings[Xcode_TARGET_BUILD_DIR] ?: @"",
NSMutableDictionary *environment = IOSTestEnvironment(_buildSettings);
[environment addEntriesFromDictionary:@{
@"DYLD_INSERT_LIBRARIES" : [@[
[XCToolLibPath() stringByAppendingPathComponent:@"otest-shim-ios.dylib"],
ideBundleInjectionLibPath,
] componentsJoinedByString:@":"],
] componentsJoinedByString:@":"],
@"NSUnbufferedIO" : @"YES",
@"XCInjectBundle" : testBundlePath,
@"XCInjectBundleInto" : testHostPath,
};
}];

return environment;
}

#pragma mark -
Expand Down
10 changes: 10 additions & 0 deletions xctool/xctool/XCToolUtil.h
Expand Up @@ -201,6 +201,16 @@ NSString *IOSTestFrameworkDirectories();
*/
NSString *OSXTestFrameworkDirectories();

/**
* Returns common environment required to query and run iOS tests.
*/
NSMutableDictionary *IOSTestEnvironment(NSDictionary *buildSettings);

/**
* Returns common environment required to query and run OS X tests.
*/
NSMutableDictionary *OSXTestEnvironment(NSDictionary *buildSettings);

/**
* Creates a temporary directory under NSTemporaryDirectory() using mkdtemp,
* and returns the path.
Expand Down
20 changes: 20 additions & 0 deletions xctool/xctool/XCToolUtil.m
Expand Up @@ -27,6 +27,7 @@
#import "ReporterEvents.h"
#import "ReporterTask.h"
#import "TaskUtil.h"
#import "XcodeBuildSettings.h"
#import "XcodeSubjectInfo.h"

static NSString *__tempDirectoryForAction = nil;
Expand Down Expand Up @@ -708,6 +709,25 @@ void PublishEventToReporters(NSArray *reporters, NSDictionary *event)
return directories;
}

NSMutableDictionary *IOSTestEnvironment(NSDictionary *buildSettings)
{
return [@{
@"DYLD_FRAMEWORK_PATH" : buildSettings[Xcode_BUILT_PRODUCTS_DIR] ?: @"",
@"DYLD_LIBRARY_PATH" : buildSettings[Xcode_BUILT_PRODUCTS_DIR] ?: @"",
@"DYLD_FALLBACK_FRAMEWORK_PATH" : IOSTestFrameworkDirectories(),
} mutableCopy];
}

NSMutableDictionary *OSXTestEnvironment(NSDictionary *buildSettings)
{
return [@{
@"DYLD_FRAMEWORK_PATH" : buildSettings[Xcode_BUILT_PRODUCTS_DIR] ?: @"",
@"DYLD_LIBRARY_PATH" : buildSettings[Xcode_BUILT_PRODUCTS_DIR] ?: @"",
@"DYLD_FALLBACK_FRAMEWORK_PATH" : OSXTestFrameworkDirectories(),
@"NSUnbufferedIO" : @"YES",
} mutableCopy];
}

NSString *XcodebuildVersion()
{
static NSString *DTXcode;
Expand Down

0 comments on commit 5244f8c

Please sign in to comment.