3 # Run tests in serial. Invoke from within tests/ directory.
12 PERF_TESTS=("string_utils_test.py")
15 if [ -f color_vars.sh ]; then
22 echo "Usage: dup <string> <count>"
25 local times=$(seq 1 $2)
33 echo "Usage: make_header <required title> <color>"
37 local title_len=${#title}
38 title_len=$((title_len + 4))
41 local right=$(($width-($title_len+$left)))
44 echo -ne "[ ${color}${title}${NC} ]"
50 echo "Usage: $0 [-a]|[-i][-u][-d] [--coverage]"
52 echo "Runs tests under ${ROOT}. Options control which test types:"
54 echo " -a | --all . . . . . . . . . . . . Run all types of tests"
55 echo " -d | --doctests . . . . . . . . . Run doctests"
56 echo " -u | --unittests . . . . . . . . . Run unittests"
57 echo " -i | --integration . . . . . . . . Run integration tests"
62 while [[ $# -gt 0 ]]; do
83 echo "Argument $key was not recognized."
92 if [ $(expr ${DOCTEST} + ${UNITTEST} + ${INTEGRATION}) -eq 0 ]; then
97 if [ ${COVERAGE} -eq 1 ]; then
102 if [ ${DOCTEST} -eq 1 ]; then
103 for doctest in $(find ${ROOT} -name "*.py" -exec grep -l "import doctest" {} \;); do
104 BASE=$(basename ${doctest})
105 HDR="${BASE} (doctest)"
106 make_header "${HDR}" "${CYAN}"
107 if [ ${COVERAGE} -eq 1 ]; then
108 OUT=$( coverage run --source ../src ${doctest} >./test_output/${BASE}-output.txt 2>&1 )
110 OUT=$( python3 ${doctest} >./test_output/${BASE}-output.txt 2>&1 )
112 TESTS_RUN=$((TESTS_RUN+1))
113 FAILED=$( echo "${OUT}" | grep '\*\*\*Test Failed\*\*\*' | wc -l )
114 if [ $FAILED == 0 ]; then
118 FAILURES=$((FAILURES+1))
119 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${doctest})"
124 if [ ${UNITTEST} -eq 1 ]; then
125 for test in $(find ${ROOT} -name "*_test.py" -print); do
126 BASE=$(basename ${test})
127 HDR="${BASE} (unittest)"
128 make_header "${HDR}" "${GREEN}"
129 if [ ${COVERAGE} -eq 1 ]; then
130 coverage run --source ../src ${test} --unittests_ignore_perf >./test_output/${BASE}-output.txt 2>&1
131 if [[ " ${PERF_TESTS[*]} " =~ " ${BASE} " ]]; then
132 echo "(re-running w/o coverage to record perf results)."
136 ${test} >./test_output/${BASE}-output.txt 2>&1
138 if [ $? -eq 0 ]; then
141 FAILURES=$((FAILURES+1))
142 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${test})"
144 TESTS_RUN=$((TESTS_RUN+1))
148 if [ ${INTEGRATION} -eq 1 ]; then
149 for test in $(find ${ROOT} -name "*_itest.py" -print); do
150 BASE=$(basename ${test})
151 HDR="${BASE} (integration test)"
152 make_header "${HDR}" "${ORANGE}"
153 if [ ${COVERAGE} -eq 1 ]; then
154 coverage run --source ../src ${test} >./test_output/${BASE}-output.txt 2>&1
156 ${test} >./test_output/${BASE}-output.txt 2>&1
158 if [ $? -eq 0 ]; then
161 FAILURES=$((FAILURES+1))
162 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${test})"
164 TESTS_RUN=$((TESTS_RUN+1))
168 if [ ${COVERAGE} -eq 1 ]; then
169 make_header "Code Coverage Report" "${GREEN}"
170 coverage combine .coverage*
171 coverage report --omit=config-3.9.py,*_test.py,*_itest.py --sort=-cover
173 echo "To recall this report w/o re-running the tests:"
175 echo " $ coverage report --omit=config-3.8.py,*_test.py,*_itest.py --sort=-cover"
177 echo "...from the 'tests' directory. Note that subsequent calls to "
178 echo "run_tests.sh with --coverage will klobber previous results. See:"
180 echo " https://coverage.readthedocs.io/en/6.2/"
184 if [ ${FAILURES} -ne 0 ]; then
185 FAILED_TESTS=$(echo ${FAILED_TESTS} | sed 's/^,/__/g')
186 FAILED_TESTS=$(echo ${FAILED_TESTS} | sed 's/,/\n__/g')
187 if [ ${FAILURES} -eq 1 ]; then
188 echo -e "${RED}There was ${FAILURES}/${TESTS_RUN} failure:"
190 echo -e "${RED}There were ${FAILURES}/${TESTS_RUN} failures:"
192 echo "${FAILED_TESTS}"
196 echo -e "${BLACK}${ON_GREEN}All (${TESTS_RUN}) test(s) passed.${NC}"