perl: Improve run_tests.sh
authorMarcel Denia <naoir@gmx.net>
Wed, 1 Jul 2015 13:58:49 +0000 (15:58 +0200)
committerMarcel Denia <naoir@gmx.net>
Tue, 1 Sep 2015 07:23:24 +0000 (09:23 +0200)
- Add some useful options for debugging tests and test failures
- Properly handle tests located in lib/

Signed-off-by: Marcel Denia <naoir@gmx.net>
lang/perl/files/perl-run_tests.sh

index 288191b43fdf00bb0000dae8e9c0c67b9a2ceb23..bf83c0a3d1de28504bbe0dec4c8854a26ba23b17 100755 (executable)
@@ -4,8 +4,52 @@ PERL_TESTSDIR="/usr/share/perl/perl-tests"
 PERL_LIBDIR="/usr/lib/perl5/%%PERL_VERSION%%/"
 PERL_DISABLEDTESTS="%%PERL_DISABLEDTESTS%%"
 
+no_run=""
+manual_run=""
+manual_run_no_base=""
+
+while [ ! -z "$1" ]; do
+       case $1 in
+               -n)
+                       no_run="yes"
+                       ;;
+               -m)
+                       manual_run="yes"
+                       ;;
+               -mb)
+                       manual_run="yes"
+                       manual_run_no_base="yes"
+                       ;;
+               --help)
+                       echo "run_tests.sh [-n|-m|-mb|--help]"
+                       echo ""
+                       echo "Options:"
+                       echo "  -n        Just prepare the environment. Don't actually run any tests"
+                       echo "  -m        Run tests manually according to MANIFEST, instead of whatever t/TEST chooses"
+                       echo "  -mb       Don't run base tests. Implies -m"
+                       echo "  --help    Print this help ;)"
+                       echo ""
+                       exit 0
+                       ;;
+               *)
+                       echo "Invalid argument: $1"
+                       ;;
+       esac
+       shift
+done
+
 if [ ! -f "$PERL_TESTSDIR/__prepared" ]; then
-       ln -s "$PERL_LIBDIR" "$PERL_TESTSDIR/lib"
+       # Many tests insist on having PERL5LIB in $PERL_TESTSDIR/lib. However,
+       # that directory may also contain tests. Some of them(FindBin.t in particular)
+       # also demand being located in a directory ending with "lib". So we can't do symlink
+       # trickery here.
+       # Our solution is to just copy PERL5LIB over.
+       if [ -d "$PERL_TESTSDIR/lib" ]; then
+               cp -a "$PERL_LIBDIR/"* "$PERL_TESTSDIR/lib/"
+       else
+               ln -s "$PERL_LIBDIR" "$PERL_TESTSDIR/lib"
+       fi
+
        ln -s /usr/bin/perl "$PERL_TESTSDIR/perl"
        ln -s /usr/bin/perl "$PERL_TESTSDIR/t/perl"
        touch "$PERL_TESTSDIR/__prepared"
@@ -20,5 +64,18 @@ if [ ! -f "$PERL_TESTSDIR/__prepared" ]; then
        mv $PERL_TESTSDIR/MANIFEST_NEW $PERL_TESTSDIR/MANIFEST
 fi
 
-cd "$PERL_TESTSDIR/t"
-./perl TEST
+if [ -z "$no_run" ]; then
+       cd "$PERL_TESTSDIR/t"
+       if [ ! -z "$manual_run" ]; then
+               for i in $(cat ../MANIFEST | sed 's/\t.*$//g' | grep '\.t$'); do
+                       if [ ! -z "$manual_run_no_base" ] && [ ! -z "$(echo $i | grep '^t/')" ]; then
+                               continue;
+                       fi
+                       echo "Running $i"
+                       ./TEST ../$i
+                       echo ""
+               done
+       else
+               ./perl TEST
+       fi
+fi