File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,13 +32,24 @@ rules_file="$(mktemp)"
3232trap ' rm -f "$rules_file"' EXIT
3333printf ' %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+
3547report_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
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments