-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathcoverage.sh
More file actions
executable file
·131 lines (109 loc) · 4.09 KB
/
coverage.sh
File metadata and controls
executable file
·131 lines (109 loc) · 4.09 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# NOTE: Expects to be run from inside the script directory.
set -e # Exit on error
cd ..
folder_path="coverage"
if [ ! -d "$folder_path" ]; then
mkdir -p "$folder_path"
echo "Folder created at: $folder_path"
else
echo "Folder already exists at: $folder_path"
fi
# Configuration: Define test files for different EVM versions
declare -a SHANGHAI_TESTS=(
# "test/helpers/LiquidStaking.t.sol"
test/helpers/PooledStaking.t.sol
# Add more shanghai tests here in the future
# "test/helpers/AnotherShanghaiTest.t.sol"
)
declare -a CANCUN_TESTS=(
# Add cancun tests here when needed
# "test/helpers/CancunTest.t.sol"
)
# Function to build match patterns for forge coverage
build_match_patterns() {
local tests=("$@")
local patterns=""
for test in "${tests[@]}"; do
if [[ -n "$patterns" ]]; then
patterns="$patterns --match-path *$(basename "$test")"
else
patterns="--match-path *$(basename "$test")"
fi
done
echo "$patterns"
}
# Function to build no-match patterns for forge coverage
build_no_match_patterns() {
local tests=("$@")
local patterns=""
for test in "${tests[@]}"; do
if [[ -n "$patterns" ]]; then
patterns="$patterns --no-match-path *$(basename "$test")"
else
patterns="--no-match-path *$(basename "$test")"
fi
done
echo "$patterns"
}
echo "Running coverage with inline EVM version flags..."
echo "-----------------------------------------------"
# Build list of all special EVM tests to exclude from default London run
ALL_SPECIAL_EVM_TESTS=("${SHANGHAI_TESTS[@]}" "${CANCUN_TESTS[@]}")
LONDON_NO_MATCH_PATTERNS=$(build_no_match_patterns "${ALL_SPECIAL_EVM_TESTS[@]}")
# Generate coverage for London EVM (default) - exclude special EVM tests
if [[ -n "$LONDON_NO_MATCH_PATTERNS" ]]; then
echo "Running coverage for London EVM..."
echo "Excluding: ${ALL_SPECIAL_EVM_TESTS[*]}"
forge coverage --evm-version london --report lcov --skip scripts $LONDON_NO_MATCH_PATTERNS --report-file "$folder_path/lcov-london.info"
else
echo "Running coverage for London EVM - no exclusions..."
forge coverage --evm-version london --report lcov --skip scripts --report-file "$folder_path/lcov-london.info"
fi
# Generate coverage for Shanghai EVM tests if any exist
if [ ${#SHANGHAI_TESTS[@]} -gt 0 ]; then
echo "Running coverage for Shanghai EVM..."
echo "Including: ${SHANGHAI_TESTS[*]}"
SHANGHAI_MATCH_PATTERNS=$(build_match_patterns "${SHANGHAI_TESTS[@]}")
forge coverage --evm-version shanghai --report lcov --skip scripts $SHANGHAI_MATCH_PATTERNS --report-file "$folder_path/lcov-shanghai.info"
fi
# Generate coverage for Cancun EVM tests if any exist
if [ ${#CANCUN_TESTS[@]} -gt 0 ]; then
echo "Running coverage for Cancun EVM..."
echo "Including: ${CANCUN_TESTS[*]}"
CANCUN_MATCH_PATTERNS=$(build_match_patterns "${CANCUN_TESTS[@]}")
forge coverage --evm-version cancun --report lcov --skip scripts $CANCUN_MATCH_PATTERNS --report-file "$folder_path/lcov-cancun.info"
fi
# Build the list of coverage files to merge
COVERAGE_FILES=("$folder_path/lcov-london.info")
if [ ${#SHANGHAI_TESTS[@]} -gt 0 ]; then
COVERAGE_FILES+=("$folder_path/lcov-shanghai.info")
fi
if [ ${#CANCUN_TESTS[@]} -gt 0 ]; then
COVERAGE_FILES+=("$folder_path/lcov-cancun.info")
fi
# Merge the lcov files
echo "Merging coverage reports..."
echo "Files to merge: ${COVERAGE_FILES[*]}"
lcov \
--rc branch_coverage=1 \
$(printf -- "--add-tracefile %s " "${COVERAGE_FILES[@]}") \
--output-file "$folder_path/lcov.info"
# Filter out test, mock, and script files
lcov \
--rc branch_coverage=1 \
--remove "$folder_path/lcov.info" \
--output-file "$folder_path/filtered-lcov.info" \
"test/*.*"
# Generate summary
lcov \
--rc branch_coverage=1 \
--list "$folder_path/filtered-lcov.info"
# Open more granular breakdown in browser
if [ "$CI" != "true" ]
then
genhtml \
--rc branch_coverage=1 \
--output-directory "$folder_path" \
"$folder_path/filtered-lcov.info"
open "$folder_path/index.html"
fi