-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathmove_tests.sh
More file actions
executable file
·81 lines (71 loc) · 2.04 KB
/
move_tests.sh
File metadata and controls
executable file
·81 lines (71 loc) · 2.04 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
#!/bin/bash
# Copyright (c) Walrus Foundation
# SPDX-License-Identifier: Apache-2.0
shopt -s nullglob
MIN_COVERAGE=${1:-70}
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\033[1m'
NORMAL='\033[0m'
COVERAGE=false
COVERAGE_ARG=""
ROOT_DIR="contracts"
while getopts "cd:" arg; do
case "${arg}" in
c)
COVERAGE=true
COVERAGE_ARG="--coverage"
;;
d)
ROOT_DIR="$OPTARG"
;;
*)
exit 1
esac
done
# 1) Run tests and record coverage
error=0
for dir in $ROOT_DIR/*/; do
if [ -f "$dir/Move.toml" ]; then
echo -e "\nTesting $dir..."
cd $dir
sui move build --allow-dirty -e testnet
sui move test $COVERAGE_ARG --allow-dirty -e testnet -i 1000000000
[ $? -ne 0 ] && error=1
cd -
fi
done
if [ $error -ne 0 ]; then
echo -e ${RED}ERROR${NORMAL}: Some Move tests failed.
exit $error
fi
if ! $COVERAGE; then
exit 0
fi
# 2) Check coverage and print summaries
error=0
for dir in $ROOT_DIR/*; do
if [ -f "$dir/Move.toml" ]; then
cd $dir
coverage_summary=$(sui move coverage summary)
echo -e "\n${BOLD}Coverage summary for $dir:${NORMAL}\n$coverage_summary"
coverage_percentage=$(echo "$coverage_summary" | awk '/Move Coverage:/ {print $5}')
if [[ ${coverage_percentage%.*} -lt $MIN_COVERAGE ]]; then
echo -e ${RED}ERROR${NORMAL}: \
Contract $dir has a coverage of ${RED}$coverage_percentage%${NORMAL}, \
which is below the minimal acceptable coverage of $MIN_COVERAGE%.
echo ' Run "sui move coverage source --module $module"' to find uncovered lines.
error=2
else
echo -e ${GREEN}SUCCESS${NORMAL}: \
Contract $dir has a coverage of ${GREEN}$coverage_percentage%${NORMAL}, \
which is above the minimal acceptable coverage of $MIN_COVERAGE%.
fi
cd -
fi
done
if [ $error -ne 0 ]; then
echo -e ${RED}ERROR${NORMAL}: Some Move contracts had insufficient test coverage.
exit $error
fi
exit 0