-
Notifications
You must be signed in to change notification settings - Fork 12
/
ftest.sh
executable file
·43 lines (36 loc) · 1.18 KB
/
ftest.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
#!/bin/bash
set -e
if [[ $(command -v lcov) == '' ]]; then
printf "${RED}You haven't installed lcov.\n"
printf "${RED}We will run 'brew install lcov'.\n"
brew install lcov
else
printf "${GREEN}You have installed lcov 👍.\n"
fi
RED='\033[0;31m'
GREEN='\033[0;32m'
PATH_COVERAGE='coverage/lcov.info'
flutter pub get
flutter test --coverage
lcov --remove $PATH_COVERAGE \
'lib/main.dart' \
'lib/*/*.g.dart' \
-o coverage/lcov.info
if [ -n "$1" ]; then
if [ "$1" = true ]; then
printf "${GREEN}Let's open an report.\n"
genhtml $PATH_COVERAGE -o coverage
open coverage/index.html
fi
fi
MIN_COVERAGE_PERC=100
percentageRate=$(lcov --summary "$PATH_COVERAGE" | grep "lines......" | cut -d ' ' -f 4 | cut -d '%' -f 1)
if [ "$(echo "${percentageRate} < $MIN_COVERAGE_PERC" | bc)" -eq 1 ]; then
printf "${RED}Error: Your coverage rate is to low, expected ${MIN_COVERAGE_PERC}%% but have ${percentageRate}%%.\n"
printf "${RED}Please add more tests to cover your code.\n"
printf "${RED}To see in local your coverage rate use:\n"
printf "${RED} sh ftest.sh true\n"
exit 1
else
printf "${GREEN}Coverage rate is fine 👍.\n"
fi