run-unittest.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash -p
  2. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. set -eu
  6. # Environment sanitization. Set a known-safe PATH. Clear environment variables
  7. # that might impact the interpreter's operation. The |bash -p| invocation
  8. # on the #! line takes the bite out of BASH_ENV, ENV, and SHELLOPTS (among
  9. # other features), but clearing them here ensures that they won't impact any
  10. # shell scripts used as utility programs. SHELLOPTS is read-only and can't be
  11. # unset, only unexported.
  12. export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
  13. unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT
  14. export -n SHELLOPTS
  15. readonly ScriptDir=$(dirname "$(echo ${0} | sed -e "s,^\([^/]\),$(pwd)/\1,")")
  16. readonly ScriptName=$(basename "${0}")
  17. readonly ThisScript="${ScriptDir}/${ScriptName}"
  18. readonly SimExecutable="${BUILD_DIR}/ninja-iossim/${CONFIGURATION}/iossim"
  19. # Helper to print a line formatted for Xcodes build output parser.
  20. XcodeNote() {
  21. echo "${ThisScript}:${1}: note: ${2}"
  22. }
  23. # Helper to print a divider to make things stick out in a busy output window.
  24. XcodeHeader() {
  25. echo "note: _________________________________________________________________"
  26. echo "note: _________________________________________________________________"
  27. echo "note: _________________________________________________________________"
  28. XcodeNote "$1" ">>>>> $2"
  29. echo "note: _________________________________________________________________"
  30. echo "note: _________________________________________________________________"
  31. echo "note: _________________________________________________________________"
  32. }
  33. # Kills the iPhone Simulator if it is running.
  34. KillSimulator() {
  35. /usr/bin/killall "iPhone Simulator" 2> /dev/null || true
  36. }
  37. # Runs tests via the iPhone Simulator for multiple devices.
  38. RunTests() {
  39. local -r appPath="${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app"
  40. if [[ ! -x "${SimExecutable}" ]]; then
  41. echo "Unable to run tests: ${SimExecutable} was not found/executable."
  42. exit 1
  43. fi
  44. for device in 'iPhone' 'iPad'; do
  45. iosVersion="6.1"
  46. KillSimulator
  47. local command=(
  48. "${SimExecutable}" "-d${device}" "-s${iosVersion}" "${appPath}"
  49. )
  50. # Pass along any command line flags
  51. if [[ "$#" -gt 0 ]]; then
  52. command+=( "--" "${@}" )
  53. fi
  54. XcodeHeader ${LINENO} "Launching tests for ${device} (iOS ${iosVersion})"
  55. "${command[@]}"
  56. # If the command didn't exit successfully, abort.
  57. if [[ $? -ne 0 ]]; then
  58. exit $?;
  59. fi
  60. done
  61. }
  62. # Time to get to work.
  63. if [[ "${PLATFORM_NAME}" != "iphonesimulator" ]]; then
  64. XcodeNote ${LINENO} "Skipping running of unittests for device build."
  65. else
  66. if [[ "$#" -gt 0 ]]; then
  67. RunTests "${@}"
  68. else
  69. RunTests
  70. fi
  71. KillSimulator
  72. fi
  73. exit 0