-
Notifications
You must be signed in to change notification settings - Fork 130
/
rust-coverage.toml
237 lines (206 loc) · 7.61 KB
/
rust-coverage.toml
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
[tasks.workspace-members-coverage]
description = "Runs the ci-flow for every workspace member."
category = "Test"
workspace = false
env = { "CARGO_MAKE_MEMBER_TASK" = "${CARGO_MAKE_CORE_TASK_NAMESPACE_PREFIX}coverage" }
run_task = "do-on-members"
[tasks.workspace-coverage]
description = "Runs coverage task for all members and packages all of them (by default the codecov flow)."
category = "Test"
dependencies = ["workspace-members-coverage", "workspace-coverage-pack"]
[tasks.workspace-coverage-pack]
description = "Publishes all member coverage reports."
category = "Test"
linux_alias = "codecov"
[tasks.pre-coverage]
category = "Test"
[tasks.coverage]
description = "Runs coverage (by default using kcov)."
category = "Test"
env = { "RUSTFLAGS" = "-C link-dead-code" }
run_task = [
{ name = "coverage-tarpaulin", condition = { platforms = [
"linux",
], env = { "CARGO_MAKE_COVERAGE_PROVIDER" = "tarpaulin" } } },
{ name = "coverage-kcov", condition = { platforms = [
"linux",
] } },
]
[tasks.coverage-kcov]
description = "Installs (if missing) and runs coverage using kcov (not supported on windows)"
category = "Test"
dependencies = ["setup-sudo-env"]
condition = { env_set = [
"CARGO_MAKE_KCOV_VERSION",
], platforms = [
"linux",
"mac",
] }
script_runner = "bash"
env = { "CARGO_MAKE_KCOV_INCLUDE_PATTERN" = "${CARGO_MAKE_WORKING_DIRECTORY}/src/" }
install_script = '''
if [ "${CARGO_MAKE_SUDO_ENABLED}" == "false" ]; then
echo "Skipping kcov installation as 'sudo' is disabled."
exit 0
fi
KCOV_INSTALLATION_DIRECTORY=""
KCOV_BINARY_DIRECTORY=""
if [ -n "${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}" ]; then
mkdir -p ${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}
cd ${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}
KCOV_INSTALLATION_DIRECTORY="$(pwd)/"
cd -
echo "Kcov Installation Directory: ${KCOV_INSTALLATION_DIRECTORY}"
KCOV_BINARY_DIRECTORY="${KCOV_INSTALLATION_DIRECTORY}/build/src/"
echo "Kcov Binary Directory: ${KCOV_BINARY_DIRECTORY}"
fi
# get help info to fetch all supported command line arguments
KCOV_HELP_INFO=`${KCOV_BINARY_DIRECTORY}kcov --help` || true
# check needed arguments are supported, else install
if [[ $KCOV_HELP_INFO != *"--include-pattern"* ]] || [[ $KCOV_HELP_INFO != *"--exclude-line"* ]] || [[ $KCOV_HELP_INFO != *"--exclude-region"* ]]; then
# check we are on a supported platform
if [ "$(uname)" == "Linux" ]; then
if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then
echo "Installing/Upgrading kcov..."
sudo apt-get update || true
sudo apt-get install -y libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc binutils-dev
fi
elif [ "$(uname)" == "Darwin" ]; then
for brew_install in zlib bash cmake pkgconfig wget ; do
if brew info ${brew_install} | grep "Not installed" ; then
brew install ${brew_install}
else
echo "skipping ${brew_install} already installed"
fi
done
fi
mkdir -p ${CARGO_MAKE_KCOV_DOWNLOAD_DIRECTORY}
cd ${CARGO_MAKE_KCOV_DOWNLOAD_DIRECTORY}
KCOV_DOWNLOAD_DIRECTORY=$(pwd)
wget https://github.com/SimonKagstrom/kcov/archive/v${CARGO_MAKE_KCOV_VERSION}.zip
unzip v${CARGO_MAKE_KCOV_VERSION}.zip
cd kcov-${CARGO_MAKE_KCOV_VERSION}
mkdir -p build
cd ./build
cmake ..
make
# if custom installation directory, leave kcov as local
if [ -n "${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}" ]; then
cd ${KCOV_DOWNLOAD_DIRECTORY}/kcov-${CARGO_MAKE_KCOV_VERSION}
mv ./* ${KCOV_INSTALLATION_DIRECTORY}
else
sudo make install
cd ../..
rm -rf kcov-${CARGO_MAKE_KCOV_VERSION}
fi
fi
'''
script = '''
echo "Working Directory: ${CARGO_MAKE_WORKING_DIRECTORY}"
KCOV_BINARY_DIRECTORY=""
if [ -n "${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}" ]; then
cd ${CARGO_MAKE_KCOV_INSTALLATION_DIRECTORY}
KCOV_INSTALLATION_DIRECTORY="$(pwd)/"
cd -
echo "Kcov Installation Directory: ${KCOV_INSTALLATION_DIRECTORY}"
KCOV_BINARY_DIRECTORY="${KCOV_INSTALLATION_DIRECTORY}/build/src/"
echo "Kcov Binary Directory: ${KCOV_BINARY_DIRECTORY}"
fi
TARGET_DIRECTORY="target/coverage"
if [ -n "$CARGO_MAKE_COVERAGE_REPORT_DIRECTORY" ]; then
TARGET_DIRECTORY="$CARGO_MAKE_COVERAGE_REPORT_DIRECTORY"
fi
echo "Target Directory: ${TARGET_DIRECTORY}"
mkdir -p "${TARGET_DIRECTORY}"
BINARY_DIRECTORY=target/debug
if [ -n "$CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY" ]; then
BINARY_DIRECTORY="${CARGO_MAKE_WORKSPACE_TARGET_DIRECTORY}/debug"
fi
BINARY_DIRECTORY=${BINARY_DIRECTORY}/deps
KCOV_EXCLUDE_LINE_ARG=""
if [ -n "$CARGO_MAKE_KCOV_EXCLUDE_LINE" ]; then
KCOV_EXCLUDE_LINE_ARG="--exclude-line=${CARGO_MAKE_KCOV_EXCLUDE_LINE}"
fi
KCOV_EXCLUDE_REGION_ARG=""
if [ -n "$CARGO_MAKE_KCOV_EXCLUDE_REGION" ]; then
KCOV_EXCLUDE_REGION_ARG="--exclude-region=${CARGO_MAKE_KCOV_EXCLUDE_REGION}"
fi
echo "Running tests from directory: ${BINARY_DIRECTORY}"
# Evaluate variables that may be in the expression
# This allows us to do double expansion on a non-variable second expansion
CARGO_MAKE_TEST_COVERAGE_BINARY_FILTER_REGEX="$(sh -c "echo \"${CARGO_MAKE_TEST_COVERAGE_BINARY_FILTER}\"")"
echo "Test binary filter regex: ${CARGO_MAKE_TEST_COVERAGE_BINARY_FILTER_REGEX}"
TEST_FILES=''
for test_file in $(find "${BINARY_DIRECTORY}" -maxdepth 1 -type f | grep -e "${CARGO_MAKE_TEST_COVERAGE_BINARY_FILTER_REGEX}"); do
keep=1
for debug_file in $(find "${BINARY_DIRECTORY}/.." -maxdepth 1 -type f); do
$(cmp -s "$debug_file" "$test_file") && keep=0 && break
done
if [ $keep -eq 1 ]; then
[ -n "$TEST_FILES" ] && TEST_FILES="$TEST_FILES $test_file" || TEST_FILES="$test_file"
fi
done
echo "Test Files:"
echo "${TEST_FILES}"
TEST_OPTIONS="--test-threads 1"
if [ "${CARGO_MAKE_TEST_USE_MULTI_TEST_PHASES}" == "true" ]; then
export RUST_TEST_THREADS="1"
if [ "${CARGO_MAKE_RUST_CHANNEL}" == "nightly" ]; then
TEST_OPTIONS="${TEST_OPTIONS} --include-ignored -Zunstable-options"
fi
fi
TEST_OPTIONS="${TEST_OPTIONS} ${CARGO_MAKE_KCOV_TEST_ARGUMENTS}"
TIMEOUT_COMMAND=""
if [ -n "${CARGO_MAKE_KCOV_TEST_TIMEOUT_VALUE}" ]; then
TIMEOUT_COMMAND="timeout ${CARGO_MAKE_KCOV_TEST_TIMEOUT_VALUE} "
fi
i=0
for file in $TEST_FILES
do
((i=i+1))
echo "Running coverage for file: $file"
${TIMEOUT_COMMAND} ${KCOV_BINARY_DIRECTORY}kcov --include-pattern=${CARGO_MAKE_KCOV_INCLUDE_PATTERN} ${KCOV_EXCLUDE_LINE_ARG} ${KCOV_EXCLUDE_REGION_ARG} "${TARGET_DIRECTORY}/${i}" "$file" ${TEST_OPTIONS} || true
done
rm -f ./core
'''
[tasks.coverage-tarpaulin]
description = "Runs coverage using tarpaulin rust crate (linux only)"
category = "Test"
[tasks.coverage-tarpaulin.linux]
command = "cargo"
args = ["tarpaulin", "--out", "Xml"]
[tasks.post-coverage]
category = "Test"
[tasks.coverage-flow]
description = "Runs the full coverage flow."
category = "Test"
dependencies = ["pre-coverage", "coverage", "post-coverage"]
[tasks.codecov]
description = "Runs codecov script to upload coverage results to codecov."
category = "Test"
condition = { env_not_set = [
"CARGO_MAKE_SKIP_CODECOV",
], platforms = [
"linux",
"mac",
] }
script_runner = "bash"
script = '''
#!/usr/bin/env bash
bash <(curl -s https://codecov.io/bash)
'''
[tasks.codecov-flow]
description = "Runs the full coverage flow and uploads the results to codecov."
category = "Test"
condition = { platforms = ["linux", "mac"] }
dependencies = ["coverage-flow", "codecov"]
[tasks.ci-coverage-flow]
description = "Runs the coverage flow and uploads the results to codecov."
category = "CI"
condition = { platforms = [
"linux",
], env_true = [
"CARGO_MAKE_CI",
"CARGO_MAKE_RUN_CODECOV",
] }
run_task = "codecov-flow"