77folder_path=" coverage"
88
99if [ ! -d " $folder_path " ]; then
10- # If not, create the folder
1110 mkdir -p " $folder_path "
1211 echo " Folder created at: $folder_path "
1312else
1413 echo " Folder already exists at: $folder_path "
1514fi
1615
16+ # Configuration: Define test files for different EVM versions
17+ declare -a SHANGHAI_TESTS=(
18+ # "test/helpers/LiquidStaking.t.sol"
19+ test/helpers/PooledStaking.t.sol
20+ # Add more shanghai tests here in the future
21+ # "test/helpers/AnotherShanghaiTest.t.sol"
22+ )
1723
24+ declare -a CANCUN_TESTS=(
25+ # Add cancun tests here when needed
26+ # "test/helpers/CancunTest.t.sol"
27+ )
1828
19- # Generates lcov.info
20- forge coverage --report lcov --skip scripts --report-file " $folder_path /lcov.info"
29+ # Function to build match patterns for forge coverage
30+ build_match_patterns () {
31+ local tests=(" $@ " )
32+ local patterns=" "
33+
34+ for test in " ${tests[@]} " ; do
35+ if [[ -n " $patterns " ]]; then
36+ patterns=" $patterns --match-path *$( basename " $test " ) "
37+ else
38+ patterns=" --match-path *$( basename " $test " ) "
39+ fi
40+ done
41+
42+ echo " $patterns "
43+ }
44+
45+ # Function to build no-match patterns for forge coverage
46+ build_no_match_patterns () {
47+ local tests=(" $@ " )
48+ local patterns=" "
49+
50+ for test in " ${tests[@]} " ; do
51+ if [[ -n " $patterns " ]]; then
52+ patterns=" $patterns --no-match-path *$( basename " $test " ) "
53+ else
54+ patterns=" --no-match-path *$( basename " $test " ) "
55+ fi
56+ done
57+
58+ echo " $patterns "
59+ }
60+
61+ echo " Running coverage with inline EVM version flags..."
62+ echo " -----------------------------------------------"
63+
64+ # Build list of all special EVM tests to exclude from default London run
65+ ALL_SPECIAL_EVM_TESTS=(" ${SHANGHAI_TESTS[@]} " " ${CANCUN_TESTS[@]} " )
66+ LONDON_NO_MATCH_PATTERNS=$( build_no_match_patterns " ${ALL_SPECIAL_EVM_TESTS[@]} " )
67+
68+ # Generate coverage for London EVM (default) - exclude special EVM tests
69+ if [[ -n " $LONDON_NO_MATCH_PATTERNS " ]]; then
70+ echo " Running coverage for London EVM..."
71+ echo " Excluding: ${ALL_SPECIAL_EVM_TESTS[*]} "
72+ forge coverage --evm-version london --report lcov --skip scripts $LONDON_NO_MATCH_PATTERNS --report-file " $folder_path /lcov-london.info"
73+ else
74+ echo " Running coverage for London EVM - no exclusions..."
75+ forge coverage --evm-version london --report lcov --skip scripts --report-file " $folder_path /lcov-london.info"
76+ fi
77+
78+ # Generate coverage for Shanghai EVM tests if any exist
79+ if [ ${# SHANGHAI_TESTS[@]} -gt 0 ]; then
80+ echo " Running coverage for Shanghai EVM..."
81+ echo " Including: ${SHANGHAI_TESTS[*]} "
82+ SHANGHAI_MATCH_PATTERNS=$( build_match_patterns " ${SHANGHAI_TESTS[@]} " )
83+ forge coverage --evm-version shanghai --report lcov --skip scripts $SHANGHAI_MATCH_PATTERNS --report-file " $folder_path /lcov-shanghai.info"
84+ fi
85+
86+ # Generate coverage for Cancun EVM tests if any exist
87+ if [ ${# CANCUN_TESTS[@]} -gt 0 ]; then
88+ echo " Running coverage for Cancun EVM..."
89+ echo " Including: ${CANCUN_TESTS[*]} "
90+ CANCUN_MATCH_PATTERNS=$( build_match_patterns " ${CANCUN_TESTS[@]} " )
91+ forge coverage --evm-version cancun --report lcov --skip scripts $CANCUN_MATCH_PATTERNS --report-file " $folder_path /lcov-cancun.info"
92+ fi
93+
94+ # Build the list of coverage files to merge
95+ COVERAGE_FILES=(" $folder_path /lcov-london.info" )
96+ if [ ${# SHANGHAI_TESTS[@]} -gt 0 ]; then
97+ COVERAGE_FILES+=(" $folder_path /lcov-shanghai.info" )
98+ fi
99+ if [ ${# CANCUN_TESTS[@]} -gt 0 ]; then
100+ COVERAGE_FILES+=(" $folder_path /lcov-cancun.info" )
101+ fi
102+
103+ # Merge the lcov files
104+ echo " Merging coverage reports..."
105+ echo " Files to merge: ${COVERAGE_FILES[*]} "
106+ lcov \
107+ --rc branch_coverage=1 \
108+ $( printf -- " --add-tracefile %s " " ${COVERAGE_FILES[@]} " ) \
109+ --output-file " $folder_path /lcov.info"
21110
22111# Filter out test, mock, and script files
23112lcov \
39128 --output-directory " $folder_path " \
40129 " $folder_path /filtered-lcov.info"
41130 open " $folder_path /index.html"
42- fi
131+ fi
0 commit comments