#!/bin/bash

TMPF=`mktemp -d $TMPDIR/php5-test-XXXXXX`
mkdir -p $TMPF/tmp
echo "Using directory $TMPF to run tests"
cd $TMPF
cp -a /usr/src/php-devel/* .
find extensions -type f -name '*.phpt' > bundled_extensions.txt
extra_extensions=`find /usr/share/doc/php-* -type d -name 'tests' | grep -v pear | sed -e 's/\/tests//'`
mkdir -p extra_extensions
cp -rp $extra_extensions extra_extensions/
find extra_extensions -type f -name '*.phpt' > extra_extensions.txt

echo "==============================================================================="
echo "Running standard tests"
TEST_PHP_EXECUTABLE='/usr/bin/php' /usr/bin/php run-tests.php -q -d session.save_path="$TMPF/tmp"

echo "==============================================================================="
echo "Running tests for the bundled extensions"
TEST_PHP_EXECUTABLE='/usr/bin/php' /usr/bin/php run-tests.php -d session.save_path="$TMPF/tmp" -d soap.wsdl_cache_dir="$TMPF/tmp" -l bundled_extensions.txt
echo "==============================================================================="
echo "Done... You must now evaluate any failed test."
echo "The failed tests are saved into the bundled_extensions.txt file"
echo "To run these tests again execute:"
echo "TEST_PHP_EXECUTABLE='/usr/bin/php' /usr/bin/php run-tests.php -d session.save_path=\"$TMPF/tmp\" -d soap.wsdl_cache_dir=\"$TMPF/tmp\" -l bundled_extensions.txt"

echo "==============================================================================="
echo "Running tests (if any) for the extra extensions"
TEST_PHP_EXECUTABLE='/usr/bin/php' /usr/bin/php run-tests.php -d session.save_path="$TMPF/tmp" -d soap.wsdl_cache_dir="$TMPF/tmp" -l extra_extensions.txt
echo "==============================================================================="
echo "Done... You must now evaluate any failed test."
echo "The failed tests are saved into the extra_extensions.txt file"
echo "To run these tests again execute:"
echo "TEST_PHP_EXECUTABLE='/usr/bin/php' /usr/bin/php run-tests.php -d session.save_path=\"$TMPF/tmp\" -d soap.wsdl_cache_dir=\"$TMPF/tmp\" -l extra_extensions.txt"

echo "==============================================================================="
echo " All tests has now been run."
echo " You must manually clean the created test directory, like so:"
echo " rm -rf $TMPF"
echo "==============================================================================="

