Fixup test runner.
[python_utils.git] / tests / run_tests.sh
index 6e0c30cf1b3c5ddb9ec6da18b2fb3c5f0553be0e..6c418a2424c52dcfa293f09de52fbb00e4570ed8 100755 (executable)
@@ -37,6 +37,18 @@ make_header() {
     echo
 }
 
+function usage() {
+    echo "Usage: $0 [-a]|[-i][-u][-d]"
+    echo
+    echo "Runs tests under ${ROOT}.  Options control which test types:"
+    echo
+    echo "    -a | --all . . . . . . . . . . . . Run all types of tests"
+    echo "    -d | --doctests  . . . . . . . . . Run doctests"
+    echo "    -u | --unittests . . . . . . . . . Run unittests"
+    echo "    -i | --integration . . . . . . . . Run integration tests"
+    echo
+    exit 1
+}
 
 while [[ $# -gt 0 ]]; do
     key="$1"
@@ -56,32 +68,31 @@ while [[ $# -gt 0 ]]; do
             INTEGRATION=1
             ;;
         *)    # unknown option
-            echo "Usage: $0 [-a]|[-i][-u][-d]"
-            echo
-            echo "Runs tests under ${ROOT}.  Options control which test types:"
-            echo
-            echo "    -a | --all . . . . . . . . . . . . Run all types of tests"
-            echo "    -d | --doctests  . . . . . . . . . Run doctests"
-            echo "    -u | --unittests . . . . . . . . . Run unittests"
-            echo "    -i | --integration . . . . . . . . Run integration tests"
-            echo
             echo "Argument $key was not recognized."
+            echo
+            usage
             exit 1
             ;;
     esac
     shift
 done
 
+if [ $(expr ${DOCTEST} + ${UNITTEST} + ${INTEGRATION}) -eq 0 ]; then
+    usage
+    exit 2
+fi
+
 if [ ${DOCTEST} -eq 1 ]; then
     for doctest in $(grep -lR doctest ${ROOT}/*.py); do
         BASE=$(basename ${doctest})
         BASE="${BASE} (doctest)"
         make_header "${BASE}" "${CYAN}"
         OUT=$( python3 ${doctest} 2>&1 )
-        if [ "$OUT" == "" ]; then
+        FAILED=$( echo "${OUT}" | grep '\*\*\*Test Failed\*\*\*' | wc -l )
+        if [ $FAILED == 0 ]; then
             echo "OK"
         else
-            echo -e "${OUT}"
+            echo -e "${FAILED}"
             FAILURES=$((FAILURES+1))
         fi
     done
@@ -112,5 +123,11 @@ if [ ${INTEGRATION} -eq 1 ]; then
 fi
 
 if [ ${FAILURES} -ne 0 ]; then
-    echo -e "${RED}There were ${FAILURES} failure(s).${NC}"
+    if [ ${FAILURES} -eq 1 ]; then
+        echo -e "${RED}There was ${FAILURES} failure.${NC}"
+    else
+        echo -e "${RED}There were ${FAILURES} failures.${NC}"
+    fi
+else
+    echo -e "${GREEN}Everything looks good.${NC}"
 fi