forked from llfbandit/dio_cache_interceptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.sh
executable file
·113 lines (104 loc) · 3.12 KB
/
run_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# remember some failed commands and report on exit
error=false
show_help() {
printf "usage: $0 [--help] [--report] [<path to package>]
Tool for running all unit and widget tests with code coverage.
(run from root of repo)
where:
<path to package>
run tests for package at path only
(otherwise runs all tests)
--report
run a coverage report
(requires lcov installed)
--help
print this message
requires code_coverage package
(install with 'pub global activate coverage')
"
exit 1
}
# run unit and widget tests
runTests () {
cd $1;
if [ -f "pubspec.yaml" ] && [ -d "test" ]; then
echo "running tests in $1"
flutter packages get
# check if build_runner needs to be run
if grep build_runner pubspec.yaml > /dev/null ; then
flutter packages pub run build_runner build --delete-conflicting-outputs
fi
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/lcov.info
rm -rf "coverage"
fi
else
# pure dart
echo "run dart tests"
pub get
pub global run coverage:collect_coverage --port=8111 -o coverage.json --resume-isolates --wait-paused &
dart --pause-isolates-on-exit --enable-vm-service=8111 "test/all_tests.dart" || error=true
pub global run coverage:format_coverage --packages=.packages -i coverage.json --report-on lib --lcov --out lcov.info
if [ -f "lcov.info" ]; then
# combine line coverage info from package tests to a common file
sed "s/^SF:.*lib/SF:$escapedPath\/lib/g" lcov.info >> $2/lcov.info
rm lcov.info
fi
rm -f coverage.json
fi
fi
cd - > /dev/null
}
runReport() {
if [ -f "lcov.info" ] && ! [ "$TRAVIS" ]; then
genhtml lcov.info -o coverage --no-function-coverage -s -p `pwd`
open coverage/index.html
fi
}
if ! [ -d .git ]; then printf "\nError: not in root of repo"; show_help; fi
case $1 in
--help)
show_help
;;
--report)
if ! [ -z ${2+x} ]; then
printf "\nError: no extra parameters required: $2"
show_help
fi
runReport
;;
*)
currentDir=`pwd`
# if no parameter passed
if [ -z $1 ]; then
rm -f 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
;;
esac
# Fail the build if there was an error
if [ "$error" = true ] ;
then
exit -1
fi