Content-Length: 599015 | pFad | http://github.com/ascii-boxes/boxes/commit/0eb8272e9b7317e2831a0de90ed444710d26f142

F6 Change testrunner.sh so that coverage is only calculated for all blac… · ascii-boxes/boxes@0eb8272 · GitHub
Skip to content

Commit 0eb8272

Browse files
committed
Change testrunner.sh so that coverage is only calculated for all black-box tests in total
Coverage per test can be displayed using the new `--coverage-per-test` option, which implies `--coverage`. This should speed up our CI workflows.
1 parent e6343dd commit 0eb8272

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed

test/testrunner.sh

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ declare -r COVERAGE_FILE=${OUT_DIR}/lcov-total.info
2525

2626
# Command Line Options
2727
declare opt_coverage=false
28+
declare opt_coverage_per_test=false
2829
declare opt_suite=false
2930
declare opt_testCase=""
3031

3132

3233
function print_usage()
3334
{
34-
echo 'Usage: testrunner.sh [--coverage] {--suite | <opt_testCase>}'
35+
echo 'Usage: testrunner.sh [--coverage] [--coverage-per-test] {--suite | <opt_testCase>}'
3536
echo ' Returns 0 for success, else non-zero'
3637
}
3738

@@ -49,6 +50,10 @@ function parse_arguments()
4950
opt_coverage=true
5051
shift
5152
;;
53+
--coverage-per-test)
54+
opt_coverage_per_test=true
55+
opt_coverage=true
56+
;;
5257
--suite)
5358
opt_suite=true
5459
shift
@@ -112,6 +117,16 @@ function cov_baseline()
112117
}
113118

114119

120+
function cov_args()
121+
{
122+
if [ ${opt_coverage_per_test} == true ]; then
123+
echo '--coverage-per-test'
124+
elif [ ${opt_coverage} == true ]; then
125+
echo '--coverage'
126+
fi
127+
}
128+
129+
115130
function execute_suite()
116131
{
117132
local countExecuted=0
@@ -122,18 +137,10 @@ function execute_suite()
122137
# unique and runs under ISO_8859-15. But this only happens on macOS.
123138
# So, if we run test 111 on macOS, we should run with LC_ALL=C
124139
for tc in *.txt; do
125-
if [ ${opt_coverage} == true ]; then
126-
if [[ $(uname) == "Darwin" ]] && [[ ${tc} == "111"* ]]; then
127-
LC_ALL=C $0 --coverage "${tc}"
128-
else
129-
$0 --coverage "${tc}"
130-
fi
140+
if [[ $(uname) == "Darwin" ]] && [[ ${tc} == "111"* ]]; then
141+
LC_ALL=C $0 "$(cov_args)" "${tc}"
131142
else
132-
if [[ $(uname) == "Darwin" ]] && [[ ${tc} == "111"* ]]; then
133-
LC_ALL=C $0 "${tc}"
134-
else
135-
$0 "${tc}"
136-
fi
143+
$0 "$(cov_args)" "${tc}"
137144
fi
138145
if [ $? -ne 0 ]; then
139146
overallResult=1
@@ -147,8 +154,8 @@ function execute_suite()
147154

148155
function measure_coverage()
149156
{
150-
local testResultsDir=${OUT_DIR}/test-results/${tcBaseName}
151157
if [ ${opt_coverage} == true ]; then
158+
local testResultsDir=${OUT_DIR}/test-results/${tcBaseName}
152159
mkdir -p "${testResultsDir}"
153160
cp ${OUT_DIR}/*.gc* "${testResultsDir}"
154161
lcov --capture --directory "${testResultsDir}" --base-directory ${SRC_DIR} --test-name "${tcBaseName}" --quiet \
@@ -162,13 +169,15 @@ function measure_coverage()
162169

163170
function consolidate_coverage()
164171
{
165-
echo -e "\nConsolidating test coverage ..."
166-
pushd ${OUT_DIR}/test-results || exit 1
167-
find . -name "*.info" | xargs printf -- '--add-tracefile %s\n' | xargs --exit \
168-
lcov --rc "${branchCoverage}=1" --exclude '*/lex.yy.c' --exclude '*/parser.c' \
169-
--output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE}
170-
popd || exit 1
171-
echo ""
172+
if [[ ${opt_coverage} == true ]]; then
173+
echo -e "\nConsolidating test coverage ..."
174+
pushd ${OUT_DIR}/test-results || exit 1
175+
find . -name "*.info" | xargs printf -- '--add-tracefile %s\n' | xargs --exit \
176+
lcov --rc "${branchCoverage}=1" --exclude '*/lex.yy.c' --exclude '*/parser.c' \
177+
--output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE}
178+
popd || exit 1
179+
echo ""
180+
fi
172181
}
173182

174183

@@ -205,8 +214,8 @@ function check_mandatory_sections()
205214
function arrange_environment()
206215
{
207216
local boxesEnv=""
208-
if [ $(grep -c "^:ENV" ${opt_testCase}) -eq 1 ]; then
209-
boxesEnv=$(cat ${opt_testCase} | sed -n '/^:ENV/,/^:ARGS/p;' | sed '1d;$d' | tr -d '\r')
217+
if [[ $(grep -c "^:ENV" "${opt_testCase}") -eq 1 ]]; then
218+
boxesEnv=$(sed -n '/^:ENV/,/^:ARGS/p;' < "${opt_testCase}" | sed '1d;$d' | tr -d '\r')
210219
fi
211220
if [ -n "$boxesEnv" ]; then
212221
echo "$boxesEnv" | sed -e 's/export/\n export/g' | sed '1d'
@@ -221,12 +230,12 @@ function arrange_environment()
221230
function arrange_test_fixtures()
222231
{
223232
if [ $(grep -c "^:EXPECTED-ERROR " ${opt_testCase}) -eq 1 ]; then
224-
expectedReturnCode=$(grep "^:EXPECTED-ERROR " ${opt_testCase} | sed -e 's/:EXPECTED-ERROR //')
233+
expectedReturnCode=$(grep "^:EXPECTED-ERROR " "${opt_testCase}" | sed -e 's/:EXPECTED-ERROR //')
225234
fi
226235

227-
cat ${opt_testCase} | sed -n '/^:INPUT/,/^:OUTPUT-FILTER/p;' | sed '1d;$d' | tr -d '\r' > "${testInputFile}"
228-
cat ${opt_testCase} | sed -n '/^:OUTPUT-FILTER/,/^:EXPECTED\b.*$/p;' | sed '1d;$d' | tr -d '\r' > "${testFilterFile}"
229-
cat ${opt_testCase} | sed -n '/^:EXPECTED/,/^:EOF/p;' | sed '1d;$d' | tr -d '\r' > "${testExpectationFile}"
236+
cat "${opt_testCase}" | sed -n '/^:INPUT/,/^:OUTPUT-FILTER/p;' | sed '1d;$d' | tr -d '\r' > "${testInputFile}"
237+
cat "${opt_testCase}" | sed -n '/^:OUTPUT-FILTER/,/^:EXPECTED\b.*$/p;' | sed '1d;$d' | tr -d '\r' > "${testFilterFile}"
238+
cat "${opt_testCase}" | sed -n '/^:EXPECTED/,/^:EOF/p;' | sed '1d;$d' | tr -d '\r' > "${testExpectationFile}"
230239
}
231240

232241

@@ -266,6 +275,7 @@ parse_arguments "$@"
266275
check_prereqs
267276
cov_baseline
268277

278+
declare tcBaseName=${opt_testCase%.txt}
269279
declare branchCoverage=lcov_branch_coverage
270280
if [[ $(uname) == "Darwin" ]]; then
271281
branchCoverage=branch_coverage
@@ -274,8 +284,13 @@ fi
274284
# Execute the entire test suite
275285
if [ ${opt_suite} == true ]; then
276286
declare -i overallResult=0
287+
clear_gcda_traces
277288
execute_suite
278289

290+
if [ ${opt_coverage_per_test} == false ]; then
291+
tcBaseName=black-box-all
292+
measure_coverage
293+
fi
279294
if [ ${opt_coverage} == true ]; then
280295
consolidate_coverage
281296
report_coverage
@@ -285,8 +300,9 @@ fi
285300

286301
# Execute only a single test
287302
echo "Running test case: ${opt_testCase}"
288-
declare -r tcBaseName=${opt_testCase%.txt}
289-
clear_gcda_traces
303+
if [ ${opt_coverage_per_test} == true ]; then
304+
clear_gcda_traces
305+
fi
290306

291307
check_mandatory_sections
292308

@@ -295,21 +311,23 @@ declare -r testInputFile=${opt_testCase/%.txt/.input.tmp}
295311
declare -r testExpectationFile=${opt_testCase/%.txt/.expected.tmp}
296312
declare -r testFilterFile=${opt_testCase/%.txt/.sed.tmp}
297313
declare -r testOutputFile=${opt_testCase/%.txt/.out.tmp}
298-
declare -r boxesArgs=$(cat ${opt_testCase} | sed -n '/^:ARGS/,+1p' | grep -v ^:INPUT | sed '1d' | tr -d '\r')
314+
declare -r boxesArgs=$(sed -n '/^:ARGS/,+1p' < "${opt_testCase}" | grep -v ^:INPUT | sed '1d' | tr -d '\r')
299315

300316
arrange_environment
301317
arrange_test_fixtures
302318

303319
declare -i actualReturnCode=100
304320
run_boxes
305-
measure_coverage
306321

322+
if [ ${opt_coverage_per_test} == true ]; then
323+
measure_coverage
324+
fi
307325
assert_outcome
308326

309-
rm ${testInputFile}
310-
rm ${testFilterFile}
311-
rm ${testExpectationFile}
312-
rm ${testOutputFile}
327+
rm "${testInputFile}"
328+
rm "${testFilterFile}"
329+
rm "${testExpectationFile}"
330+
rm "${testOutputFile}"
313331

314332
echo " OK"
315333
exit 0

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/ascii-boxes/boxes/commit/0eb8272e9b7317e2831a0de90ed444710d26f142

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy