mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
## Prior to this change Our test_all script was using an Xcode schemes search and filter to identify any test schemes that exist in the repository and test them. Unfortunately, the script was not also testing to confirm that it found at least *some* tests, meaning if it did not find any tests it would silently succeed. The script was essentially optimized for us adding multiple test schemes in the future. In practice, the frequency with which we add new test schemes is low (we've added only one in the past year via MaterialComponentsAlpha). ## The root cause With d238c86d47eb072617d285106147ace613321aee, our Xcode test scheme names changed and our scheme search was no longer returning our unit test schemes, resulting in test_all succeeding even though it hadn't run any tests. ## After this change The test_all script will explicitly test specific schemes. If these schemes change or move in the future, this script will fail until we also update the script's schemes. This script now also pipes the test output through xcpretty if it is available. Closes https://github.com/material-components/material-components-ios/issues/5539
67 lines
2.0 KiB
Bash
Executable File
67 lines
2.0 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)"
|
|
readonly COVERAGE_OPTIONS="GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES -enableCodeCoverage YES"
|
|
|
|
# When run on Travis CI, this variable should be passed in
|
|
if [[ ! $DESTINATION ]]; then
|
|
DESTINATION="platform=iOS Simulator,name=iPhone 7,OS=latest"
|
|
fi
|
|
|
|
# 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
|
|
}
|
|
|
|
xcodebuid_test() {
|
|
if hash xcpretty 2>/dev/null; then
|
|
set -o pipefail # Required for xcpretty to propagate failure.
|
|
xcodebuild test "${@:1}" "$COVERAGE_OPTIONS" -destination "$DESTINATION" | xcpretty
|
|
else
|
|
xcodebuild test "${@:1}" "$COVERAGE_OPTIONS" -destination "$DESTINATION"
|
|
fi
|
|
}
|
|
|
|
if [ ! -d "$ROOT_DIR/catalog/MDCCatalog.xcworkspace" ]; then
|
|
pod install --project-directory="$ROOT_DIR/catalog"
|
|
fi
|
|
|
|
did_any_fail=false
|
|
|
|
xcodebuid_test \
|
|
-workspace "$ROOT_DIR/catalog/MDCCatalog.xcworkspace" \
|
|
-scheme "MaterialComponents-Unit-Tests"
|
|
if [ $? -ne 0 ]; then
|
|
did_any_fail=true
|
|
fi
|
|
|
|
xcodebuid_test \
|
|
-workspace "$ROOT_DIR/catalog/MDCCatalog.xcworkspace" \
|
|
-scheme "MaterialComponentsAlpha-Unit-Tests"
|
|
if [ $? -ne 0 ]; then
|
|
did_any_fail=true
|
|
fi
|
|
|
|
if $did_any_fail; then
|
|
exit 1
|
|
fi |