-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·61 lines (53 loc) · 1.59 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
#!/bin/bash
# Parse flags
while getopts "cehr" flag
do
case "${flag}" in
c) c=true;;
e) e=true;;
h) h=true;;
r) r=true;c=true;; # Must run coverage to show the report
esac
done
# Display help
if [[ "$h" == true ]]; then
echo "Usage: ./test.sh [-h | -c | -r]"
echo "Helper bash script for running tests"
echo " -h - display help"
echo " -c - run with coverage"
echo " -e - also test examples"
echo " -r - show html report. implies -c."
exit 0
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
if [ $c ]; then
echo "Running tests with coverage"
echo "---------------------------"
# Collect coverage for each file individually to not artificially increase coverage
declare -a FILES_TO_COVER=("ascii_trees" "lexer" "macros" "optimisers" "preprocessor")
coverage erase
for NAME in "${FILES_TO_COVER[@]}"; do
echo -e "${GREEN}Collecting coverage for $NAME.py${NC}"
coverage run --append --include="./psll/$NAME.py" -m pytest -k "not examples" --quiet;
# Exit if unittests of this file failed
if [ "$?" != "0" ]; then
echo -e "${RED}Something is wrong${NC}"
exit 1
fi
done
else
echo "Running tests without coverage"
echo "------------------------------"
pytest -k "not examples"
fi
[ $e ] && pytest -k "examples" --quiet
[ $c ] && echo "" && coverage report
# If -r option is passed, display the coverage report and delete the .coverage file
if [ $r ]; then
coverage html
rm .coverage
open ./htmlcov/index.html
fi