-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·88 lines (73 loc) · 2.37 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env zsh
set -e
set -u
# By default we test with code coverage and display details (lines missed)
should_build=false
export_code_cov=false
testonly=false # if true, no code coverage will happen
summary=false # if true, code coverage will only show summary, no details
code_cov_report_file_path=""
for arg in "$@"
do
case $arg in
--build)
should_build=true
shift # Remove --build from processing
;;
--codecov)
export_code_cov=true
code_cov_report_file_path="$2"
shift # Remove --codecov from processing
;;
--testonly)
testonly=true
shift # Remove --testonly from processing
;;
--summary)
summary=true
shift # Remove --summary from processing
;;
*)
shift # Ignore other argument from processing
;;
esac
done
me=$(basename "$0")
REL_DIR=$0:P
DIR="$( cd "$( dirname "$REL_DIR" )" && pwd )";
cd "$DIR"
cd "../../" # go to parent of parent, which is project root.
echo "✨ Start of '$me' (see: '$DIR/$me')"
echo "✨ PWD: $PWD"
echo "✨ Ensure 'useLocalFramework' is set to 'true' in Package.swift"
sh ./scripts/ios/ensure-is-local.sh || exit $?
if $should_build; then
echo "✨ Building Sargon..."
sh ./scripts/ios/build-sargon.sh --maconly || exit $?
echo "✨ Sargon built"
else
echo "🙅♀️ Skip building, test (and coverage?) only"
fi
echo "✨ Calling 'swift test'"
if $testonly; then
swift test
exit 0;
fi
swift test --enable-code-coverage
BIN_PATH="$(swift build --show-bin-path)"
XCTEST_PATH="$(find ${BIN_PATH} -name '*.xctest')"
COV_BUILD_FOLDER=$XCTEST_PATH
if [[ "$OSTYPE" == "darwin"* ]]; then
f="$(basename $XCTEST_PATH .xctest)"
COV_BUILD_FOLDER="${COV_BUILD_FOLDER}/Contents/MacOS/$f"
fi
COV_DATA_PATH=".build/debug/codecov/default.profdata"
COV_ARGS="$COV_BUILD_FOLDER -instr-profile=\"$COV_DATA_PATH\" -ignore-filename-regex=\".build|Tests|UniFFI/Sargon.swift\""
NON_EXPORT_COV_ARGS="$COV_ARGS -region-coverage-lt=99 -use-color"
if $summary; then
eval "xcrun llvm-cov report $NON_EXPORT_COV_ARGS"
elif $export_code_cov; then
eval "xcrun llvm-cov export -format="lcov" $COV_ARGS > $code_cov_report_file_path"
elif [[ "$testonly" = false ]]; then # details
eval "xcrun llvm-cov show $NON_EXPORT_COV_ARGS"
fi