9556853ef596e2a803facaa62719c8d17c0f9f3a
[racktables] / tests / express.sh
1 #!/bin/sh
2
3 THISDIR=`dirname $0`
4 BASEDIR=`readlink -f "$THISDIR/.."`
5 : ${PHPUNIT_BIN:=phpunit}
6
7 case `"$PHPUNIT_BIN" --version` in
8 'PHPUnit 4.'*|'PHPUnit 5.'*)
9 BOOTSTRAP_FILE=bootstrap_v4v5.php
10 ;;
11 'PHPUnit 6.'*|'PHPUnit 7.'*)
12 BOOTSTRAP_FILE=bootstrap_v6v7.php
13 ;;
14 *)
15 echo 'ERROR: failed to find a known version of PHPUnit'
16 "$PHPUNIT_BIN" --version
17 exit 5
18 esac
19
20 echo "Running express tests using the base directory '$BASEDIR'"
21 echo "and PHPUnit bootstrap file '$BOOTSTRAP_FILE'."
22
23 # Every file in wwwroot/inc/ must be a valid PHP input file and must not
24 # produce any output when parsed by PHP (because, for instance, a plain text
25 # file is a valid PHP input file).
26 echo
27 cd "$BASEDIR"
28 files=0
29 errors=0
30 TEMPFILE=`mktemp /tmp/racktables_unittest.XXXXXX`
31 FORMAT='%-40s : %s\n'
32 for f in wwwroot/inc/*.php plugins/*/plugin.php; do
33 if [ "$f" = "wwwroot/inc/init.php" ]; then
34 printf "$FORMAT" "$f" 'not tested'
35 continue # see below
36 fi
37 fname=`basename "$f"`
38 cd `dirname "$f"`
39 php "$fname" > "$TEMPFILE"
40 rc=$?
41 if [ $rc -eq 0 -a ! -s "$TEMPFILE" ]; then
42 printf "$FORMAT" "$f" 'OK'
43 else
44 if [ $rc -ne 0 ]; then
45 printf "$FORMAT" "$f" "ERROR: PHP interpreter returned code $rc"
46 errors=`expr $errors + 1`
47 fi
48 if [ -s "$TEMPFILE" ]; then
49 printf "$FORMAT" "$f" 'ERROR: produces output when parsed'
50 errors=`expr $errors + 1`
51 fi
52 fi
53 files=`expr $files + 1`
54 cd "$BASEDIR"
55 done
56 for f in tests/*.php; do
57 if php --syntax-check "$f" >/dev/null 2>&1; then
58 printf "$FORMAT" "$f" 'OK (syntax only)'
59 else
60 printf "$FORMAT" "$f" "ERROR: PHP syntax check failed"
61 errors=`expr $errors + 1`
62 fi
63 files=`expr $files + 1`
64 done
65 echo '---------------------------------------------------'
66 echo "Files parsed: $files, failed tests: $errors"
67 rm -f "$TEMPFILE"
68 [ $errors -eq 0 ] || exit 1
69
70 # A side effect of syncdomain.php is testing whether init.php is functional.
71 echo
72 cd "$BASEDIR/wwwroot"
73 echo 'Testing syncdomain.php'; ../scripts/syncdomain.php --help || exit 1
74 echo 'Testing cleanup_ldap_cache.php'; ../scripts/cleanup_ldap_cache.php || exit 1
75 echo 'Testing reload_dictionary.php'; ../scripts/reload_dictionary.php || exit 1
76
77 # At this point it makes sense to test specific functions.
78 echo
79 cd "$BASEDIR/tests"
80 "$PHPUNIT_BIN" --group small --bootstrap $BOOTSTRAP_FILE || exit 1