run_tests.sh 3.6 KB

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