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 if [ -f $project ]; then
39 # run unit test, save to temp file, ignore strerr stream
40 $project -silent -o $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE 2> /dev/null
41 # print to screen and append to summary
42 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE
43 cat $REPORT_PATH_ABSOLUTE/$TEMP_REPORT_FILE >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
44 echo "" >> $REPORT_PATH_ABSOLUTE/$REPORT_FILE
46 # save path of missing test to temporary file
47 missing=(`echo $project | sed -e s,$UNIT_TESTS_ROOT_DIR_ABSOLUTE,,g`)
48 echo "$missing" >> "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND"
52 if [ -f "$REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND" ]; then
53 # print list of missing test executables
55 echo "###################################################"
56 echo "Executables for following unit tests were not found"
57 echo -e "###################################################\E[31m\E[1m" ## set red color & bold
58 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND
59 tput sgr0 # restore terminal defaults
61 # and save same list also to test summary file
63 echo "###################################################" >> $REPORT
64 echo "Executables for following unit tests were not found" >> $REPORT
65 echo "###################################################" >> $REPORT
66 cat $REPORT_PATH_ABSOLUTE/$TEMP_FILE_EXEC_NOT_FOUND >> $REPORT
69 # remove temporary files
70 rm $REPORT_PATH_ABSOLUTE/temp_*.txt
72 # tell that script reached the end
74 echo "All done!" >> $REPORT
78 echo "Paths for report and/or tests not found!"
79 echo "Script must be run from scripts directory"