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 paths, cut .pro extension
32 UNIT_TEST_PROJECTS=(`find $UNIT_TESTS_ROOT_DIR_ABSOLUTE | egrep \.pro$ | sed -e s,.pro$,,g`)
34 echo "###################################################"
35 echo "All unit test executables will be deleted"
36 echo "and qmake + make will be run for root tests.pro"
37 echo "###################################################"
40 # remove all unit test binaries
41 for BINARY in "${UNIT_TEST_PROJECTS[@]}"
43 # remove only if file really exists
44 if [ -a $BINARY ]; then
50 cd $UNIT_TESTS_ROOT_DIR_ABSOLUTE
56 echo "###################################################"
57 echo "Executing tests..."
58 echo "###################################################"
61 for PROJECT in "${UNIT_TEST_PROJECTS[@]}"
63 # do not try to test the root tests.pro project
64 if [ $PROJECT != "$UNIT_TESTS_ROOT_DIR_ABSOLUTE/tests" ]; then
65 # check if unit test file is found and is executable
66 if [ -x $PROJECT ]; then
67 # go to unit test directory
68 cd "`echo $PROJECT | grep --perl-regexp -o .*\(?=/\)`"
69 # run unit test, save to temp file, ignore strerr stream
70 $PROJECT -silent -o $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE 2>&1 | grep -v "atk_object_set_name..assertion"
72 # print to screen and append to summary
73 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE
74 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
75 echo "" >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
77 # save path of missing test to temporary file
78 MISSING=(`echo $PROJECT | sed -e s,$UNIT_TESTS_ROOT_DIR_ABSOLUTE,,g`)
79 echo "$MISSING" >> "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND"
84 if [ -f "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND" ]; then
85 # print list of missing test executables
87 echo "###################################################"
88 echo "Executables for following unit tests were not found"
89 echo -e "###################################################\E[31m\E[1m" ## set red color & bold
90 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND
91 tput sgr0 # restore terminal defaults
93 echo "Some possible causes:"
94 echo " - project has set target name explicitly. Target name must be same as the directory name"
95 echo " - don't use shadow build system"
96 echo " - test project is not included in the master test project (tests/tests.pro)"
98 # and save same list also to test summary file
100 echo "###################################################" >> $REPORT
101 echo "Executables for following unit tests were not found" >> $REPORT
102 echo "###################################################" >> $REPORT
103 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND >> $REPORT
106 # check if unit test output contained any qDebug or qWarning prints
107 DEBUG_COUNT=$(egrep -c "(QDEBUG|QWARN)" $REPORT_PATH_ABSOLUTE/$REPORT_FILE)
108 if [ $DEBUG_COUNT -ge 1 ]; then
110 # print message in red and bold
111 echo -e "\E[31m\E[1mDisable debug output from unit tests so test output stays readable!!!"
112 tput sgr0 # restore terminal defaults
115 # remove temporary files
116 rm $REPORT_PATH_ABSOLUTE/temp_*.txt
118 # remove all unit test binaries so they doesn't accidentally get into repository
119 for BINARY in "${UNIT_TEST_PROJECTS[@]}"
121 # remove only if file really exists
122 if [ -a $BINARY ]; then
127 # tell that script reached the end
129 echo "All done!" >> $REPORT
133 echo "Paths for report and/or tests not found!"
134 echo "Script must be run from scripts directory"