67 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright 2016-present the Material Components for iOS authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
readonly SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly ROOT_DIR="$(dirname $SCRIPTS_DIR)"
# Note that the following is using 10.1 until Travis CI fixes
# https://github.com/travis-ci/travis-ci/issues/7031
readonly DESTINATION="platform=iOS Simulator,name=iPhone 7,OS=10.1"
readonly COVERAGE_OPTIONS="GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES -enableCodeCoverage YES"
# Given a path to an Xcode log file in $1, print a guess at what caused the
# failure.
function guess_failure() {
if [[ $TRAVIS == "true" ]]; then
tail -n 200 "$1"
else
grep --context=20 "The following build commands failed:" "$1"
fi
}
readonly WORKSPACE_SCHEMES=$("$SCRIPTS_DIR"/xcode/list_all_xcode_schemes)
all_tests_ok=1
for workspace_scheme in $WORKSPACE_SCHEMES; do
workspace=$(echo $workspace_scheme | cut -d: -f1)
scheme=$(echo $workspace_scheme | cut -d: -f2)
# Assume any scheme with the name "*Tests*" is a testing scheme.
if [[ $scheme != *Tests* ]]; then
continue
fi
echo $workspace $scheme
log_file=$(dirname "$workspace")/"test_log_for_scheme_${scheme}.txt"
options="-workspace $workspace -scheme $scheme"
if xcodebuild test $options $COVERAGE_OPTIONS -destination "$DESTINATION" >"$log_file" 2>&1; then
rm "$log_file"
else
all_tests_ok=0
echo
echo "Failed to test $scheme in $workspace."
guess_failure "$log_file"
echo "Log left in $log_file."
echo "Continuing with next test..."
echo
fi
done
# If any test failed, exit with a failure exit status so continuous integration
# tools can react appropriately.
if [ "$all_tests_ok" -eq 1 ]; then
exit 0
else
exit 1
fi