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 MAKE_OPTIONS="-j3 -k -s -w"
16 # check that directories are found
17 if [[ -d $REPORT_PATH && -d $UNIT_TESTS_ROOT_DIR ]]; then
18 # convert relational paths to absolute ones
19 UNIT_TESTS_ROOT_DIR_ABSOLUTE=`cd $UNIT_TESTS_ROOT_DIR; pwd`
20 REPORT_PATH_ABSOLUTE=`cd $REPORT_PATH; pwd`
21 REPORT="$REPORT_PATH_ABSOLUTE/$REPORT_FILE"
23 echo "Running recursively all tests under $UNIT_TESTS_ROOT_DIR_ABSOLUTE"
24 echo "Saving results to $REPORT"
27 # overwrite report summary file and write header
28 echo "##########################################" > $REPORT
29 echo "# Summary of unit tests executed" >> $REPORT
30 echo "# Date: `date`" >> $REPORT
31 echo "# User: `whoami`" >> $REPORT
32 echo "##########################################" >> $REPORT
35 # find all test .pro files paths, cut .pro extension
36 UNIT_TEST_PROJECTS=(`find $UNIT_TESTS_ROOT_DIR_ABSOLUTE | egrep \.pro$ | sed -e s,.pro$,,g`)
38 echo "###################################################"
39 echo "All unit test executables will be deleted"
40 echo "and qmake + make will be run for root tests.pro"
41 echo "###################################################"
44 # remove all unit test binaries
45 for BINARY in "${UNIT_TEST_PROJECTS[@]}"
47 # remove only if file really exists
48 if [ -a $BINARY ]; then
54 cd $UNIT_TESTS_ROOT_DIR_ABSOLUTE
60 echo "###################################################"
61 echo "Executing tests..."
62 echo "###################################################"
65 for PROJECT in "${UNIT_TEST_PROJECTS[@]}"
67 # do not try to test the root tests.pro project
68 if [ $PROJECT != "$UNIT_TESTS_ROOT_DIR_ABSOLUTE/tests" ]; then
69 # check if unit test file is found and is executable
70 if [ -x $PROJECT ]; then
71 # go to unit test directory
72 cd "`echo $PROJECT | grep --perl-regexp -o .*\(?=/\)`"
73 # run unit test, save to temp file, ignore strerr stream
74 $PROJECT -silent -o $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE 2>&1 | grep -v -f $SCRIPT_DIR/filtering_patterns_for_unit_tests_output.txt
76 # print to screen and append to summary
77 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE
78 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
80 echo "" >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
82 # save path of missing test to temporary file
83 MISSING=(`echo $PROJECT | sed -e s,$UNIT_TESTS_ROOT_DIR_ABSOLUTE,,g`)
84 echo "$MISSING" >> "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND"
89 if [ -f "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND" ]; then
90 # print list of missing test executables
92 echo "###################################################"
93 echo "Executables for following unit tests were not found"
94 echo -e "###################################################\E[31m\E[1m" ## set red color & bold
95 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND
96 tput sgr0 # restore terminal defaults
98 echo "Some possible causes:"
99 echo " - project has set target name explicitly. Target name must be same as the directory name"
100 echo " - don't use shadow build system"
101 echo " - test project is not included in the master test project (tests/tests.pro)"
103 # and save same list also to test summary file
105 echo "###################################################" >> $REPORT
106 echo "Executables for following unit tests were not found" >> $REPORT
107 echo "###################################################" >> $REPORT
108 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND >> $REPORT
111 # check if unit test output contained any qDebug or qWarning prints
112 DEBUG_COUNT=$(egrep -c "(QDEBUG|QWARN)" $REPORT_PATH_ABSOLUTE/$REPORT_FILE)
113 if [ $DEBUG_COUNT -ge 1 ]; then
115 # print message in red and bold
116 echo -e "\E[31m\E[1mDisable debug output from unit tests so test output stays readable!!!"
117 tput sgr0 # restore terminal defaults
120 # remove temporary files
121 rm $REPORT_PATH_ABSOLUTE/temp_*.txt
123 # remove all unit test binaries so they doesn't accidentally get into repository
124 for BINARY in "${UNIT_TEST_PROJECTS[@]}"
126 # remove only if file really exists
127 if [ -a $BINARY ]; then
132 # tell that script reached the end
134 echo "All done!" >> $REPORT
138 echo "Paths for report and/or tests not found!"
139 echo "Script must be run from scripts directory"