From: Paulo Vital <pvital(a)linux.vnet.ibm.com>
This patch isolates each unit test execution reducing the occurrences of tests
using data from previous unit tests and making results not reliable.
In addition, it also simplifies the output of tests execution, printing the tags
PASSED and FAILED and the error/failed banners only when necessary.
Signed-off-by: Paulo Vital <pvital(a)linux.vnet.ibm.com>
---
tests/run_tests.sh.in | 52 +++++++++++++++++++++++++++++++++++++++------------
1 file changed, 40 insertions(+), 12 deletions(-)
diff --git a/tests/run_tests.sh.in b/tests/run_tests.sh.in
index 68dfa2e..a43a90a 100644
--- a/tests/run_tests.sh.in
+++ b/tests/run_tests.sh.in
@@ -21,6 +21,10 @@
HAVE_UNITTEST=@HAVE_PYMOD_UNITTEST@
PYTHON_VER=@PYTHON_VERSION@
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+NC='\033[0m' # No Color
+
if [ "$1" = "-v" ]; then
OPTS="-v"
shift
@@ -40,19 +44,43 @@ else
CMD="python -m unittest"
fi
-LIST=($ARGS)
-MODEL_LIST=()
-MOCK_LIST=()
-for ((i=0;i<${#LIST[@]};i++)); do
-
- if [[ ${LIST[$i]} == test_model* ]]; then
- MODEL_LIST+=(${LIST[$i]})
+NUM_TESTS=0
+TIME=0
+declare -A FAILED_UT # dict to store failed unit tests and its OUTPUT_FILE
+OUTPUT_FILE=$(mktemp)
+for UT in $ARGS; do
+ echo -n "***** Running unit test: $UT... "
+ # ../../../../../ refers to the project root
+ # ../../../../ refers to wok directory
+ # ../../../ refers to plugins directory
+ OUTPUT=$(PYTHONPATH=../../../../../:../../../../:../../../ \
+ PYTHONWARNINGS="ignore:Unverified HTTPS request" \
+ $CMD $OPTS $UT 2>&1)
+ RES=$?
+ if [ $RES -ne 0 ]; then
+ # unit test has failed, so keep the OUTPUT_FILE and print the results
+ echo -e "\t ${RED}FAILED${NC}"
+ ERROR_LOG_BEGIN=$(echo "$OUTPUT" | grep -n "^\==*" | head -n1
| cut -d":" -f1)
+ ERROR_LOG_END=$(echo "$OUTPUT" | wc -l)
+ echo "$OUTPUT" | tail -n $((${ERROR_LOG_END}-${ERROR_LOG_BEGIN}+1))
+ STATS=$(echo "$OUTPUT" | grep "Ran")
+ FAILED_UT+=([$UT]=$(echo "$OUTPUT" | grep FAILED | cut -d" "
-f2-4))
+ echo "$OUTPUT" >> $OUTPUT_FILE
else
- MOCK_LIST+=(${LIST[$i]})
+ # unit test has passed, so print the results and delete the OUTPUT_FILE
+ STATS=$(echo "$OUTPUT" | grep "Ran")
+ echo -e "\t ${GREEN}PASSED${NC} - $STATS"
fi
+ TES=$(echo $STATS | cut -d" " -f2)
+ NUM_TESTS=$(echo "$NUM_TESTS + $TES" | bc)
+ TES=$(echo $STATS | cut -d" " -f5)
+ TIME=$(echo "$TIME + ${TES:0:-1}" | bc)
done
-# ../../../../../ refers to the project root
-# ../../../../ refers to wok directory
-# ../../../ refers to plugins directory
-PYTHONPATH=../../../../../:../../../../:../../../ PYTHONWARNINGS="ignore:Unverified
HTTPS request" $CMD $OPTS ${MODEL_LIST[@]} ${MOCK_LIST[@]}
+# Print summary results
+echo -e
"======================================================================"
+echo -e "===================== Kimchi Unit Tests Summary
======================"
+echo -e "Ran $NUM_TESTS tests in $TIME seconds."
+for i in "${!FAILED_UT[@]}"; do
+ echo -e "$i FAILED: ${FAILED_UT[$i]} - full log available at $OUTPUT_FILE"
+done
--
2.5.5