1#!/bin/bash 2# 3# Helper to run the pods tests. 4 5set -eu 6 7readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")") 8 9printUsage() { 10 NAME=$(basename "${0}") 11 cat << EOF 12usage: ${NAME} [OPTIONS] 13 14This script runs some test to check the CocoaPods integration. 15 16OPTIONS: 17 18 General: 19 20 -h, --help 21 Show this message 22 --skip-static 23 Skip the static based pods tests. 24 --skip-framework 25 Skip the framework based pods tests. 26 --skip-ios 27 Skip the iOS pods tests. 28 --skip-osx 29 Skip the OS X pods tests. 30 31EOF 32} 33 34TEST_MODES=( "static" "framework" ) 35TEST_NAMES=( "iOSCocoaPodsTester" "OSXCocoaPodsTester" ) 36while [[ $# != 0 ]]; do 37 case "${1}" in 38 -h | --help ) 39 printUsage 40 exit 0 41 ;; 42 --skip-static ) 43 TEST_MODES=(${TEST_MODES[@]/static}) 44 ;; 45 --skip-framework ) 46 TEST_MODES=(${TEST_MODES[@]/framework}) 47 ;; 48 --skip-ios ) 49 TEST_NAMES=(${TEST_NAMES[@]/iOSCocoaPodsTester}) 50 ;; 51 --skip-osx ) 52 TEST_NAMES=(${TEST_NAMES[@]/OSXCocoaPodsTester}) 53 ;; 54 -*) 55 echo "ERROR: Unknown option: ${1}" 1>&2 56 printUsage 57 exit 1 58 ;; 59 *) 60 echo "ERROR: Unknown argument: ${1}" 1>&2 61 printUsage 62 exit 1 63 ;; 64 esac 65 shift 66done 67 68# Sanity check. 69if [[ "${#TEST_NAMES[@]}" == 0 ]] ; then 70 echo "ERROR: Need to run at least iOS or OS X tests." 1>&2 71 exit 2 72fi 73if [[ "${#TEST_MODES[@]}" == 0 ]] ; then 74 echo "ERROR: Need to run at least static or frameworks tests." 1>&2 75 exit 2 76fi 77 78header() { 79 echo "" 80 echo "========================================================================" 81 echo " ${@}" 82 echo "========================================================================" 83 echo "" 84} 85 86# Cleanup hook for do_test, assumes directory is correct. 87cleanup() { 88 local TEST_NAME="$1" 89 90 echo "Cleaning up..." 91 92 # Generally don't let things fail, and eat common stdout, but let stderr show 93 # incase something does hiccup. 94 xcodebuild -workspace "${TEST_NAME}.xcworkspace" -scheme "${TEST_NAME}" clean > /dev/null || true 95 pod deintegrate > /dev/null || true 96 # Flush the cache so nothing is left behind. 97 pod cache clean --all || true 98 # Delete the files left after pod deintegrate. 99 rm -f Podfile.lock || true 100 rm -rf "${TEST_NAME}.xcworkspace" || true 101 git checkout -- "${TEST_NAME}.xcodeproj" || true 102 # Remove the Podfile that was put in place. 103 rm -f Podfile || true 104} 105 106do_test() { 107 local TEST_NAME="$1" 108 local TEST_MODE="$2" 109 110 header "${TEST_NAME}" - Mode: "${TEST_MODE}" 111 cd "${ScriptDir}/${TEST_NAME}" 112 113 # Hook in cleanup for any failures. 114 trap "cleanup ${TEST_NAME}" EXIT 115 116 # Ensure nothing is cached by pods to start with that could throw things off. 117 pod cache clean --all 118 119 # Put the right Podfile in place. 120 cp -f "Podfile-${TEST_MODE}" "Podfile" 121 122 xcodebuild_args=( "-workspace" "${TEST_NAME}.xcworkspace" "-scheme" "${TEST_NAME}" ) 123 124 # For iOS, if the SDK is not provided it tries to use iphoneos, and the test 125 # fail on Travis since those machines don't have a Code Signing identity. 126 if [[ "${TEST_NAME}" == iOS* ]] ; then 127 # Apparently the destination flag is required to avoid "Unsupported architecture" 128 # errors. 129 xcodebuild_args+=( 130 -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO 131 -destination "platform=iOS Simulator,name=iPad 2,OS=9.3" 132 ) 133 fi 134 135 # Do the work! 136 pod install --verbose 137 138 xcodebuild "${xcodebuild_args[@]}" build 139 140 # Clear the hook and manually run cleanup. 141 trap - EXIT 142 cleanup "${TEST_NAME}" 143} 144 145# Run the tests. 146for TEST_NAME in "${TEST_NAMES[@]}" ; do 147 for TEST_MODE in "${TEST_MODES[@]}" ; do 148 do_test "${TEST_NAME}" "${TEST_MODE}" 149 done 150done 151