-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.sh
91 lines (79 loc) · 2.21 KB
/
test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# https://medium.com/@nocnoc/combined-code-coverage-for-flutter-and-dart-237b9563ecf8
# remember some failed commands and report on exit
error=false
show_help() {
printf "usage: $0 [--help]
Tool for running all unit and widget tests with code coverage and automatically generated if lcov is installed.
(run from root of repo)
where:
--help
print this message
"
exit 1
}
# run unit and widget tests
runTests () {
cd $1;
if [ -f "pubspec.yaml" ] && [ -d "test" ]; then
echo "running tests in $1"
flutter pub get
escapedPath="$(echo $1 | sed 's/\//\\\//g')"
# run tests with coverage
if grep flutter pubspec.yaml > /dev/null; then
echo "run flutter tests"
if [ -f "test/all_tests.dart" ]; then
flutter test --coverage test/all_tests.dart || error=true
else
flutter test --coverage || error=true
fi
if [ -d "coverage" ]; then
# combine line coverage info from package tests to a common file
sed "s/^SF:lib/SF:$escapedPath\/lib/g" coverage/lcov.info >> $2/coverage/lcov.info
fi
else
echo "not a flutter package, skipping"
fi
fi
cd - > /dev/null
}
runReport() {
if [ -f "coverage/lcov.info" ] && ! [ "$TRAVIS" ]; then
C:/ProgramData/chocolatey/lib/lcov/tools/bin/genhtml coverage/lcov.info -o coverage --no-function-coverage -s -p `pwd`/coverage
if $IsWindows || $ENV:OS; then
start coverage/index.html
else
open coverage/index.html
fi
fi
}
if ! [ -d .git ]; then printf "\nError: not in root of repo"; show_help; fi
case $1 in
--help)
show_help
;;
*)
currentDir=`pwd`
# if no parameter passed
if [ -z $1 ]; then
rm -f coverage/lcov.info
dirs=(`find . -maxdepth 2 -type d`)
for dir in "${dirs[@]}"; do
runTests $dir $currentDir
done
else
if [[ -d "$1" ]]; then
runTests $1 $currentDir
else
printf "\nError: not a directory: $1"
show_help
fi
fi
runReport
;;
esac
# Fail the build if there was an error
if [ "$error" = true ] ;
then
exit -1
fi