mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-01-09 07:11:20 +08:00
* Snapshot Testing Proof of Concept (#5754) ### The problem We currently do not have UI tests on a component level. Integrating snapshot tests would allow us to have peace of mind with each PR that it isn't going to introduce any changes to the UI unless its intended to. ### The solution * Integrate `ios-snapshot-test-case` pod to handle generating and diffing images of components. * Integrate `git-lfs` to handle storage of the goldens. This PR creates one test to showcase the ability to do snapshot tests. Upon merging this PR, you must install git-lfs in order to properly have the images pulled down. The 3 steps to do this: 1. `brew install git-lfs` 2. `git lfs install` 3. `git lfs pull` Additionally, the golden is generated using an iOS 11 simulator at 2x scale so that the kokoro jobs are happy. ### Related bugs Closes #5740 ### Difference from #5754 **Note:** This is a re-revert of #5754 that aims to fix issues with Travis CI by ensuring the snapshot test only runs on a single iOS version. I've opened #5888 to expand on this in the future. A few things changed in the approach in this PR: * We only run the snapshot test for iOS 11.2.0 until we can have an elegant solution for supporting multiple OS''s (see #5888) * The snapshot tests now live in their own test target to avoid issues with having to require an App host for all tests. * Additionally, a dummy swift file was required for compilation of this new test target (see https://forums.developer.apple.com/thread/88451 for context)
60 lines
1.9 KiB
Bash
Executable File
60 lines
1.9 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 "MDCCatalog"
|
|
if [ $? -ne 0 ]; then
|
|
did_any_fail=true
|
|
fi
|
|
|
|
if $did_any_fail; then
|
|
exit 1
|
|
fi |