Skip to content

Commit 2337460

Browse files
author
Nathan Gillett
committed
Fix coverage display rounding to match integer gate
Signed-off-by: Nathan Gillett <nathan@intentproof.io>
1 parent dfb63cf commit 2337460

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

scripts/check-coverage.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,24 @@ rules_file="$(mktemp)"
3232
trap 'rm -f "$rules_file"' EXIT
3333
printf '%s\n' "${CRITICAL_RULES[@]}" >"$rules_file"
3434

35+
coverage_percent_display() {
36+
awk -v c="$1" -v t="$2" 'BEGIN {
37+
if (t == 0) { print "0.0"; exit }
38+
printf "%.1f", int(1000 * c / t) / 10
39+
}'
40+
}
41+
42+
threshold_met() {
43+
awk -v c="$1" -v t="$2" -v min="$3" \
44+
'BEGIN { exit !(t > 0 && c * 100 >= t * min) }'
45+
}
46+
3547
report_threshold() {
3648
local label="$1" covered="$2" total="$3" min="$4"
3749
local pct
38-
pct="$(awk -v c="$covered" -v t="$total" 'BEGIN { printf "%.1f", 100 * c / t }')"
50+
pct="$(coverage_percent_display "$covered" "$total")"
3951
echo "${label}: ${pct}% (${covered}/${total} statements), minimum ${min}%"
40-
if awk -v c="$covered" -v t="$total" -v min="$min" \
41-
'BEGIN { exit !(t > 0 && c * 100 >= t * min) }'; then
52+
if threshold_met "$covered" "$total" "$min"; then
4253
echo " PASS"
4354
return 0
4455
fi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
# Regression test: displayed percent must not round up past a failing gate.
3+
set -euo pipefail
4+
5+
pct="$(awk -v c=9399 -v t=10000 'BEGIN {
6+
if (t == 0) { print "0.0"; exit }
7+
printf "%.1f", int(1000 * c / t) / 10
8+
}')"
9+
10+
if [[ "$pct" != "93.9" ]]; then
11+
echo "FAIL: expected truncated display 93.9%, got ${pct}%" >&2
12+
exit 1
13+
fi
14+
15+
if awk -v c=9399 -v t=10000 -v min=94 \
16+
'BEGIN { exit !(t > 0 && c * 100 >= t * min) }'; then
17+
echo "FAIL: expected integer gate to fail at 9399/10000 min 94%" >&2
18+
exit 1
19+
fi
20+
21+
echo "PASS: display percent matches integer gate semantics"

0 commit comments

Comments
 (0)