Created new script for running all unit tests
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 24 May 2010 12:41:10 +0000 (15:41 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 24 May 2010 12:41:10 +0000 (15:41 +0300)
 - All .pro files are searched under tests directory and
   file with same name (without .pro extension)
   is expected to be the actual unit test executable

scripts/master_test_script.sh [deleted file]
scripts/run_unit_tests.sh [new file with mode: 0755]

diff --git a/scripts/master_test_script.sh b/scripts/master_test_script.sh
deleted file mode 100644 (file)
index 0f80199..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/bin/bash
-
-if [$1 -eq ""]; then
-   echo "Usage of the script: ./master_test_script.sh destination_folder_for_test_reports tests_folder_location"
-else
-##########################################################
-# This script is executed from /scripts directory        #
-# in situare project folder                              #
-##########################################################
-clear
-echo "This is the master script for building and executing all automatic unit test."
-echo "As a final step, it creates summary report from all tests executed."
-##########################################################
-#Environment settings                                   #
-##########################################################
-#Store all directory names to a list
-#Modify these paths to point to correct path
-location=$2
-echo $location
-echo "Tests situate at: $location"
-
-TEST_REPORT=$1
-echo "Directory to store test report: $1"
-#cd $location
-if [ ! -e $1/tests_summary.txt ]; then
-    touch $1/tests_summary.txt
-    echo "##########################################" >> tests_summary.txt
-    echo "# Summary of unit tests executed         #" >> tests_summary.txt
-    echo "# Date: `date`    #" >> tests_summary.txt
-    echo "# User: `whoami`                            #" >> tests_summary.txt
-    echo "##########################################" >> tests_summary.txt
-fi  
-
-FILE=$1/tests_summary.txt
-cd $location
-MODULES=(`ls`)
-echo $MODULES
-
-for component in "${MODULES[@]}"
-do 
-  echo "Found test directory: $component"
-done
-
-##########################################################
-#First part: Execution of all tests                      #
-##########################################################
-for component in "${MODULES[@]}" #Loop through components
-do
-  cd $location/$component
-  CASES=(`ls`) #List all test cases under component directory
-  for unittest in "${CASES[@]}"
-  do
-    cd $location/$component/$unittest
-    echo "Building tests for $component/$unittest"
-    qmake
-    make
-    echo "Running tests for $component/$unittest"
-    ./$unittest -o testreport_$component.txt
-    echo "Cleaning $unittest"
-    make clean
-    rm Makefile
-    rm $unittest
-  done
-done
-
-#########################################################
-# Second part: Extraction of results                   #
-#########################################################
-echo "Summarizing test results....." 
-for component in "${MODULES[@]}" #Loop through components
-do 
-  cd $location/$component
-  CASES=(`ls`) #List all test cases uner component directory
-  for unittests in "${CASES[@]}"
-  do
-    cd $location/$component/$unittests
-    echo "############# $component/$unittests ################" >> $FILE
-    grep Totals *.txt >> $FILE
-  done
-done
-fi
-exit 0
diff --git a/scripts/run_unit_tests.sh b/scripts/run_unit_tests.sh
new file mode 100755 (executable)
index 0000000..2aa0cce
--- /dev/null
@@ -0,0 +1,81 @@
+#!/bin/bash
+
+clear
+
+# set default values
+UNIT_TESTS_ROOT_DIR="../tests"
+REPORT_PATH="../doc"
+REPORT_FILE="unit_test_results.txt"
+TEMP_FILE_EXEC_NOT_FOUND="temp_exec_not_found.txt"
+TEMP_REPORT_FILE="temp_report.txt"
+
+# check that directories are found
+if [[ -d $REPORT_PATH && -d $UNIT_TESTS_ROOT_DIR ]]; then
+    # convert relational paths to absolute ones
+    UNIT_TESTS_ROOT_DIR_ABSOLUTE=`cd $UNIT_TESTS_ROOT_DIR; pwd`
+    REPORT_PATH_ABSOLUTE=`cd $REPORT_PATH; pwd`
+    REPORT="$REPORT_PATH_ABSOLUTE/$REPORT_FILE"
+    echo ""
+    echo "Running recursively all tests under $UNIT_TESTS_ROOT_DIR_ABSOLUTE"
+    echo "Saving results to $REPORT"
+    echo ""
+
+    # overwrite report summary file and write header
+    echo "##########################################" > $REPORT
+    echo "# Summary of unit tests executed" >> $REPORT
+    echo "# Date: `date`" >> $REPORT
+    echo "# User: `whoami`" >> $REPORT
+    echo "##########################################" >> $REPORT
+    echo "" >> $REPORT
+
+    # find all test .pro files pahts, cut .pro extension
+    UNIT_TEST_PROJECTS=(`find $UNIT_TESTS_ROOT_DIR_ABSOLUTE | egrep .pro$ | sed -e s/.pro//g`)
+
+    # run tests
+    for project in "${UNIT_TEST_PROJECTS[@]}"
+    do 
+        if [ -f $project ]; then
+            echo ""
+            # run unit test, save to temp file, ignore strerr stream
+            $project -silent -o $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE 2> /dev/null
+            # print to screen and append to summary
+            cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE
+            cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
+            echo "" >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
+        else
+            # save path of missing test to temporary file
+            missing=(`echo $project | sed -e s,$UNIT_TESTS_ROOT_DIR_ABSOLUTE,,g`)
+            echo "$missing" >> "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND"
+        fi
+    done
+
+    if [ -f "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND" ]; then
+        # print list of missing test executables
+        echo ""
+        echo "###################################################"
+        echo "Executables for following unit tests were not found"
+        echo -e "###################################################\E[31m\E[1m" ## set red color & bold
+        cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND
+        tput sgr0 # restore terminal defaults
+
+        # and save same list also to test summary file
+        echo "" >> $REPORT
+        echo "###################################################" >> $REPORT
+        echo "Executables for following unit tests were not found" >> $REPORT
+        echo "###################################################"  >> $REPORT
+        cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND  >> $REPORT
+    fi
+
+    # remove temporary files
+    rm $REPORT_PATH_ABSOLUTE/temp_*.txt
+
+    # tell that script reached the end
+    echo "" >> $REPORT
+    echo "All done!" >> $REPORT
+    echo ""
+    echo "All done!"
+else
+    echo "Paths for report and/or tests not found!"
+    echo "Script must be run from scripts directory"
+fi
+echo ""