run_tests.sh 3.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/bin/bash
#
# Helper to run the pods tests.

set -eu

readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")

printUsage() {
  NAME=$(basename "${0}")
  cat << EOF
usage: ${NAME} [OPTIONS]

This script runs some test to check the CocoaPods integration.

OPTIONS:

 General:

   -h, --help
         Show this message
   --skip-static
         Skip the static based pods tests.
   --skip-framework
         Skip the framework based pods tests.
   --skip-ios
         Skip the iOS pods tests.
   --skip-osx
         Skip the OS X pods tests.

EOF
}

34
TEST_MODES=( "static" "framework" )
35 36 37 38 39 40 41 42
TEST_NAMES=( "iOSCocoaPodsTester" "OSXCocoaPodsTester" )
while [[ $# != 0 ]]; do
  case "${1}" in
    -h | --help )
      printUsage
      exit 0
      ;;
    --skip-static )
43
      TEST_MODES=(${TEST_MODES[@]/static})
44 45
      ;;
    --skip-framework )
46
      TEST_MODES=(${TEST_MODES[@]/framework})
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
      ;;
    --skip-ios )
      TEST_NAMES=(${TEST_NAMES[@]/iOSCocoaPodsTester})
      ;;
    --skip-osx )
      TEST_NAMES=(${TEST_NAMES[@]/OSXCocoaPodsTester})
      ;;
    -*)
      echo "ERROR: Unknown option: ${1}" 1>&2
      printUsage
      exit 1
      ;;
    *)
      echo "ERROR: Unknown argument: ${1}" 1>&2
      printUsage
      exit 1
      ;;
  esac
  shift
done

# Sanity check.
if [[ "${#TEST_NAMES[@]}" == 0 ]] ; then
  echo "ERROR: Need to run at least iOS or OS X tests." 1>&2
  exit 2
fi
if [[ "${#TEST_MODES[@]}" == 0 ]] ; then
  echo "ERROR: Need to run at least static or frameworks tests." 1>&2
  exit 2
fi

header() {
  echo ""
  echo "========================================================================"
  echo "    ${@}"
  echo "========================================================================"
  echo ""
}

# Cleanup hook for do_test, assumes directory is correct.
cleanup() {
  local TEST_NAME="$1"

  echo "Cleaning up..."

  # Generally don't let things fail, and eat common stdout, but let stderr show
  # incase something does hiccup.
  xcodebuild -workspace "${TEST_NAME}.xcworkspace" -scheme "${TEST_NAME}" clean > /dev/null || true
  pod deintegrate > /dev/null || true
96 97 98
  # Flush the cache so nothing is left behind.
  pod cache clean --all || true
  # Delete the files left after pod deintegrate.
99 100 101
  rm -f Podfile.lock || true
  rm -rf "${TEST_NAME}.xcworkspace" || true
  git checkout -- "${TEST_NAME}.xcodeproj" || true
102 103
  # Remove the Podfile that was put in place.
  rm -f Podfile || true
104 105 106 107
}

do_test() {
  local TEST_NAME="$1"
108
  local TEST_MODE="$2"
109

110
  header "${TEST_NAME}" - Mode: "${TEST_MODE}"
111 112 113 114 115
  cd "${ScriptDir}/${TEST_NAME}"

  # Hook in cleanup for any failures.
  trap "cleanup ${TEST_NAME}" EXIT

116 117 118 119 120 121
  # Ensure nothing is cached by pods to start with that could throw things off.
  pod cache clean --all

  # Put the right Podfile in place.
  cp -f "Podfile-${TEST_MODE}" "Podfile"

122 123 124 125 126
  xcodebuild_args=( "-workspace" "${TEST_NAME}.xcworkspace" "-scheme" "${TEST_NAME}" )

  # For iOS, if the SDK is not provided it tries to use iphoneos, and the test
  # fail on Travis since those machines don't have a Code Signing identity.
  if  [[ "${TEST_NAME}" == iOS* ]] ; then
127 128 129 130 131 132
    # Apparently the destination flag is required to avoid "Unsupported architecture"
    # errors.
    xcodebuild_args+=(
        -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
        -destination "platform=iOS Simulator,name=iPad 2,OS=9.3"
    )
133 134
  fi

135 136
  # Do the work!
  pod install --verbose
137 138

  xcodebuild "${xcodebuild_args[@]}" build
139 140 141 142 143 144 145 146 147 148 149 150

  # Clear the hook and manually run cleanup.
  trap - EXIT
  cleanup "${TEST_NAME}"
}

# Run the tests.
for TEST_NAME in "${TEST_NAMES[@]}" ; do
  for TEST_MODE in "${TEST_MODES[@]}" ; do
    do_test "${TEST_NAME}" "${TEST_MODE}"
  done
done