-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathcoverage.sh
More file actions
executable file
·50 lines (40 loc) · 1.49 KB
/
coverage.sh
File metadata and controls
executable file
·50 lines (40 loc) · 1.49 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
48
49
50
#!/bin/bash
FAIL=0
echo "Generating coverage report..."
COVERAGE_OUTPUT=$(forge coverage --no-match-coverage "(test|script|dependencies|FormatResolver)" --report summary)
# Display the coverage report
echo "=== Coverage Report ==="
echo "$COVERAGE_OUTPUT"
echo "======================="
TOTAL_LINE=$(echo "$COVERAGE_OUTPUT" | grep "| Total.*|")
if [ -z "$TOTAL_LINE" ]; then
echo "❌ Could not find Total coverage line"
exit 1
fi
LINE_COV=$(echo "$TOTAL_LINE" | awk -F'|' '{print $3}' | grep -o '[0-9]*\.[0-9]*%' | sed 's/%//')
STMT_COV=$(echo "$TOTAL_LINE" | awk -F'|' '{print $4}' | grep -o '[0-9]*\.[0-9]*%' | sed 's/%//')
BRANCH_COV=$(echo "$TOTAL_LINE" | awk -F'|' '{print $5}' | grep -o '[0-9]*\.[0-9]*%' | sed 's/%//')
FUNC_COV=$(echo "$TOTAL_LINE" | awk -F'|' '{print $6}' | grep -o '[0-9]*\.[0-9]*%' | sed 's/%//')
if [ "$(echo "$LINE_COV < 100" | bc -l)" = "1" ]; then
echo "❌ Line coverage ($LINE_COV%) is below 100%"
FAIL=1
fi
if [ "$(echo "$STMT_COV < 100" | bc -l)" = "1" ]; then
echo "❌ Statement coverage ($STMT_COV%) is below 100%"
FAIL=1
fi
if [ "$(echo "$BRANCH_COV < 100" | bc -l)" = "1" ]; then
echo "❌ Branch coverage ($BRANCH_COV%) is below 100%"
FAIL=1
fi
if [ "$(echo "$FUNC_COV < 100" | bc -l)" = "1" ]; then
echo "❌ Function coverage ($FUNC_COV%) is below 100%"
FAIL=1
fi
if [ $FAIL = 1 ]; then
echo ""
echo "Coverage check failed! All coverage metrics must be 100%"
exit 1
else
echo "✅ Coverage requirements met!"
fi