-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck-coverage.sh
More file actions
executable file
·47 lines (39 loc) · 1.36 KB
/
Copy pathcheck-coverage.sh
File metadata and controls
executable file
·47 lines (39 loc) · 1.36 KB
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
#!/usr/bin/env bash
# Enforces line-coverage threshold against coverage/lcov.info.
# Usage: bash scripts/check-coverage.sh [threshold]
#
# Excludes only code that cannot be unit-tested:
# - generated code (*.g.dart, *.freezed.dart)
# - generated localizations (l10n/)
# - app entry points (main.dart, app.dart)
#
set -euo pipefail
THRESHOLD="${1:-${COVERAGE_THRESHOLD:-80}}"
LCOV="${LCOV_PATH:-coverage/lcov.info}"
if [ ! -f "$LCOV" ]; then
echo "ERROR: $LCOV not found. Run 'flutter test --coverage' first." >&2
exit 1
fi
EXCLUDE_PATTERNS='\.g\.dart$|\.freezed\.dart$|/l10n/|/main\.dart$|/app\.dart$'
LF=$(awk -v exc="$EXCLUDE_PATTERNS" '
/^SF:/ { skip = ($0 ~ exc); next }
/^LF:/ && !skip { sub("LF:", ""); sum += $0 }
END { print sum + 0 }
' "$LCOV")
LH=$(awk -v exc="$EXCLUDE_PATTERNS" '
/^SF:/ { skip = ($0 ~ exc); next }
/^LH:/ && !skip { sub("LH:", ""); sum += $0 }
END { print sum + 0 }
' "$LCOV")
if [ "$LF" -eq 0 ]; then
echo "ERROR: no lines found in $LCOV" >&2
exit 1
fi
PCT=$(awk -v lh="$LH" -v lf="$LF" 'BEGIN { printf "%.2f", (lh / lf) * 100 }')
PASS=$(awk -v pct="$PCT" -v th="$THRESHOLD" 'BEGIN { print (pct + 0 >= th + 0) ? 1 : 0 }')
if [ "$PASS" -eq 1 ]; then
echo "Coverage ${PCT}% (lines ${LH}/${LF}) — meets ${THRESHOLD}% threshold"
exit 0
fi
echo "FAIL: coverage ${PCT}% (lines ${LH}/${LF}) below ${THRESHOLD}% threshold" >&2
exit 1