blob: bafb95d4ded0e45e8b8f13494ac20facfbffceef [file] [log] [blame]
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +00001#!/bin/bash
2
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00003# Copyright 2015 The Bazel Authors. All rights reserved.
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +00004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -eu
18
Peter Schmitte47a5a92016-08-10 15:14:54 +000019TEMP_DIR="$(mktemp -d ${TMPDIR:-/tmp}/test_temp_dir.XXXXXX)"
20trap 'rm -rf "${TEMP_DIR}"' ERR EXIT
21
22TEST_APP_DIR="${TEMP_DIR}/test_app_dir"
23mkdir "${TEST_APP_DIR}"
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000024unzip -qq -d "${TEST_APP_DIR}" "%(test_app_ipa)s"
25TEST_APP_DIR="${TEST_APP_DIR}/Payload/%(test_app_name)s.app"
26
Peter Schmitte47a5a92016-08-10 15:14:54 +000027XCTEST_APP_DIR="${TEMP_DIR}/xctest_app_dir"
28mkdir "${XCTEST_APP_DIR}"
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000029unzip -qq -d "${XCTEST_APP_DIR}" "%(xctest_app_ipa)s"
Dave MacLachlana09fb732016-02-03 21:24:45 +000030XCTEST_APP_DIR="${XCTEST_APP_DIR}/Payload/%(xctest_app_name)s.xctest"
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000031
32killall "iOS Simulator" >/dev/null 2>/dev/null || :
33
Peter Schmitte47a5a92016-08-10 15:14:54 +000034SIMHOME="${TEMP_DIR}/simhome"
35mkdir "${SIMHOME}"
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000036
Peter Schmitte47a5a92016-08-10 15:14:54 +000037LOGFILE="${TEMP_DIR}/logfile"
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000038
Dave MacLachlan61532432015-11-04 23:02:02 +000039SIMULATOR_PLATFORM="$(/usr/bin/xcrun --sdk iphonesimulator --show-sdk-platform-path)"
40SIMULATOR_DEV_LIBRARY="$SIMULATOR_PLATFORM/Developer/Library"
41
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000042"%(iossim_path)s" \
43 -u "${SIMHOME}" \
44 -d "%(device_type)s" \
45 -s "%(simulator_sdk)s" \
46 -t 60 \
Dave MacLachlan61532432015-11-04 23:02:02 +000047 -e DYLD_INSERT_LIBRARIES="$SIMULATOR_DEV_LIBRARY/PrivateFrameworks/IDEBundleInjection.framework/IDEBundleInjection" \
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000048 -e "XCInjectBundle=${TEST_APP_DIR}" \
49 -e "XCInjectBundleInto=${XCTEST_APP_DIR}" \
Dave MacLachlan61532432015-11-04 23:02:02 +000050 -e DYLD_FALLBACK_FRAMEWORK_PATH="$SIMULATOR_DEV_LIBRARY/Frameworks" \
Daniel Wagner-Hall1f4ce802015-05-04 15:07:29 +000051 "${XCTEST_APP_DIR}" \
52 -NSTreatUnknownArgumentsAsOpen NO \
53 -ApplePersistenceIgnoreState YES \
54 -XCTest All \
55 "${TEST_APP_DIR}" \
56 2>&1 | tee "${LOGFILE}"
57
58killall "iOS Simulator" >/dev/null 2>/dev/null || :
59
60# TODO(danielwh): Much better support for detecting failures. Actually parse the log.
61if grep -q "with [1-9].* failure" "${LOGFILE}"; then
62 exit 1
63fi