Skip to content

Commit f012710

Browse files
coverage script
1 parent 46e3e1c commit f012710

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

scripts/coverage.bash

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
OK=0
4+
TRY_AGAIN=11
5+
PKG_NOT_INSTALLED=65
6+
7+
ANSI_RED='\033[0;31m'
8+
ANSI_GREEN='\033[0;32m'
9+
ANSI_BROWN='\033[0;33m'
10+
ANSI_CLEAR='\033[0m'
11+
12+
13+
function run_tests_generate_coverage() {
14+
dart pub global run coverage:test_with_coverage
15+
}
16+
17+
function build_html_for_coverage_results() {
18+
genhtml -o coverage coverage/lcov.info
19+
}
20+
21+
function info_log() {
22+
echo -e "$ANSI_GREEN[info]$ANSI_CLEAR $1"
23+
}
24+
25+
function warning_log() {
26+
echo -e "$ANSI_BROWN[warning]$ANSI_CLEAR $1"
27+
}
28+
29+
function error_log() {
30+
echo -e "$ANSI_RED[error]$ANSI_CLEAR $1"
31+
}
32+
33+
info_log 'Running tests and generating coverage...'
34+
35+
run_tests_generate_coverage
36+
37+
if [ $? -eq $PKG_NOT_INSTALLED ]
38+
then
39+
warning_log 'Package coverage is not installed. Installing...'
40+
41+
dart pub global activate coverage
42+
43+
run_tests_generate_coverage
44+
fi
45+
46+
if [ ! $? -eq $OK ]
47+
then
48+
error_log 'Could not generate coverage! Are you sure you are in a directory that has test folders?'
49+
exit $TRY_AGAIN
50+
fi
51+
52+
info_log 'Generating HTML webpages for viewing coverage results.'
53+
54+
build_html_for_coverage_results
55+
56+
if [ ! $? -eq $OK ]
57+
then
58+
error_log 'Could not build HTML webpages using lcov command! Maybe the program is not available?'
59+
exit $TRY_AGAIN
60+
fi
61+
62+
info_log 'All done. The following command opens the main HTML webpage.'
63+
echo 'open coverage/index.html'

0 commit comments

Comments
 (0)