-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.sh
executable file
·84 lines (67 loc) · 1.81 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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Initial test for rpmdistro-gitoverlay
export PYTHON=${PYTHON:-"/usr/bin/python"}
export PYTHON3=${PYTHON3:-"/usr/bin/python3"}
export PYTHONPATH=${PYTHONPATH:-$(pwd)}
export WORK_DIR=$(mktemp -p $(pwd) -d -t .tmp.XXXXXXXXXX)
LOG=${LOG:-"$(pwd)/tests.log"}
cleanup () {
rm -rf ${WORK_DIR}
}
get_coverage_bin() {
COVERAGE_BIN=${COVERAGE_BIN-"/usr/bin/coverage"}
if [[ ! -x "${COVERAGE_BIN}" ]]; then
# Check to see if it is in local instead.
COVERAGE_BIN="/usr/local/bin/coverage"
fi
if [[ ! -x "${COVERAGE_BIN}" ]]; then
# The executable is "coverage2" on systems with default python3 and no
# python3 install.
COVERAGE_BIN="/usr/bin/coverage2"
fi
if [[ ! -x "${COVERAGE_BIN}" ]]; then
COVERAGE_BIN="/usr/bin/coverage3"
fi
echo ${COVERAGE_BIN}
}
load_coverage() {
COVERAGE_BIN=$1;
if [[ -x "${COVERAGE_BIN}" ]]; then
COVERAGE="${COVERAGE_BIN}
run
--source=./rdgo/
--branch"
else
COVERAGE="${PYTHON3:-/usr/bin/python3}"
fi
echo ${COVERAGE}
}
execute_unittest() {
# Load variables
COVERAGE_BIN=$1; shift
COVERAGE=$1;
# Execute Unit tests
set +e
${COVERAGE} -m unittest discover ./tests/unit/ | tee -a ${LOG}
_UNIT_FAIL="$?"
set -e
if [[ -x "${COVERAGE_BIN}" ]]; then
echo "Coverage report:" | tee -a ${LOG}
${COVERAGE_BIN} report | tee -a ${LOG}
fi
if [[ $_UNIT_FAIL -eq 0 ]]; then
echo "ALL TESTS PASSED"
exit 0
else
echo "Unit tests failed."
fi
}
trap cleanup EXIT
echo "UNIT TESTS:"
# Get Coverage and Coverage bin
COVERAGE_BIN=$(get_coverage_bin)
COVERAGE=$(load_coverage "${COVERAGE_BIN}")
execute_unittest ${COVERAGE_BIN} ${COVERAGE}
exit 1