Permalink
Browse files

Add test target to base makefile and the libs makefile.

This introduces a script called unittests.sh which locates all files
matching test_*.pro and then runs the tests those are expected to
generate and complains if either the tests fail or it can't find
the test executable. This script is run on both make test in the
mythtv directory and make test in the mythtv/libs directory.

The lib*/test directories have been added to the subdirs that
libs.pro compiles and a clean of the test_mythtimer.pro target has
been added. This allows a make in mythtv or mythtv/libs to compile
the unit test and a make clean to remove it. It would be nice to
have these targets work from mythtv/libs/libmythbase, but I don't
know how to do that with the current .pro file arrangement.

Note: This and the MythTimer unit test are intended as templates
for other unit tests. Any suggestions for improvement are welcome.
  • Loading branch information...
1 parent a5d37fe commit 8e0a73d44ee19e4ac38cd74c0d926f213dcf9089 @daniel-kristjansson daniel-kristjansson committed with jyavenard Feb 20, 2013
View
@@ -93,3 +93,6 @@ uninstall: $(addsuffix _uninstall,$(SUBDIRS))
-rmdir $(INSTALL_ROOT)/${PREFIX}/include/mythtv
-rmdir $(INSTALL_ROOT)/${PREFIX}/lib/mythtv
-rmdir $(INSTALL_ROOT)/${PREFIX}/share/mythtv
+
+test:
+ -./programs/scripts/unittests.sh
@@ -0,0 +1,9 @@
+include (../../../settings.pro)
+
+TEMPLATE = subdirs
+
+SUBDIRS += test_*
+
+unittest.target = test
+unittest.commands = ../../../programs/scripts/unittests.sh
+unix:QMAKE_EXTRA_TARGETS += unittest
@@ -1,14 +1,16 @@
-include ( ../../../settings.pro )
+include ( ../../../../settings.pro )
CONFIG += qtestlib
TEMPLATE = app
TARGET = test_mythtimer
-DEPENDPATH += . ..
-INCLUDEPATH += . ..
+DEPENDPATH += . ../..
+INCLUDEPATH += . ../..
# Input
HEADERS += test_mythtimer.h
SOURCES += test_mythtimer.cpp
HEADERS += mythtimer.h
SOURCES += mythtimer.cpp
+
+QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2)
View
@@ -34,3 +34,10 @@ libmythmetadata.depends = $$LIBMYTHTVDEPS libmythtv
#libmythmediaserver
SUBDIRS += libmythprotoserver
libmythprotoserver.depends = $$LIBMYTHTVDEPS libmythtv
+
+# unit tests
+SUBDIRS += lib*/test
+
+unittest.target = test
+unittest.commands = ../programs/scripts/unittests.sh
+unix:QMAKE_EXTRA_TARGETS += unittest
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+# unittests.sh runs all unit tests and returns 0 if all are successful
+
+DIRNAME=`which dirname`
+BASENAME=`which basename`
+SED=`which sed`
+TEST_FAILED=0
+
+
+TESTS=`find -name "test_*.pro"`
+
+for TEST in $TESTS
+do
+ PATH=`$DIRNAME $TEST`
+ EXEC=`$BASENAME $TEST | $SED -e 's/.pro//'`
+ RUNNABLE=$PATH/$EXEC
+ if test -x $RUNNABLE -a -f $RUNNABLE ; then
+ if ./$RUNNABLE ; then
+ echo
+ else
+ echo "error: A unit test failed."
+ TEST_FAILED=1
+ fi
+ else
+ echo "Unable to find test $RUNNABLE, marking as a failed unit test."
+ TEST_FAILED=1
+ fi
+done
+
+if test "x$TEST_FAILED" != "x0" ; then
+ echo "error: At least one unit test failed, returning 1"
+fi
+
+exit $TEST_FAILED

0 comments on commit 8e0a73d

Please sign in to comment.