forked from balancer/balancer-v3-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.sh
executable file
·70 lines (58 loc) · 1.87 KB
/
coverage.sh
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
#!/bin/bash
set -e # exit on error
# reduces the amount of tests in fuzzing, so coverage runs faster
export FOUNDRY_PROFILE=coverage
export CURRENT_PACKAGE=$(basename "$PWD")
# generates lcov.info
forge coverage --report lcov
# Initialize variables
current_file=""
lines_found=0
lines_hit=0
sed "s/\/.*$CURRENT_PACKAGE.//g" lcov.info > lcov-clearfolders.info
sed -i -e "s/\.\.contracts\//contracts\//g" lcov-clearfolders.info
# generates coverage/lcov.info
COVERAGE=true yarn hardhat coverage
# Foundry uses relative paths but Hardhat uses absolute paths.
# Convert absolute paths to relative paths for consistency.
sed -i -e "s/\/.*$CURRENT_PACKAGE.//g" coverage/lcov.info
# Merge lcov files
lcov \
--rc lcov_branch_coverage=1 \
--rc derive_function_end_line=0 \
--add-tracefile lcov-clearfolders.info \
--add-tracefile coverage/lcov.info \
--output-file lcov-merged.info \
--no-checksum
if [$CURRENT_PACKAGE = 'vault']; then
# Filter out node_modules, test, and mock files
lcov \
--rc lcov_branch_coverage=1 \
--rc derive_function_end_line=0 \
--remove lcov-merged.info \
"*node_modules*" "*test*" "*mock*" \
--output-file lcov-filtered.info
else
# Filter out node_modules, test, mock files and vault contracts
lcov \
--rc lcov_branch_coverage=1 \
--rc derive_function_end_line=0 \
--remove lcov-merged.info \
"*node_modules*" "*test*" "*mock*" "*/vault/*"\
--output-file lcov-filtered.info
fi
# Generate summary
lcov \
--rc lcov_branch_coverage=1 \
--rc derive_function_end_line=0 \
--list lcov-filtered.info
# Open more granular breakdown in browser
rm -rf coverage-genhtml/
genhtml \
--rc genhtml_branch_coverage=1 \
--rc derive_function_end_line=0 \
--output-directory coverage-genhtml \
lcov-filtered.info
open coverage-genhtml/index.html
# Delete temp files
rm -rf lcov-*.info lcov-*.info-e coverage/ lcov.info coverage.json