forked from deanishe/alfred-workflow
-
Notifications
You must be signed in to change notification settings - Fork 7
/
run-tests.sh
executable file
·155 lines (126 loc) · 2.42 KB
/
run-tests.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
rootdir="$( cd "$( dirname "$0" )"; pwd )"
usage() {
cat > /dev/stderr <<EOS
run-tests.sh [-v|-V] [-c <pkg>] [<tests/test_script.py>...]
Run test script(s) with coverage for one package.
Usage:
run-tests.sh [-v|-V] [-c <pkg>] [-l] [-t] [<tests/test_script.py>...]
run-tests.sh -h
Options:
-c <pkg> coverage report package
-l run linter
-t run tests (default)
-v verbose output
-V very verbose output
-h show this message and exit
Example:
run-tests.sh -c workflow.notify tests/test_notify.py
EOS
}
if [ -t 1 ]; then
red='\033[0;31m'
green='\033[0;32m'
nc='\033[0m'
else
red=
green=
nc=
fi
function log() {
echo "$@"
}
function fail() {
printf "${red}$@${nc}\n"
}
function success() {
printf "${green}$@${nc}\n"
}
coverpkg=workflow
vopts=
dolint=1
dotest=0
forcetest=1
while getopts ":c:hltvV" opt; do
case $opt in
c)
coverpkg="$OPTARG"
;;
l)
dolint=0
;;
t)
forcetest=0
;;
h)
usage
exit 0
;;
v)
vopts="-v"
;;
V)
vopts="-vv"
;;
\?)
log "Invalid option: -$OPTARG"
exit 1
;;
esac
done
shift $((OPTIND-1))
# Set test options and run tests
#-------------------------------------------------------------------------
unset alfred_version alfred_workflow_version alfred_workflow_bundleid
unset alfred_workflow_name alfred_workflow_cache alfred_workflow_data
files=(tests)
if [[ $# -gt 0 ]]; then
files=$@
fi
if [[ "$dolint" -eq 0 ]]; then
dotest=1
fi
if [[ "$forcetest" -eq 0 ]]; then
dotest=0
fi
coverage erase
# command rm -fv .coverage.*
if [[ $dotest -eq 0 ]]; then
# More options are in tox.ini
export PYTEST_ADDOPTS="--cov-report=html"
pytest $vopts --cov="$coverpkg" $files
ret1=${PIPESTATUS[0]}
echo
case "$ret1" in
0) success "TESTS OK" ;;
*) fail "TESTS FAILED" ;;
esac
if [[ "$ret1" -ne 0 ]]; then
exit $ret1
fi
echo
fi
if [[ $dolint -eq 0 ]]; then
flake8 $files
ret2=${PIPESTATUS[0]}
case "$ret2" in
0) success "LINTING OK" ;;
*) fail "LINTING FAILED" ;;
esac
fi
if [[ "$ret2" -ne 0 ]]; then
exit $ret2
fi
if [[ "$dotest" -eq 1 ]]; then
exit 0
fi
# Test coverage
coverage xml
coverage report --fail-under 100 --show-missing
ret3=${PIPESTATUS[0]}
echo
case "$ret3" in
0) success "COVERAGE OK" ;;
*) fail "COVERAGE FAILED" ;;
esac
exit $ret3