MythTV  master
unittests.sh
Go to the documentation of this file.
1 #!/bin/sh
2 #
3 # unittests.sh runs all unit tests and returns 0 if all are successful
4 
5 DIRNAME=`which dirname`
6 BASENAME=`which basename`
7 SED=`which sed`
8 GCOV=`which gcov`
9 GREP=`which grep`
10 TEST_FAILED=0
11 
12 if test "x$(uname -s)" = "xFreeBSD"; then
13  # Find all shared libraries (".so" on linux/freebsd, ".dylib" on OSX).
14  # Eliminate multiples on OSX because of where the suffix is added.
15  DIRS=""
16  LIBS=$(find $(dirname $(pwd)) -name "*.so" -o -name "*.dylib")
17  for lib in $LIBS ; do
18  DIR=$(dirname $lib)
19  DIRS="$DIRS $DIR"
20  done
21  export LD_LIBRARY_PATH=$(echo ${DIRS} | tr ' ' ':')
22 fi
23 
24 TESTS=`find . -name "test_*.pro"`
25 
26 for TEST in $TESTS
27 do
28  FPATH=`$DIRNAME $TEST`
29  EXEC=`$BASENAME $TEST | $SED -e 's/\.pro//'`
30  COV=`$BASENAME $TEST | $SED -e 's/test_//' | $SED -e 's/\.pro/.cpp/'`
31  COVGCNO=`$BASENAME $TEST | $SED -e 's/test_//' | $SED -e 's/\.pro/.gcno/'`
32  RUNNABLE=$FPATH/$EXEC
33  if test -x $RUNNABLE -a -f $RUNNABLE ; then
34  if ./$RUNNABLE ; then
35  if test -x "$GCOV" -a -f $FPATH/$COVGCNO ; then
36  P=`pwd` ; cd $FPATH # pushd==
37  LINES=`$GCOV $COV | $GREP Lines | $SED -e 's/Lines//'`
38  echo Coverage: $COV $LINES. See $FPATH/$COV.gcov for details
39  cd $P # popd==
40  fi
41  echo
42  else
43  echo "error: A unit test failed."
44  TEST_FAILED=1
45  fi
46  else
47  echo "Unable to find test $RUNNABLE, marking as a failed unit test."
48  TEST_FAILED=1
49  fi
50 done
51 
52 if test "x$TEST_FAILED" != "x0" ; then
53  echo "error: At least one unit test failed, returning 1"
54 fi
55 
56 exit $TEST_FAILED