com phpruntests: Code to generate phar and mods deal with phar relative path issues: .gitignore build.xml build/build.xml build/buildPhar.php
build/phpdefinitions.txt_sample phpdefinitions.txt_sa mple src/configuration/settings/rtTestDirectorySetting.php
src/configuration/settings/rtTestFileSetting.php src/tes trun/rtPhpTestRun.php tests/rtTestBootstrap.php
| From: | Zoe Slattery | Date: | Tue, 09 Oct 2012 12:34:11 +0000 |
| Subject: | com phpruntests: Code to generate phar and mods deal with phar relative path issues: .gitignore build.xml build/build.xml build/buildPhar.php build/phpdefinitions.txt_sample phpdefinitions.txt_sa mple src/configuration/settings/rtTestDirectorySetting.php src/configuration/settings/rtTestFileSetting.php src/tes trun/rtPhpTestRun.php tests/rtTestBootstrap.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66748@lists.php.net to get a copy of this message | ||
Commit: 5bfcd27d56f557e23760435c4fd0ca83f6d077ba
Author: zoe slattery <zoe@php.net> Tue, 9 Oct 2012 13:34:11 +0100
Parents: 2a000e34b920604b6633d5a96950d30fdd9285d0
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=5bfcd27d56f557e23760435c4fd0ca83f6d077ba
Log:
Code to generate phar and mods deal with phar relative path issues
Changed paths:
A .gitignore
D build.xml
A build/build.xml
A build/buildPhar.php
A build/phpdefinitions.txt_sample
D phpdefinitions.txt_sample
M src/configuration/settings/rtTestDirectorySetting.php
M src/configuration/settings/rtTestFileSetting.php
M src/testrun/rtPhpTestRun.php
M tests/rtTestBootstrap.php
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cb6c57 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build_output/* +.project + diff --git a/build.xml b/build.xml deleted file mode 100755 index c17a71d..0000000 --- a/build.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version="1.0"?> - -<project name="runtests" default="qa" basedir="."> -<property file="phpdefinitions.txt" /> - - <target name="clean"> - <delete dir="_compare" /> - <delete dir="_coverage" /> - <delete dir="_docs" /> - <delete dir="_sniff" /> - <delete dir="QA/ext" /> - <delete dir="QA/sapi" /> - <delete dir="QA/tests" /> - <delete dir="QA/Zend" /> - <delete> - <fileset dir="phpt-tests" includes="*.out" /> - <fileset dir="phpt-tests" includes="*.exp" /> - <fileset dir="phpt-tests" includes="*.diff" /> - <fileset dir="phpt-tests" includes="*.log" /> - <fileset dir="phpt-tests" includes="*.sh" /> - <fileset dir="phpt-tests" includes="*.post" /> - <fileset dir="phpt-tests" includes="*.php" /> - </delete> - </target> - - <target name="qa" depends="lint, test, coverage, compare, doc" description="Perform quality assurance."> - </target> - - <target name="doc" description="Create API documentation in _docs/html/."> - <delete dir="_docs" /> - <exec command="doxygen" checkReturn="true"/> - </target> - - <target name="lint" description="Lint check all PHP files."> - <phplint haltonfailure="true"> - <fileset dir="src"> - <include name="*.php"/> - <include name="**/*.php"/> - </fileset> - </phplint> - </target> - - <target name="test" description="Run all unit tests."> - <delete dir="_coverage" /> - <exec command="phpunit tests" passthru="true" checkReturn="true"/> - </target> - - <target name="coverage" description="Create code coverage report in _coverage."> - <delete dir="_coverage" /> - <exec command="phpunit --coverage-html _coverage tests" /> - </target> - - <target name="compare" description="Old/New comparison of phpt results."> - <fail unless="php" message="Path to standard PHP executable not defined, use -Dphp=/path/to/php" /> - <fail unless="php_to_test" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php/to/test" /> - <fail unless="php_source" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php_source_dir" /> - - - <delete dir="_compare" /> - <mkdir dir="_compare" /> - - <delete dir="${temp_directory}/phpruntests" /> - <mkdir dir="${temp_directory}/phpruntests" /> - - <echo msg="Copying QATESTS tar file to temporary directory" /> - - <copy file="${project.basedir}/QA/QATESTS.tgz" tofile="${temp_directory}/phpruntests/QATESTS.tgz" /> - - <echo msg="Extracting QATESTS.." /> - - <exec command="tar xfz QATESTS.tgz" dir="${temp_directory}/phpruntests" /> - - <echo msg="Running the tests using standard (old) run-tests.php.." /> - - <exec command="${php} -n ${php_source}/run-tests.php -n -p ${php_to_test} ${temp_directory}/phpruntests/Zend ${temp_directory}/phpruntests/ext ${temp_directory}/phpruntests/sapi ${temp_directory}/phpruntests/tests > ${project.basedir}/_compare/old.out" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true"/> - - <echo msg="Running the tests using new run-tests.php.." /> - - <exec command="${php} -n ${project.basedir}/src/run-tests.php -n -p ${php_to_test} -o csv -s ${project.basedir}/_compare/new.out ${temp_directory}/phpruntests" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true" /> - - <echo msg="Comparing the results from new and old runs" /> - - <exec command="${php} -n QA/compareNewOld.php ${project.basedir}/_compare/new.out ${project.basedir}/_compare/old.out phpruntests > ${project.basedir}/_compare/compare_new_old.out" dir="${project.basedir}" passthru="true" checkReturn="true"/> - - - </target> - - <target name="sniff" description="Run all PHP_CodeSniffer sniffs."> - <delete dir="_sniff" /> - <mkdir dir="_sniff" /> - - <exec command="phpcs -n --extensions=php --report=full src > ${project.basedir}/_sniff/sniff.out" passthru="true"/> - </target> - -</project> diff --git a/build/build.xml b/build/build.xml new file mode 100644 index 0000000..5dd285e --- /dev/null +++ b/build/build.xml @@ -0,0 +1,99 @@ +<?xml version="1.0"?> + +<project name="runtests" default="qa" basedir=".."> +<property file="build/phpdefinitions.txt" /> + + <target name="clean"> + <delete dir="_compare" /> + <delete dir="_coverage" /> + <delete dir="_docs" /> + <delete dir="_sniff" /> + <delete dir="QA/ext" /> + <delete dir="QA/sapi" /> + <delete dir="QA/tests" /> + <delete dir="QA/Zend" /> + <delete> + <fileset dir="phpt-tests" includes="*.out" /> + <fileset dir="phpt-tests" includes="*.exp" /> + <fileset dir="phpt-tests" includes="*.diff" /> + <fileset dir="phpt-tests" includes="*.log" /> + <fileset dir="phpt-tests" includes="*.sh" /> + <fileset dir="phpt-tests" includes="*.post" /> + <fileset dir="phpt-tests" includes="*.php" /> + </delete> + </target> + + <target name="qa" depends="lint, test, coverage, compare, doc" description="Perform quality assurance."> + </target> + + <target name="doc" description="Create API documentation in _docs/html/."> + <delete dir="_docs" /> + <exec command="doxygen" checkReturn="true"/> + </target> + + <target name="lint" description="Lint check all PHP files."> + <phplint haltonfailure="true"> + <fileset dir="src"> + <include name="*.php"/> + <include name="**/*.php"/> + </fileset> + </phplint> + </target> + + <target name="test" description="Run all unit tests."> + <delete dir="_coverage" /> + <exec command="phpunit tests" passthru="true" checkReturn="true"/> + </target> + + <target name="coverage" description="Create code coverage report in _coverage."> + <delete dir="_coverage" /> + <exec command="phpunit --coverage-html _coverage tests" /> + </target> + + <target name="compare" description="Old/New comparison of phpt results."> + <fail unless="php" message="Path to standard PHP executable not defined, use -Dphp=/path/to/php" /> + <fail unless="php_to_test" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php/to/test" /> + <fail unless="php_source" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php_source_dir" /> + + + <delete dir="_compare" /> + <mkdir dir="_compare" /> + + <delete dir="${temp_directory}/phpruntests" /> + <mkdir dir="${temp_directory}/phpruntests" /> + + <echo msg="Copying QATESTS tar file to temporary directory" /> + + <copy file="${project.basedir}/QA/QATESTS.tgz" tofile="${temp_directory}/phpruntests/QATESTS.tgz" /> + + <echo msg="Extracting QATESTS.." /> + + <exec command="tar xfz QATESTS.tgz" dir="${temp_directory}/phpruntests" /> + + <echo msg="Running the tests using standard (old) run-tests.php.." /> + + <exec command="${php} -n ${php_source}/run-tests.php -n -p ${php_to_test} ${temp_directory}/phpruntests/Zend ${temp_directory}/phpruntests/ext ${temp_directory}/phpruntests/sapi ${temp_directory}/phpruntests/tests > ${project.basedir}/_compare/old.out" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true"/> + + <echo msg="Running the tests using new run-tests.php.." /> + + <exec command="${php} -n ${project.basedir}/src/run-tests.php -n -p ${php_to_test} -o csv -s ${project.basedir}/_compare/new.out ${temp_directory}/phpruntests" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true" /> + + <echo msg="Comparing the results from new and old runs" /> + + <exec command="${php} -n QA/compareNewOld.php ${project.basedir}/_compare/new.out ${project.basedir}/_compare/old.out phpruntests > ${project.basedir}/_compare/compare_new_old.out" dir="${project.basedir}" passthru="true" checkReturn="true"/> + + + </target> + + <target name="sniff" description="Run all PHP_CodeSniffer sniffs."> + <delete dir="_sniff" /> + <mkdir dir="_sniff" /> + + <exec command="phpcs -n --extensions=php --report=full src > ${project.basedir}/_sniff/sniff.out" passthru="true"/> + </target> + + <target name="phar" description="Build run-tests.phar file"> + <exec command="${phpphar} ${project.basedir}/build/buildPhar.php ${project.basedir}/src ${project.basedir}/build_output" passthru="true" /> + </target> + +</project> diff --git a/build/buildPhar.php b/build/buildPhar.php new file mode 100644 index 0000000..67cef44 --- /dev/null +++ b/build/buildPhar.php @@ -0,0 +1,14 @@ +<?php + +$srcRoot = $argv[1]; +$targetRoot = $argv[2]; + +$targetname = $targetRoot . "/run-tests.phar"; + +if(file_exists($targetname)) { + unlink($targetname); +} +$phar = new Phar($targetname, FilesystemIterator::CURRENT_AS_FILEINFO| FilesystemIterator::KEY_AS_FILENAME, "run-tests.phar"); +$phar->setStub($phar->createDefaultStub("run-tests.php")); +$phar->buildFromDirectory($srcRoot,'/\.php$|\.txt$/'); +?> diff --git a/build/phpdefinitions.txt_sample b/build/phpdefinitions.txt_sample new file mode 100644 index 0000000..5cf6d34 --- /dev/null +++ b/build/phpdefinitions.txt_sample @@ -0,0 +1,27 @@ +# This file is used as a phing property file and is also read by rtTestBoootstrap.php to determine which +# PHP exectables to use in running unit tests + +#These are example settings, you will change them to the right paths on your system +#then copy this to phpdefinitions.txt +# +#The version of PHP that you are using to run unit tests +php=/usr/local/php540naked/bin/php +# +#The version of PHP that you intend to test +php_to_test=/usr/local/php5xx/bin/php +# +#The version of PHP CGI that you intend to test +php_cgi_to_test=/usr/local/php5xx/bin/php-cgi +# +#The version of PHP that you are using to build the phar file. NB php.ini must have phar.readonly = 0; +phpphar=/usr/bin/php +# +#If the versions of PHP that you intent to test have NOT been +#built --with-zlib, put zlib=0 on the next line. +zlib=1 +# +#The location of a copy run-tests.php for running comparison results (qa target) +php_source=/Users/zoe/Workspaces/php-src +# +#Temporary (writable) directory - also used buy qa target +temp_directory=/tmp diff --git a/phpdefinitions.txt_sample b/phpdefinitions.txt_sample deleted file mode 100644 index 3363812..0000000 --- a/phpdefinitions.txt_sample +++ /dev/null @@ -1,24 +0,0 @@ -# This file is used as a phing property file and is also read by rtTestBoootstrap.php to determine which -# PHP exectables to use in running unit tests - -#These are example settings, you will change them to the right paths on your system -#then copy this to phpdefinitions.txt -# -#The version of PHP that you are using to run unit tests -php=/usr/local/php540naked/bin/php -# -#The version of PHP that you intend to test -php_to_test=/usr/local/php5xx/bin/php -# -#The version of PHP CGI that you intend to test -php_cgi_to_test=/usr/local/php5xx/bin/php-cgi -# -#If the versions of PHP that you intent to test have NOT been -#built --with-zlib, put zlib=0 on the next line. -zlib=1 -# -#The location of a copy run-tests.php for running comparison results (qa target) -php_source=/Users/zoe/Workspaces/php-src -# -#Temporary (writable) directory - also used buy qa target -temp_directory=/tmp diff --git a/src/configuration/settings/rtTestDirectorySetting.php b/src/configuration/settings/rtTestDirectorySetting.php index f2cce9f..690e491 100644 --- a/src/configuration/settings/rtTestDirectorySetting.php +++ b/src/configuration/settings/rtTestDirectorySetting.php @@ -29,6 +29,17 @@ class rtTestDirectorySetting extends rtSetting public function init(rtRuntestsConfiguration $configuration) { $fileArray = $configuration->getTestFilename(); + + //phar does not understand relative paths, so if we have just given a relative path from the + //currrent working directory phar will not find the file. Here, if the file does not exist + //but a file with cwd prepended does, we reset the name with the cwd prepend. + for ($i=0; $i<count($fileArray); $i++) { + if(!file_exists($fileArray[$i])) { + if(file_exists($configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i])) + $fileArray[$i] = $configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i]; + } + } + foreach ($fileArray as $file) { if (is_dir($file)) { diff --git a/src/configuration/settings/rtTestFileSetting.php b/src/configuration/settings/rtTestFileSetting.php index d6e747f..bdf80da 100644 --- a/src/configuration/settings/rtTestFileSetting.php +++ b/src/configuration/settings/rtTestFileSetting.php @@ -29,6 +29,18 @@ class rtTestFileSetting extends rtSetting public function init(rtRuntestsConfiguration $configuration) { $fileArray = $configuration->getTestFilename(); + + //phar does not understand relative paths, so if we have just given a relative path from the + //currrent working directory phar will not find the file. Here, if the file does not exist + //but a file with cwd prepended does, we reset the name with the cwd prepend. + //TODO: If this only applies to phar is there a better way? + + for ($i=0; $i<count($fileArray); $i++) { + if(!file_exists($fileArray[$i])) { + if(file_exists($configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i])) + $fileArray[$i] = $configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i]; + } + } foreach ($fileArray as $fn) { if (!is_dir($fn) && substr($fn, -5) == ".phpt") { diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index 8b4c358..d42094c 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -64,6 +64,7 @@ class rtPhpTestRun //Set reporting option $this->setReportStatus(); + /* * Main decision point. Either we start this with a directory (or set of directories, in which case tests are @@ -194,8 +195,8 @@ class rtPhpTestRun //This section deals with running single test cases, or lists of test cases. foreach ($testNames as $testName) { - - if (!file_exists($testName)) { + + if (!file_exists($testName)) { echo rtText::get('invalidTestFileName', array($testName)); exit(); } @@ -240,6 +241,8 @@ class rtPhpTestRun } public function buildSubDirectoryList($testDirectories){ + + $subDirectories = array(); foreach ($testDirectories as $testDirectory) { $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory)); diff --git a/tests/rtTestBootstrap.php b/tests/rtTestBootstrap.php index 2e2d90f..7251a61 100644 --- a/tests/rtTestBootstrap.php +++ b/tests/rtTestBootstrap.php @@ -5,8 +5,8 @@ require_once __DIR__ . '/../src/rtAutoload.php'; /** * Check to see if the PHP and CGI executables are in a config file */ -if(file_exists(__DIR__ . '/../phpdefinitions.txt')) { - $phpdefs=file(__DIR__ . '/../phpdefinitions.txt'); +if(file_exists(__DIR__ . '/../build/phpdefinitions.txt')) { + $phpdefs=file(__DIR__ . '/../build/phpdefinitions.txt'); foreach($phpdefs as $line) { if(preg_match('/^php_to_test=(.*)/', $line, $matches)) { define('RT_PHP_PATH', trim($matches[1])); @@ -19,6 +19,6 @@ if(file_exists(__DIR__ . '/../phpdefinitions.txt')) { } } } else { - echo "You must provide PHP versions in phpdefinitions.txt\n"; + echo "You must provide PHP versions in build/phpdefinitions.txt\n"; } ?>
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2cb6c57 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build_output/* +.project + diff --git a/build.xml b/build.xml deleted file mode 100755 index c17a71d..0000000 --- a/build.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version="1.0"?> - -<project name="runtests" default="qa" basedir="."> -<property file="phpdefinitions.txt" /> - - <target name="clean"> - <delete dir="_compare" /> - <delete dir="_coverage" /> - <delete dir="_docs" /> - <delete dir="_sniff" /> - <delete dir="QA/ext" /> - <delete dir="QA/sapi" /> - <delete dir="QA/tests" /> - <delete dir="QA/Zend" /> - <delete> - <fileset dir="phpt-tests" includes="*.out" /> - <fileset dir="phpt-tests" includes="*.exp" /> - <fileset dir="phpt-tests" includes="*.diff" /> - <fileset dir="phpt-tests" includes="*.log" /> - <fileset dir="phpt-tests" includes="*.sh" /> - <fileset dir="phpt-tests" includes="*.post" /> - <fileset dir="phpt-tests" includes="*.php" /> - </delete> - </target> - - <target name="qa" depends="lint, test, coverage, compare, doc" description="Perform quality assurance."> - </target> - - <target name="doc" description="Create API documentation in _docs/html/."> - <delete dir="_docs" /> - <exec command="doxygen" checkReturn="true"/> - </target> - - <target name="lint" description="Lint check all PHP files."> - <phplint haltonfailure="true"> - <fileset dir="src"> - <include name="*.php"/> - <include name="**/*.php"/> - </fileset> - </phplint> - </target> - - <target name="test" description="Run all unit tests."> - <delete dir="_coverage" /> - <exec command="phpunit tests" passthru="true" checkReturn="true"/> - </target> - - <target name="coverage" description="Create code coverage report in _coverage."> - <delete dir="_coverage" /> - <exec command="phpunit --coverage-html _coverage tests" /> - </target> - - <target name="compare" description="Old/New comparison of phpt results."> - <fail unless="php" message="Path to standard PHP executable not defined, use -Dphp=/path/to/php" /> - <fail unless="php_to_test" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php/to/test" /> - <fail unless="php_source" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php_source_dir" /> - - - <delete dir="_compare" /> - <mkdir dir="_compare" /> - - <delete dir="${temp_directory}/phpruntests" /> - <mkdir dir="${temp_directory}/phpruntests" /> - - <echo msg="Copying QATESTS tar file to temporary directory" /> - - <copy file="${project.basedir}/QA/QATESTS.tgz" tofile="${temp_directory}/phpruntests/QATESTS.tgz" /> - - <echo msg="Extracting QATESTS.." /> - - <exec command="tar xfz QATESTS.tgz" dir="${temp_directory}/phpruntests" /> - - <echo msg="Running the tests using standard (old) run-tests.php.." /> - - <exec command="${php} -n ${php_source}/run-tests.php -n -p ${php_to_test} ${temp_directory}/phpruntests/Zend ${temp_directory}/phpruntests/ext ${temp_directory}/phpruntests/sapi ${temp_directory}/phpruntests/tests > ${project.basedir}/_compare/old.out" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true"/> - - <echo msg="Running the tests using new run-tests.php.." /> - - <exec command="${php} -n ${project.basedir}/src/run-tests.php -n -p ${php_to_test} -o csv -s ${project.basedir}/_compare/new.out ${temp_directory}/phpruntests" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true" /> - - <echo msg="Comparing the results from new and old runs" /> - - <exec command="${php} -n QA/compareNewOld.php ${project.basedir}/_compare/new.out ${project.basedir}/_compare/old.out phpruntests > ${project.basedir}/_compare/compare_new_old.out" dir="${project.basedir}" passthru="true" checkReturn="true"/> - - - </target> - - <target name="sniff" description="Run all PHP_CodeSniffer sniffs."> - <delete dir="_sniff" /> - <mkdir dir="_sniff" /> - - <exec command="phpcs -n --extensions=php --report=full src > ${project.basedir}/_sniff/sniff.out" passthru="true"/> - </target> - -</project> diff --git a/build/build.xml b/build/build.xml new file mode 100644 index 0000000..5dd285e --- /dev/null +++ b/build/build.xml @@ -0,0 +1,99 @@ +<?xml version="1.0"?> + +<project name="runtests" default="qa" basedir=".."> +<property file="build/phpdefinitions.txt" /> + + <target name="clean"> + <delete dir="_compare" /> + <delete dir="_coverage" /> + <delete dir="_docs" /> + <delete dir="_sniff" /> + <delete dir="QA/ext" /> + <delete dir="QA/sapi" /> + <delete dir="QA/tests" /> + <delete dir="QA/Zend" /> + <delete> + <fileset dir="phpt-tests" includes="*.out" /> + <fileset dir="phpt-tests" includes="*.exp" /> + <fileset dir="phpt-tests" includes="*.diff" /> + <fileset dir="phpt-tests" includes="*.log" /> + <fileset dir="phpt-tests" includes="*.sh" /> + <fileset dir="phpt-tests" includes="*.post" /> + <fileset dir="phpt-tests" includes="*.php" /> + </delete> + </target> + + <target name="qa" depends="lint, test, coverage, compare, doc" description="Perform quality assurance."> + </target> + + <target name="doc" description="Create API documentation in _docs/html/."> + <delete dir="_docs" /> + <exec command="doxygen" checkReturn="true"/> + </target> + + <target name="lint" description="Lint check all PHP files."> + <phplint haltonfailure="true"> + <fileset dir="src"> + <include name="*.php"/> + <include name="**/*.php"/> + </fileset> + </phplint> + </target> + + <target name="test" description="Run all unit tests."> + <delete dir="_coverage" /> + <exec command="phpunit tests" passthru="true" checkReturn="true"/> + </target> + + <target name="coverage" description="Create code coverage report in _coverage."> + <delete dir="_coverage" /> + <exec command="phpunit --coverage-html _coverage tests" /> + </target> + + <target name="compare" description="Old/New comparison of phpt results."> + <fail unless="php" message="Path to standard PHP executable not defined, use -Dphp=/path/to/php" /> + <fail unless="php_to_test" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php/to/test" /> + <fail unless="php_source" message="Path to test PHP source dir not defined, use -Dphp_to_test=/path/to/php_source_dir" /> + + + <delete dir="_compare" /> + <mkdir dir="_compare" /> + + <delete dir="${temp_directory}/phpruntests" /> + <mkdir dir="${temp_directory}/phpruntests" /> + + <echo msg="Copying QATESTS tar file to temporary directory" /> + + <copy file="${project.basedir}/QA/QATESTS.tgz" tofile="${temp_directory}/phpruntests/QATESTS.tgz" /> + + <echo msg="Extracting QATESTS.." /> + + <exec command="tar xfz QATESTS.tgz" dir="${temp_directory}/phpruntests" /> + + <echo msg="Running the tests using standard (old) run-tests.php.." /> + + <exec command="${php} -n ${php_source}/run-tests.php -n -p ${php_to_test} ${temp_directory}/phpruntests/Zend ${temp_directory}/phpruntests/ext ${temp_directory}/phpruntests/sapi ${temp_directory}/phpruntests/tests > ${project.basedir}/_compare/old.out" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true"/> + + <echo msg="Running the tests using new run-tests.php.." /> + + <exec command="${php} -n ${project.basedir}/src/run-tests.php -n -p ${php_to_test} -o csv -s ${project.basedir}/_compare/new.out ${temp_directory}/phpruntests" dir="${temp_directory}/phpruntests" passthru="true" checkReturn="true" /> + + <echo msg="Comparing the results from new and old runs" /> + + <exec command="${php} -n QA/compareNewOld.php ${project.basedir}/_compare/new.out ${project.basedir}/_compare/old.out phpruntests > ${project.basedir}/_compare/compare_new_old.out" dir="${project.basedir}" passthru="true" checkReturn="true"/> + + + </target> + + <target name="sniff" description="Run all PHP_CodeSniffer sniffs."> + <delete dir="_sniff" /> + <mkdir dir="_sniff" /> + + <exec command="phpcs -n --extensions=php --report=full src > ${project.basedir}/_sniff/sniff.out" passthru="true"/> + </target> + + <target name="phar" description="Build run-tests.phar file"> + <exec command="${phpphar} ${project.basedir}/build/buildPhar.php ${project.basedir}/src ${project.basedir}/build_output" passthru="true" /> + </target> + +</project> diff --git a/build/buildPhar.php b/build/buildPhar.php new file mode 100644 index 0000000..67cef44 --- /dev/null +++ b/build/buildPhar.php @@ -0,0 +1,14 @@ +<?php + +$srcRoot = $argv[1]; +$targetRoot = $argv[2]; + +$targetname = $targetRoot . "/run-tests.phar"; + +if(file_exists($targetname)) { + unlink($targetname); +} +$phar = new Phar($targetname, FilesystemIterator::CURRENT_AS_FILEINFO| FilesystemIterator::KEY_AS_FILENAME, "run-tests.phar"); +$phar->setStub($phar->createDefaultStub("run-tests.php")); +$phar->buildFromDirectory($srcRoot,'/\.php$|\.txt$/'); +?> diff --git a/build/phpdefinitions.txt_sample b/build/phpdefinitions.txt_sample new file mode 100644 index 0000000..5cf6d34 --- /dev/null +++ b/build/phpdefinitions.txt_sample @@ -0,0 +1,27 @@ +# This file is used as a phing property file and is also read by rtTestBoootstrap.php to determine which +# PHP exectables to use in running unit tests + +#These are example settings, you will change them to the right paths on your system +#then copy this to phpdefinitions.txt +# +#The version of PHP that you are using to run unit tests +php=/usr/local/php540naked/bin/php +# +#The version of PHP that you intend to test +php_to_test=/usr/local/php5xx/bin/php +# +#The version of PHP CGI that you intend to test +php_cgi_to_test=/usr/local/php5xx/bin/php-cgi +# +#The version of PHP that you are using to build the phar file. NB php.ini must have phar.readonly = 0; +phpphar=/usr/bin/php +# +#If the versions of PHP that you intent to test have NOT been +#built --with-zlib, put zlib=0 on the next line. +zlib=1 +# +#The location of a copy run-tests.php for running comparison results (qa target) +php_source=/Users/zoe/Workspaces/php-src +# +#Temporary (writable) directory - also used buy qa target +temp_directory=/tmp diff --git a/phpdefinitions.txt_sample b/phpdefinitions.txt_sample deleted file mode 100644 index 3363812..0000000 --- a/phpdefinitions.txt_sample +++ /dev/null @@ -1,24 +0,0 @@ -# This file is used as a phing property file and is also read by rtTestBoootstrap.php to determine which -# PHP exectables to use in running unit tests - -#These are example settings, you will change them to the right paths on your system -#then copy this to phpdefinitions.txt -# -#The version of PHP that you are using to run unit tests -php=/usr/local/php540naked/bin/php -# -#The version of PHP that you intend to test -php_to_test=/usr/local/php5xx/bin/php -# -#The version of PHP CGI that you intend to test -php_cgi_to_test=/usr/local/php5xx/bin/php-cgi -# -#If the versions of PHP that you intent to test have NOT been -#built --with-zlib, put zlib=0 on the next line. -zlib=1 -# -#The location of a copy run-tests.php for running comparison results (qa target) -php_source=/Users/zoe/Workspaces/php-src -# -#Temporary (writable) directory - also used buy qa target -temp_directory=/tmp diff --git a/src/configuration/settings/rtTestDirectorySetting.php b/src/configuration/settings/rtTestDirectorySetting.php index f2cce9f..690e491 100644 --- a/src/configuration/settings/rtTestDirectorySetting.php +++ b/src/configuration/settings/rtTestDirectorySetting.php @@ -29,6 +29,17 @@ class rtTestDirectorySetting extends rtSetting public function init(rtRuntestsConfiguration $configuration) { $fileArray = $configuration->getTestFilename(); + + //phar does not understand relative paths, so if we have just given a relative path from the + //currrent working directory phar will not find the file. Here, if the file does not exist + //but a file with cwd prepended does, we reset the name with the cwd prepend. + for ($i=0; $i<count($fileArray); $i++) { + if(!file_exists($fileArray[$i])) { + if(file_exists($configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i])) + $fileArray[$i] = $configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i]; + } + } + foreach ($fileArray as $file) { if (is_dir($file)) { diff --git a/src/configuration/settings/rtTestFileSetting.php b/src/configuration/settings/rtTestFileSetting.php index d6e747f..bdf80da 100644 --- a/src/configuration/settings/rtTestFileSetting.php +++ b/src/configuration/settings/rtTestFileSetting.php @@ -29,6 +29,18 @@ class rtTestFileSetting extends rtSetting public function init(rtRuntestsConfiguration $configuration) { $fileArray = $configuration->getTestFilename(); + + //phar does not understand relative paths, so if we have just given a relative path from the + //currrent working directory phar will not find the file. Here, if the file does not exist + //but a file with cwd prepended does, we reset the name with the cwd prepend. + //TODO: If this only applies to phar is there a better way? + + for ($i=0; $i<count($fileArray); $i++) { + if(!file_exists($fileArray[$i])) { + if(file_exists($configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i])) + $fileArray[$i] = $configuration->getSetting('CurrentDirectory') . '/' . $fileArray[$i]; + } + } foreach ($fileArray as $fn) { if (!is_dir($fn) && substr($fn, -5) == ".phpt") { diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index 8b4c358..d42094c 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -64,6 +64,7 @@ class rtPhpTestRun //Set reporting option $this->setReportStatus(); + /* * Main decision point. Either we start this with a directory (or set of directories, in which case tests are @@ -194,8 +195,8 @@ class rtPhpTestRun //This section deals with running single test cases, or lists of test cases. foreach ($testNames as $testName) { - - if (!file_exists($testName)) { + + if (!file_exists($testName)) { echo rtText::get('invalidTestFileName', array($testName)); exit(); } @@ -240,6 +241,8 @@ class rtPhpTestRun } public function buildSubDirectoryList($testDirectories){ + + $subDirectories = array(); foreach ($testDirectories as $testDirectory) { $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory)); diff --git a/tests/rtTestBootstrap.php b/tests/rtTestBootstrap.php index 2e2d90f..7251a61 100644 --- a/tests/rtTestBootstrap.php +++ b/tests/rtTestBootstrap.php @@ -5,8 +5,8 @@ require_once __DIR__ . '/../src/rtAutoload.php'; /** * Check to see if the PHP and CGI executables are in a config file */ -if(file_exists(__DIR__ . '/../phpdefinitions.txt')) { - $phpdefs=file(__DIR__ . '/../phpdefinitions.txt'); +if(file_exists(__DIR__ . '/../build/phpdefinitions.txt')) { + $phpdefs=file(__DIR__ . '/../build/phpdefinitions.txt'); foreach($phpdefs as $line) { if(preg_match('/^php_to_test=(.*)/', $line, $matches)) { define('RT_PHP_PATH', trim($matches[1])); @@ -19,6 +19,6 @@ if(file_exists(__DIR__ . '/../phpdefinitions.txt')) { } } } else { - echo "You must provide PHP versions in phpdefinitions.txt\n"; + echo "You must provide PHP versions in build/phpdefinitions.txt\n"; } ?>