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 if [ "${BASE}" == "zookeeper_test.py" ]; then
129 echo "(skipping zookeeper_test.py; if you have a zookeeper instance, fixme)"
132 make_header "${HDR}" "${GREEN}"
133 if [ ${COVERAGE} -eq 1 ]; then
134 coverage run --source ../src ${test} --unittests_ignore_perf >./test_output/${BASE}-output.txt 2>&1
135 if [[ " ${PERF_TESTS[*]} " =~ " ${BASE} " ]]; then
136 echo "(re-running w/o coverage to record perf results)."
140 ${test} >./test_output/${BASE}-output.txt 2>&1
142 if [ $? -eq 0 ]; then
145 FAILURES=$((FAILURES+1))
146 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${test})"
148 TESTS_RUN=$((TESTS_RUN+1))
152 if [ ${INTEGRATION} -eq 1 ]; then
153 for test in $(find ${ROOT} -name "*_itest.py" -print); do
154 BASE=$(basename ${test})
155 HDR="${BASE} (integration test)"
156 make_header "${HDR}" "${ORANGE}"
157 if [ ${COVERAGE} -eq 1 ]; then
158 coverage run --source ../src ${test} >./test_output/${BASE}-output.txt 2>&1
160 ${test} >./test_output/${BASE}-output.txt 2>&1
162 if [ $? -eq 0 ]; then
165 FAILURES=$((FAILURES+1))
166 FAILED_TESTS="${FAILED_TESTS},${BASE} (python3 ${test})"
168 TESTS_RUN=$((TESTS_RUN+1))
172 if [ ${COVERAGE} -eq 1 ]; then
173 make_header "Code Coverage Report" "${GREEN}"
174 coverage combine .coverage*
175 coverage report --omit=config-3.9.py,*_test.py,*_itest.py --sort=-cover
177 echo "To recall this report w/o re-running the tests:"
179 echo " $ coverage report --omit=config-3.8.py,*_test.py,*_itest.py --sort=-cover"
181 echo "...from the 'tests' directory. Note that subsequent calls to "
182 echo "run_tests.sh with --coverage will klobber previous results. See:"
184 echo " https://coverage.readthedocs.io/en/6.2/"
188 if [ ${FAILURES} -ne 0 ]; then
189 FAILED_TESTS=$(echo ${FAILED_TESTS} | sed 's/^,/__/g')
190 FAILED_TESTS=$(echo ${FAILED_TESTS} | sed 's/,/\n__/g')
191 if [ ${FAILURES} -eq 1 ]; then
192 echo -e "${RED}There was ${FAILURES}/${TESTS_RUN} failure:"
194 echo -e "${RED}There were ${FAILURES}/${TESTS_RUN} failures:"
196 echo "${FAILED_TESTS}"
200 echo -e "${BLACK}${ON_GREEN}All (${TESTS_RUN}) test(s) passed.${NC}"