-
Notifications
You must be signed in to change notification settings - Fork 28
/
test.sh
executable file
·130 lines (107 loc) · 2.78 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
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
#!/bin/bash
EXPECTED_ARGS=1
E_BADARGS=65
MAX_PYLINT_VIOLATIONS=2600
MAX_PEP8_VIOLATIONS=1320
PACKAGE_NAME=latex2edx
progname=$(basename $0)
usage()
{
cat <<EOF
Usage: test.sh [options]
Run the test runner and optional quality checks
Options:
--help print this help message
-q or --with-quality run pylint and pep8 on code
-d or --diff-cover report of coverage in diff from origin/master
-c or --with-coveralls run coveralls at the end (prompting for repo token)
EOF
}
SHORTOPTS="qcd"
LONGOPTS="help,with-quality,with-coveralls,diff-cover"
if $(getopt -T >/dev/null 2>&1) ; [ $? = 4 ] ; then # New longopts getopt.
OPTS=$(getopt -o $SHORTOPTS --long $LONGOPTS -n "$progname" -- "$@")
else # Old classic getopt.
# Special handling for --help on old getopt.
case $1 in --help) usage ; exit 0 ;; esac
OPTS=$(getopt $SHORTOPTS "$@")
fi
if [ $? -ne 0 ]; then
echo "'$progname --help' for more information" 1>&2
exit 1
fi
eval set -- "$OPTS"
quality=false
coveralls=false
diffcover=false
while [ $# -gt 0 ]; do
: debug: $1
case $1 in
--help)
usage
exit 0
;;
-q|--with-quality)
quality=true
shift
;;
-c|--with-coveralls)
coveralls=true
shift
;;
-d|--diff-cover)
diffcover=true
shift
;;
--)
shift
break
;;
*)
echo "Internal Error: option processing error: $1" 1>&2
exit 1
;;
esac
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Using git version $(git --version)"
nosetests --with-coverage --cover-html --cover-package=$PACKAGE_NAME,$PACKAGE_NAME.test --exclude testtex
test_results=$?
if $quality; then
# Show nice reports
pylint --rcfile=$DIR/.pylintrc $PACKAGE_NAME
pep8 $PACKAGE_NAME --max-line-length=120
# Run again for automated violation testing
pylint_violations=$(pylint --rcfile=$DIR/.pylintrc $PACKAGE_NAME -r n | grep -v '\*\*\*\*\*\*\*\*\*\*' | wc -l)
pep8_violations=$(pep8 $PACKAGE_NAME | wc -l)
fi
if $diffcover; then
coverage xml -i
diff-cover coverage.xml
rm coverage.xml
fi
if $coveralls; then
echo "What is the coverall repo token?"
read token
echo "repo_token: $token" > $DIR/.coveralls.yml
coveralls
rm $DIR/.coveralls.yml
fi
exit_code=0
if [[ $test_results -ne 0 ]]; then
echo "Unit tests failed, failing test"
exit_code=$[exit_code + 1]
fi
if [[ pylint_violations!="" && pylint_violations -gt MAX_PYLINT_VIOLATIONS ]]; then
echo "$pylint_violations is too many PyLint Violations, failing test (allowed $MAX_PYLINT_VIOLATIONS)"
exit_code=$[exit_code + 1]
else
echo "PyLint Violations = $pylint_violations: OK"
fi
if [[ pep8_violations!="" && pep8_violations -gt MAX_PEP8_VIOLATIONS ]]; then
echo "$pep8_violations is too many PEP-8 Violations, failing test (allowed $MAX_PEP8_VIOLATIONS"
exit_code=$[exit_code + 1]
else
echo "PEP-8 Violations = $pep8_violations: OK"
fi
exit $exit_code