Created
October 8, 2019 08:02
-
-
Save ManWithBear/57cbabc8dcd0193d156c376d2d23ff02 to your computer and use it in GitHub Desktop.
Adds -record command line argument to test run in Xcode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add -record flag to iOSUITests test run | |
# By default run all tests. If test name passed as argument, run tests only for this testcase | |
# setup destinations | |
export currentDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# Name of simulators to run tests on | |
devicesArray=( | |
"CI iPhone 7 12.0" | |
"CI iPad Air 2 12.0" | |
) | |
destination="" | |
for i in ${!devicesArray[*]} | |
do | |
destination="$destination -destination 'platform=iOS Simulator,OS=12.2,name=${devicesArray[$i]}'" | |
done | |
# build project | |
buildCommand="xcodebuild -workspace ${WORKSPACE_PATH}/WORKSPACE_NAME.xcworkspace -scheme iOSUITests build-for-testing -parallel-testing-enabled NO -derivedDataPath 'build' $destination" | |
eval $buildCommand | |
if [ $? -ne 0 ]; then | |
echo "Looks like building the project failed. Please ensure the project is buildable and stable" | |
exit 1 | |
fi | |
# add flag to xctestrun by creating swift plist parsing programm and running it over xctestrun file | |
filePath=$(find build/Build/Products -name '*.xctestrun') | |
swifty=' | |
import Cocoa | |
import Foundation | |
let file = ProcessInfo.processInfo.arguments[1] | |
guard let dict = NSDictionary(contentsOfFile: file) else { | |
fatalError("Cant read dict") | |
} | |
let argsKey = "CommandLineArguments" | |
let keys = dict.allKeys as! [String] | |
for key in keys { | |
let content = dict[key] as! NSDictionary | |
let list = (content[argsKey] as? NSArray)?.mutableCopy() as? NSMutableArray ?? NSMutableArray() | |
list.add("-record") | |
content.setValue(list, forKey: argsKey) | |
} | |
dict.write(toFile: file, atomically: true) | |
' | |
echo "$swifty" > plistUpdate.swift | |
swiftc plistUpdate.swift | |
update="./plistUpdate $filePath" | |
eval $update | |
rm plistUpdate.swift | |
rm plistUpdate | |
# run tests | |
testCommand="xcodebuild test-without-building -maximum-concurrent-test-simulator-destinations 2 -xctestrun $filePath $destination" | |
onlyTests="" | |
for var in "$@" | |
do | |
onlyTests="$onlyTests -only-testing:iOSUITests/$var" | |
done | |
testCommand="$testCommand $onlyTests" | |
eval $testCommand | |
# Play "Ping" sound when tests done | |
afplay /System/Library/Sounds/Glass.aiff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment