Skip to content

Commit e17b781

Browse files
committed
Fix coverage measurement on macos-26
1 parent 739f85f commit e17b781

5 files changed

Lines changed: 46 additions & 24 deletions

File tree

src/generate.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,11 @@ int output_box(const sentry_t *thebox)
10871087
}
10881088

10891089
bxstr_t *obuf_trimmed = bxs_rtrim(obuf);
1090-
fprintf(opt.outfile, "%s%s", bxs_to_output(obuf_trimmed),
1091-
(input.final_newline || j < nol - skip_end - 1 ? opt.eol : ""));
1090+
const char *line_end = "";
1091+
if (input.final_newline || j < nol - skip_end - 1) {
1092+
line_end = opt.eol;
1093+
}
1094+
fprintf(opt.outfile, "%s%s", bxs_to_output(obuf_trimmed), line_end);
10921095

10931096
bxs_free(obuf);
10941097
bxs_free(obuf_trimmed);

src/remove.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,15 @@ int hmm(shape_line_ctx_t *shapes_relevant, uint32_t *cur_pos, size_t shape_idx,
331331
}
332332
else if (cur_pos == end_pos) {
333333
/* we are at the end, which is fine if there is nothing else to match */
334-
result = (shape_idx == (SHAPES_PER_SIDE - 1) && anchored_right)
335-
|| ((shapes_relevant[shape_idx].empty || bxs_is_blank(shapes_relevant[shape_idx].text))
336-
&& !non_empty_shapes_after(shapes_relevant, shape_idx) ? 1 : 0);
334+
if (shape_idx == (SHAPES_PER_SIDE - 1) && anchored_right) {
335+
result = 1;
336+
}
337+
else if (shapes_relevant[shape_idx].empty || bxs_is_blank(shapes_relevant[shape_idx].text)) {
338+
result = !non_empty_shapes_after(shapes_relevant, shape_idx);
339+
}
340+
else {
341+
result = 0;
342+
}
337343
}
338344
else if (shape_idx >= SHAPES_PER_SIDE - 1) {
339345
/* no more shapes to try, which is fine if the rest of the line is blank */

test/test-sunny-days-all.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ declare opt_coverage=false
3434
declare branchCoverage=lcov_branch_coverage
3535
declare -a lcovArgs=(--ignore-errors unused)
3636
declare -a lcovCaptureArgs=()
37+
declare -ar lcovCaptureRcArgs=(--rc geninfo_unexecuted_blocks=1)
3738
declare -ar lcovExcludeArgs=(--exclude '*/lex.yy.c' --exclude '*/parser.c' --exclude '*/lexer.l' --exclude '*/parser.y')
3839

3940
if [[ $(uname) == "Darwin" ]]; then
@@ -199,10 +200,10 @@ function measure_coverage()
199200
mkdir -p "${COVERAGE_DIR}"
200201
cp ${OUT_DIR}/*.gc* "${COVERAGE_DIR}"
201202
lcov --capture --directory "${COVERAGE_DIR}" --base-directory "${SRC_DIR}" --test-name SunnyDayTests \
202-
--quiet "${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
203-
--output-file "${COVERAGE_FILE}"
203+
--quiet "${lcovCaptureArgs[@]}" "${lcovCaptureRcArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" \
204+
--rc "${branchCoverage}=1" --output-file "${COVERAGE_FILE}" || return 1
204205
echo -n " Coverage: "
205-
lcov --summary "${COVERAGE_FILE}" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%'
206+
lcov --summary "${COVERAGE_FILE}" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%' || return 1
206207
fi
207208
}
208209

@@ -213,7 +214,7 @@ function report_coverage()
213214
local testReportDir=${OUT_DIR}/report-sunny
214215
mkdir -p ${testReportDir}
215216
genhtml --title "Boxes / Sunny-Day Tests" --branch-coverage --legend \
216-
--output-directory ${testReportDir} ${COVERAGE_FILE}
217+
--output-directory ${testReportDir} ${COVERAGE_FILE} || return 1
217218
echo -e "\nTest coverage report available at ${testReportDir}/index.html"
218219
fi
219220
}
@@ -267,7 +268,7 @@ do
267268
done
268269

269270
echo "${countExecuted} tests executed, $((countExecuted - countFailed)) successful, ${countFailed} failed."
270-
measure_coverage
271-
report_coverage
271+
measure_coverage || exit $?
272+
report_coverage || exit $?
272273

273274
exit ${result}

test/testrunner.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ declare opt_testCase=""
3333
declare branchCoverage=lcov_branch_coverage
3434
declare -a lcovArgs=(--ignore-errors unused)
3535
declare -a lcovCaptureArgs=()
36+
declare -ar lcovCaptureRcArgs=(--rc geninfo_unexecuted_blocks=1)
3637
declare -ar lcovExcludeArgs=(--exclude '*/lex.yy.c' --exclude '*/parser.c' --exclude '*/lexer.l' --exclude '*/parser.y')
3738

3839
if [[ $(uname) == "Darwin" ]]; then
@@ -125,8 +126,8 @@ function cov_baseline()
125126
if [ ! -f ${BASELINE_FILE} ]; then
126127
echo "Creating coverage baseline ..."
127128
lcov --capture --initial --no-recursion --directory ${OUT_DIR} --base-directory ${SRC_DIR} \
128-
"${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
129-
--output-file ${BASELINE_FILE}
129+
"${lcovCaptureArgs[@]}" "${lcovCaptureRcArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" \
130+
--rc "${branchCoverage}=1" --output-file ${BASELINE_FILE} || return 1
130131
echo -e "Coverage baseline created in ${BASELINE_FILE}\n"
131132
fi
132133
fi
@@ -175,23 +176,28 @@ function measure_coverage()
175176
mkdir -p "${testResultsDir}"
176177
cp ${OUT_DIR}/*.gc* "${testResultsDir}"
177178
lcov --capture --directory "${testResultsDir}" --base-directory ${SRC_DIR} --test-name "${tcBaseName}" --quiet \
178-
"${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
179-
--output-file "${testResultsDir}/coverage.info"
179+
"${lcovCaptureArgs[@]}" "${lcovCaptureRcArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" \
180+
--rc "${branchCoverage}=1" --output-file "${testResultsDir}/coverage.info" || return 1
180181
echo -n " Coverage: "
181-
lcov --summary "${testResultsDir}/coverage.info" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%'
182+
lcov --summary "${testResultsDir}/coverage.info" 2>&1 | grep 'lines...' | grep -oP '\d+\.\d*%' || return 1
182183
fi
183184
}
184185

185186

186187
function consolidate_coverage()
187188
{
188189
if [[ ${opt_coverage} == true ]]; then
190+
local status=0
191+
189192
echo -e "\nConsolidating test coverage ..."
190193
pushd ${OUT_DIR}/test-results || exit 1
191194
find . -name "*.info" | xargs printf -- '--add-tracefile %s\n' | xargs --exit \
192195
lcov --rc "${branchCoverage}=1" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" \
193-
--output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE}
196+
--output-file ../${COVERAGE_FILE} --add-tracefile ../${BASELINE_FILE} || status=$?
194197
popd || exit 1
198+
if [ ${status} -ne 0 ]; then
199+
return ${status}
200+
fi
195201
echo ""
196202
fi
197203
}
@@ -202,7 +208,7 @@ function report_coverage()
202208
local testReportDir=${OUT_DIR}/report
203209
mkdir -p ${testReportDir}
204210
genhtml --title "Boxes / All Tests" --branch-coverage --legend \
205-
--output-directory ${testReportDir} ${COVERAGE_FILE}
211+
--output-directory ${testReportDir} ${COVERAGE_FILE} || return 1
206212
echo -e "\nTest coverage report available at ${testReportDir}/index.html"
207213
}
208214

@@ -317,7 +323,7 @@ function assert_outcome()
317323

318324
parse_arguments "$@"
319325
check_prereqs
320-
cov_baseline
326+
cov_baseline || exit $?
321327

322328
declare tcBaseName=${opt_testCase%.txt}
323329

@@ -329,11 +335,14 @@ if [ ${opt_suite} == true ]; then
329335

330336
if [ ${opt_coverage_per_test} == false ]; then
331337
tcBaseName=black_box_all
332-
measure_coverage
338+
if ! measure_coverage; then
339+
overallResult=1
340+
fi
333341
fi
334342
if [ ${opt_coverage} == true ]; then
335-
consolidate_coverage
336-
report_coverage
343+
if ! consolidate_coverage || ! report_coverage; then
344+
overallResult=1
345+
fi
337346
fi
338347
exit ${overallResult}
339348
fi
@@ -363,7 +372,7 @@ declare -i actualReturnCode=100
363372
run_boxes
364373

365374
if [ ${opt_coverage_per_test} == true ]; then
366-
measure_coverage
375+
measure_coverage || exit $?
367376
fi
368377
assert_outcome
369378

utest/report.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# Calculate and report the unit test coverage. Invoked by Makefile.
1717
# ____________________________________________________________________________________________________________________
1818

19+
set -euo pipefail
20+
1921

2022
# Expects environment variables OUT_DIR and SRC_DIR.
2123
declare -r tcBaseName=unittest
@@ -25,6 +27,7 @@ declare -r testReportDir=${OUT_DIR}/report-utest
2527
declare branchCoverage=lcov_branch_coverage
2628
declare -a lcovArgs=(--ignore-errors unused)
2729
declare -a lcovCaptureArgs=()
30+
declare -ar lcovCaptureRcArgs=(--rc geninfo_unexecuted_blocks=1)
2831
declare -ar lcovExcludeArgs=(--exclude '*/lex.yy.c' --exclude '*/parser.c' --exclude '*/lexer.l' --exclude '*/parser.y')
2932

3033
if [[ $(uname) == "Darwin" ]]; then
@@ -44,7 +47,7 @@ then
4447
mkdir -p "${testReportDir}"
4548
cp "${OUT_DIR}"/*.gc* "${testResultsDir}"
4649
lcov --capture --directory "${testResultsDir}" --base-directory "${SRC_DIR}" --test-name ${tcBaseName} --quiet \
47-
"${lcovCaptureArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
50+
"${lcovCaptureArgs[@]}" "${lcovCaptureRcArgs[@]}" "${lcovExcludeArgs[@]}" "${lcovArgs[@]}" --rc "${branchCoverage}=1" \
4851
--output-file "${testResultsDir}/coverage.info"
4952
echo -n "[ Coverage ] "
5053
genhtml --title "Boxes / Unit Tests" --branch-coverage --legend --output-directory "${testReportDir}" \

0 commit comments

Comments
 (0)