6 UNIT_TESTS_ROOT_DIR="../tests"
8 REPORT_FILE="unit_test_results.txt"
9 TEMP_FILE_EXEC_NOT_FOUND="temp_exec_not_found.txt"
10 TEMP_REPORT_FILE="temp_report.txt"
12 # check that directories are found
13 if [[ -d $REPORT_PATH && -d $UNIT_TESTS_ROOT_DIR ]]; then
14 # convert relational paths to absolute ones
15 UNIT_TESTS_ROOT_DIR_ABSOLUTE=`cd $UNIT_TESTS_ROOT_DIR; pwd`
16 REPORT_PATH_ABSOLUTE=`cd $REPORT_PATH; pwd`
17 REPORT="$REPORT_PATH_ABSOLUTE/$REPORT_FILE"
19 echo "Running recursively all tests under $UNIT_TESTS_ROOT_DIR_ABSOLUTE"
20 echo "Saving results to $REPORT"
23 # overwrite report summary file and write header
24 echo "##########################################" > $REPORT
25 echo "# Summary of unit tests executed" >> $REPORT
26 echo "# Date: `date`" >> $REPORT
27 echo "# User: `whoami`" >> $REPORT
28 echo "##########################################" >> $REPORT
31 # find all test .pro files pahts, cut .pro extension
32 UNIT_TEST_PROJECTS=(`find $UNIT_TESTS_ROOT_DIR_ABSOLUTE | egrep .pro$ | sed -e s/.pro//g`)
35 for project in "${UNIT_TEST_PROJECTS[@]}"
37 # do not try to test the root tests.pro project
38 if [ $project != "$UNIT_TESTS_ROOT_DIR_ABSOLUTE/tests" ]; then
39 # check if unit test file is found and is executable
40 if [ -x $project ]; then
42 # run unit test, save to temp file, ignore strerr stream
43 $project -silent -o $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE 2> /dev/null
44 # print to screen and append to summary
45 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE
46 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
47 echo "" >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
49 # save path of missing test to temporary file
50 missing=(`echo $project | sed -e s,$UNIT_TESTS_ROOT_DIR_ABSOLUTE,,g`)
51 echo "$missing" >> "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND"
56 if [ -f "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND" ]; then
57 # print list of missing test executables
59 echo "###################################################"
60 echo "Executables for following unit tests were not found"
61 echo -e "###################################################\E[31m\E[1m" ## set red color & bold
62 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND
63 tput sgr0 # restore terminal defaults
65 echo "Some possible causes:"
66 echo " - project has set target name explicitly. Target name must be same as directory name"
67 echo " - don't use shadow build system"
69 # and save same list also to test summary file
71 echo "###################################################" >> $REPORT
72 echo "Executables for following unit tests were not found" >> $REPORT
73 echo "###################################################" >> $REPORT
74 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND >> $REPORT
77 # check if unit test output contained any qDebug or qWarning prints
78 debugs=$(egrep -c "(QDEBUG|QWARN)" $REPORT_PATH_ABSOLUTE/$REPORT_FILE)
79 if [ $debugs -ge 1 ]; then
81 # print message in red and bold
82 echo -e "\E[31m\E[1mDisable debug output from unit tests so test output stays readable!!!"
83 tput sgr0 # restore terminal defaults
86 # remove temporary files
87 rm $REPORT_PATH_ABSOLUTE/temp_*.txt
89 # tell that script reached the end
91 echo "All done!" >> $REPORT
95 echo "Paths for report and/or tests not found!"
96 echo "Script must be run from scripts directory"