com phpruntests: Adding and testing code to read skipif.inc files to enable whole directory skips: build/build.xml phpt-tests/group_of_
tests/sample_test.phpt phpt-tests/group_of_tests/skip if.inc src/run-tests.php src/testcase/rtTestOutputWrite r.php
src/testgroup/rtGroupConfiguration.php src/testgr oup/rtGroupResults.php src/testgroup/rtPhpTestGroup.php src/testrun/rtPhpTestRun.php
tests/rtGroupConfigurationT est.php tests/rtPhpTestGroupTest.php
| From: | Zoe Slattery | Date: | Wed, 27 Feb 2013 16:52:34 +0000 |
| Subject: | com phpruntests: Adding and testing code to read skipif.inc files to enable whole directory skips: build/build.xml phpt-tests/group_of_ tests/sample_test.phpt phpt-tests/group_of_tests/skip if.inc src/run-tests.php src/testcase/rtTestOutputWrite r.php src/testgroup/rtGroupConfiguration.php src/testgr oup/rtGroupResults.php src/testgroup/rtPhpTestGroup.php src/testrun/rtPhpTestRun.php tests/rtGroupConfigurationT est.php tests/rtPhpTestGroupTest.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66819@lists.php.net to get a copy of this message | ||
Commit: 68730ea02f1d723b6bfa75055365add8fad7ebc0
Author: zoe slattery <zoe@php.net> Wed, 27 Feb 2013 16:52:34 +0000
Parents: 5b5cec2bc466d6fe9c9d5b4e6998bb0febff1c9c
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=68730ea02f1d723b6bfa75055365add8fad7ebc0
Log:
Adding and testing code to read skipif.inc files to enable whole directory skips
Changed paths:
M build/build.xml
A phpt-tests/group_of_tests/sample_test.phpt
A phpt-tests/group_of_tests/skipif.inc
M src/run-tests.php
M src/testcase/rtTestOutputWriter.php
M src/testgroup/rtGroupConfiguration.php
M src/testgroup/rtGroupResults.php
M src/testgroup/rtPhpTestGroup.php
M src/testrun/rtPhpTestRun.php
M tests/rtGroupConfigurationTest.php
M tests/rtPhpTestGroupTest.php
diff --git a/build/build.xml b/build/build.xml index 5dd285e..8dba21e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -32,7 +32,7 @@ </target> <target name="lint" description="Lint check all PHP files."> - <phplint haltonfailure="true"> + <phplint haltonfailure="true" level="debug"> <fileset dir="src"> <include name="*.php"/> <include name="**/*.php"/> diff --git a/phpt-tests/group_of_tests/sample_test.phpt b/phpt-tests/group_of_tests/sample_test.phpt new file mode 100644 index 0000000..06501aa --- /dev/null +++ b/phpt-tests/group_of_tests/sample_test.phpt @@ -0,0 +1,8 @@ +--TEST-- +Try a sample test +--FILE-- +<?php + echo "Hello world\n"; +?> +--EXPECT-- +Hello world diff --git a/phpt-tests/group_of_tests/skipif.inc b/phpt-tests/group_of_tests/skipif.inc new file mode 100644 index 0000000..67c8d2b --- /dev/null +++ b/phpt-tests/group_of_tests/skipif.inc @@ -0,0 +1,3 @@ +<?php + echo "skip me please \n"; +?> diff --git a/src/run-tests.php b/src/run-tests.php index 3d11d00..a93108c 100644 --- a/src/run-tests.php +++ b/src/run-tests.php @@ -20,8 +20,6 @@ function rtExceptionHandler(Exception $e) { set_exception_handler('rtExceptionHandler'); - - /* * check the version of the running php-executable and * ensure that is 5.3 or higher diff --git a/src/testcase/rtTestOutputWriter.php b/src/testcase/rtTestOutputWriter.php index 0623292..84314d1 100644 --- a/src/testcase/rtTestOutputWriter.php +++ b/src/testcase/rtTestOutputWriter.php @@ -98,7 +98,7 @@ abstract class rtTestOutputWriter * @param integer $processCount * @return string */ - public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount) + public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount, $skippedGroups) { // if the overview was already created retun it if (!is_null($this->overview)) { @@ -134,6 +134,12 @@ abstract class rtTestOutputWriter $str = ''; $str .= "\n\n----------------------------------------\n"; + $str .= "Number of skipped groups:"; + $blanks = 30 - strlen("Number of skipped groups:") - strlen(count($skippedGroups)); + $str = $this->writeBlanks($str, $blanks); + $str .= count($skippedGroups); + $str .= "\n----------------------------------------\n"; + $str .= "Tests:"; $blanks = 30 - strlen("Tests:") - strlen($count); $str = $this->writeBlanks($str, $blanks); @@ -194,9 +200,9 @@ abstract class rtTestOutputWriter } - public function printOverview($parallelGroups=NULL, $serialGroups = NULL, $processCount=NULL) { + public function printOverview($parallelGroups=NULL, $serialGroups = NULL, $processCount=NULL, $skippedGroups=null) { - print $this->getOverview($parallelGroups, $serialGroups, $processCount); + print $this->getOverview($parallelGroups, $serialGroups, $processCount, $skippedGroups); flush(); } diff --git a/src/testgroup/rtGroupConfiguration.php b/src/testgroup/rtGroupConfiguration.php index 4339ee2..c99f34f 100644 --- a/src/testgroup/rtGroupConfiguration.php +++ b/src/testgroup/rtGroupConfiguration.php @@ -21,6 +21,8 @@ class rtGroupConfiguration protected $isRedirect=false; protected $serialGroup=false; protected $redirectFromID = null; + protected $skipFile = ""; + protected $hasSkipCode = false; public function __construct($directory) @@ -29,8 +31,7 @@ class rtGroupConfiguration } public function parseRedirect(rtPHPTest $redirectedTest) { - //Going to assume that we have already parsed the SKIPIF (if it exists) - //var_dump($redirectedTest->getSection('REDIRECTTEST')->getContents()); + $name = $redirectedTest->getName(); $code = implode($redirectedTest->getSection('REDIRECTTEST')->getContents(), "\n"); @@ -75,7 +76,7 @@ class rtGroupConfiguration //Find the key in the full name of the test contains the redirect $position = strpos($name, $key); - //Take the root strng from before the key + //Take the root string from before the key $root=substr($name, 0, $position); $title = $redirectedTest->getSection('TEST')->getContents(); @@ -94,14 +95,22 @@ class rtGroupConfiguration } - public function parse() { - //Here insert code to read a config file from the test directory that determines whether the set of tests shoudl be run + public function parseConfiguration() { + //Here insert code to read a config file from the test directory that determines whether the set of tests should be run //in parallel or not? $this->serialGroup = false; + + + //Code to read the directory skipif, run it and skip the directory + if(file_exists($this->testDirectory. "/skipif.inc")) { + $this->hasSkipCode = true; + $this->skipFile = $this->testDirectory."/skipif.inc"; + } return; } + public function getEnvironmentVariables() { return $this->environmentVariables; } @@ -116,6 +125,12 @@ class rtGroupConfiguration } public function getRedirectFromID() { return $this->redirectFromID; - } + } + public function hasSkipCode() { + return $this->hasSkipCode; + } + public function getSkipFile() { + return $this->skipFile; + } } diff --git a/src/testgroup/rtGroupResults.php b/src/testgroup/rtGroupResults.php index 26e9f90..7218b70 100644 --- a/src/testgroup/rtGroupResults.php +++ b/src/testgroup/rtGroupResults.php @@ -22,6 +22,7 @@ class rtGroupResults protected $runOrder; protected $runByProcessor = 0; protected $absTime; + protected $isSkipGroup = false; public function __construct($gn) { $this->groupName = $gn; @@ -68,6 +69,10 @@ class rtGroupResults public function setProc($p) { $this->runByProcessor = $p; } + public function setSkip($s) { + $this->isSkipGroup = $s; + } + public function getTime() { return $this->timeToRun; } @@ -82,6 +87,9 @@ class rtGroupResults public function getAbsTime() { return $this->absTime; } + public function isSkipGroup() { + return $this->isSkipGroup; + } } \ No newline at end of file diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php index 012560d..900141c 100644 --- a/src/testgroup/rtPhpTestGroup.php +++ b/src/testgroup/rtPhpTestGroup.php @@ -19,112 +19,136 @@ class rtPhpTestGroup extends rtTask implements rtTaskInterface protected $runConfiguration; protected $groupConfiguration; protected $groupResults; - + + public function __construct(rtRuntestsConfiguration $runConfiguration, $directory, $groupConfiguration) { - $this->runConfiguration = $runConfiguration; + $this->runConfiguration = $runConfiguration; $this->testDirectory = $directory; - $this->groupConfiguration = $groupConfiguration; + $this->groupConfiguration = $groupConfiguration; $this->groupResults = new rtGroupResults($directory); $this->init(); } - + public function __destruct() { - unset ($this->testCases); - unset ($this->groupResults); - + unset ($this->testCases); + unset ($this->groupResults); + } - + public function init() - { - if($this->groupConfiguration->isRedirect()) { - //merge in environmental variables (this is for REDEIRRECT). - foreach($this->groupConfiguration->getEnvironmentVariables() as $key=>$value) { - $this->runConfiguration->setEnvironmentVariable($key, $value); - } - } - - - $this->testFiles = rtUtil::getTestList($this->testDirectory); - - $redirectFromID = $this->groupConfiguration->getRedirectFromID(); - - foreach ($this->testFiles as $testFileName) { - //echo "\n" .memory_get_usage() . ", setup start". $testFileName . "\n"; - - //testFiles is a list of file names relative to the current working directory - - if (!file_exists($testFileName)) { - echo rtText::get('invalidTestFileName', array($testFileName)); - exit(); + { + if($this->groupConfiguration->isRedirect()) { + //merge in environmental variables (this is for REDEIRRECT). + foreach($this->groupConfiguration->getEnvironmentVariables() as $key=>$value) { + $this->runConfiguration->setEnvironmentVariable($key, $value); } - - // Create a new test file object; - $testFile = new rtPhpTestFile(); - $testFile->doRead($testFileName); - $testFile->normaliseLineEndings(); - - //The test name is the full path to the test file name without the .phpt - - $testStatus = new rtTestStatus($testFile->getTestName()); - if ($testFile->arePreconditionsMet() ) { - // Create a new test case - $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus, $redirectFromID); - } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){ - //Redirect handler, save the test case for processing after the main groups have finished. - //Check to make sure that it shouldn't be skipped, if skipped don't save it - $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); - if($redirectedTest->hasSection('SKIPIF')) { - $redirectedTest->runSkipif($this->runConfiguration); - if($redirectedTest->getStatus()->getValue('skip')) { - $testStatus->setTrue('skip'); - $testStatus->setMessage('skip', $testFile->getExitMessage(). ' and the skip condition has failed'); - $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); - } else { - $testStatus->setTrue('redirected'); - $testStatus->setMessage('redirected', $testFile->getExitMessage()); - $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); - $this->groupResults->setRedirectedTestCase($redirectedTest); - } - - } + } + + if($this->groupConfiguration->hasSkipCode()) { - }else { - $testStatus->setTrue('bork'); - $testStatus->setMessage('bork', $testFile->getExitMessage()); - $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); - + //If there is some 'skip' code run it to see if the tests should be skipped and then do nothing else + + $phpCommand = $this->runConfiguration->getSetting('PhpExecutable'); + $arguments = preg_replace('/error_reporting=32767/', 'error_reporting=0', $this->runConfiguration->getSetting('PhpCommandLineArguments')); + + $phpCommand .= ' -f '.$this->groupConfiguration->getSkipFile(); + + $runner = new rtPhpRunner($phpCommand); + $result = $runner->runphp(); + + + if (preg_match('/^\s*skip\s*(.+)\s*/i', $result, $matches)) { + $this->groupResults->setSkip(true); + } + } + + + if($this->isSkipGroup() !== true) { + + $this->testFiles = rtUtil::getTestList($this->testDirectory); + + $redirectFromID = $this->groupConfiguration->getRedirectFromID(); + + foreach ($this->testFiles as $testFileName) { + //echo "\n" .memory_get_usage() . ", setup start". $testFileName . "\n"; + + //testFiles is a list of file names relative to the current working directory + + if (!file_exists($testFileName)) { + echo rtText::get('invalidTestFileName', array($testFileName)); + exit(); + } + + // Create a new test file object; + $testFile = new rtPhpTestFile(); + $testFile->doRead($testFileName); + $testFile->normaliseLineEndings(); + + //The test name is the full path to the test file name without the .phpt + + $testStatus = new rtTestStatus($testFile->getTestName()); + if ($testFile->arePreconditionsMet() ) { + // Create a new test case + $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus, $redirectFromID); + } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){ + //Redirect handler, save the test case for processing after the main groups have finished. + //Check to make sure that it shouldn't be skipped, if skipped don't save it + $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); + if($redirectedTest->hasSection('SKIPIF')) { + $redirectedTest->runSkipif($this->runConfiguration); + if($redirectedTest->getStatus()->getValue('skip')) { + $testStatus->setTrue('skip'); + $testStatus->setMessage('skip', $testFile->getExitMessage(). ' and the skip condition has failed'); + $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); + } else { + $testStatus->setTrue('redirected'); + $testStatus->setMessage('redirected', $testFile->getExitMessage()); + $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); + $this->groupResults->setRedirectedTestCase($redirectedTest); + } + + } + + } else { + $testStatus->setTrue('bork'); + $testStatus->setMessage('bork', $testFile->getExitMessage()); + $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); + + } + //echo "\n" .memory_get_usage() . ", setup complete". $testFileName . "\n"; + } } } public function run() { - $s=microtime(true); - + $s=microtime(true); + if (count($this->testCases) == 0) { return; } - + for($i=0; $i<count($this->testCases); $i++) { - - $testCase = $this->testCases[$i]; + + $testCase = $this->testCases[$i]; $testCase->executeTest($this->runConfiguration); - - + + $testResult = new rtTestResults($testCase); $testResult->processResults($testCase, $this->runConfiguration); - $this->groupResults->setTestStatus($testCase->getName(), $testResult->getStatus()); - - + $this->groupResults->setTestStatus($testCase->getName(), $testResult->getStatus()); + + } - + $e=microtime(true); - + $this->groupResults->setTime($e-$s); $this->groupResults->setAbsTime($e); } @@ -134,19 +158,23 @@ class rtPhpTestGroup extends rtTask implements rtTaskInterface $testOutputWriter = rtTestOutputWriter::getInstance($this->groupResults->getTestStatusList(), $outType); $testOutputWriter->write($this->testDirectory, $cid); } - - + + public function getTestCases() { - return $this->testCases; + return $this->testCases; } - + public function getGroupName() { - return $this->testDirectory; + return $this->testDirectory; } - - public function getGroupResults() { - return $this->groupResults; + + public function getGroupResults() { + return $this->groupResults; } - + + public function isSkipGroup() { + return $this->groupResults->isSkipGroup(); + } + } ?> diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index b95a987..f26b1f3 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -15,397 +15,410 @@ */ class rtPhpTestRun { - protected $commandLineArguments; - protected $runConfiguration; - protected $redirectedTestCases = array(); - protected $resultList = array(); //An array of arrays of Group Results - protected $serialTasks = array(); - protected $parallelTasks = array(); - protected $reportStatus = 0; - protected $numberOfSerialGroups = 0; - protected $numberOfParallelGroups = 0; - protected $processorCount; - protected $runStartTime; - - public function __construct($argv) - { - $this->commandLineArguments = $argv; - } - - public function run() - { + protected $commandLineArguments; + protected $runConfiguration; + protected $redirectedTestCases = array(); + protected $resultList = array(); //An array of arrays of Group Results + protected $serialTasks = array(); + protected $parallelTasks = array(); + protected $reportStatus = 0; + protected $numberOfSerialGroups = 0; + protected $numberOfParallelGroups = 0; + protected $processorCount; + protected $runStartTime; + protected $skippedGroups = array(); + + public function __construct($argv) + { + $this->commandLineArguments = $argv; + } + + public function run() + { $this->runStartTime = microtime(true); - //Set SSH variables - - // check the operation-system (win/unix) - $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix'; - - //Configure the test environment - $this->runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os); - $this->runConfiguration->getUserEnvironment(); - $this->runConfiguration->configure(); - - - - //Check help message - if($this->runConfiguration->hasCommandLineOption('help') || $this->runConfiguration->hasCommandLineOption('h')) { - echo rtText::get('help'); - exit; - } - - //Check the preconditions - $preConditionList = rtPreConditionList::getInstance($os); - $preConditionList->adaptList(); - - // $preConditionList->check($this->commandLine, $this->environmentVariables); - $preConditionList->check($this->runConfiguration); - - //Write PHP executable name to the array of env variables. Some - //test cases expect to be able to use it. - $php = $this->runConfiguration->getSetting('PhpExecutable'); - $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php); - - //Set reporting option - $this->setReportStatus(); - - $this->processorCount = $this->requestedProcessorCount(); - + //Set SSH variables + + // check the operation-system (win/unix) + $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix'; + + //Configure the test environment + $this->runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os); + $this->runConfiguration->getUserEnvironment(); + $this->runConfiguration->configure(); + + + + //Check help message + if($this->runConfiguration->hasCommandLineOption('help') || $this->runConfiguration->hasCommandLineOption('h')) { + echo rtText::get('help'); + exit; + } + + //Check the preconditions + $preConditionList = rtPreConditionList::getInstance($os); + $preConditionList->adaptList(); + + // $preConditionList->check($this->commandLine, $this->environmentVariables); + $preConditionList->check($this->runConfiguration); + + //Write PHP executable name to the array of env variables. Some + //test cases expect to be able to use it. + $php = $this->runConfiguration->getSetting('PhpExecutable'); + $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php); + + //Set reporting option + $this->setReportStatus(); + + $this->processorCount = $this->requestedProcessorCount(); + /* - * Main decision point. Either we start this with a directory (or set of directories, in which case tests are + * Main decision point. Either we start this with a directory (or set of directories, in which case tests are * run as a group (and in parallel if required) or...... - */ - if ($this->runConfiguration->getSetting('TestDirectories') != null) { - - $this->doGroupRuns(); - - } else { - - /* - *... the input is a test file, or list of files and are just run as single tests - * and not in parallel - */ - if ($this->runConfiguration->getSetting('TestFiles') == null) { - echo rtText::get('invalidTestFileName'); - exit(); - }else{ - $this->run_tests($this->runConfiguration->getSetting('TestFiles')); - } - } - - if(count($this->redirectedTestCases) > 0) { - $this->doRedirectedRuns(); - } - - if(($this->numberOfSerialGroups != 0) || ($this->numberOfParallelGroups != 0)) { - $this->createRunOutput(); - } - - } - - public function doGroupRuns() { - - $subDirectories = $this->buildSubDirectoryList($this->runConfiguration->getSetting('TestDirectories')); - $groupConfigurations = $this->buildGroupConfigurations($subDirectories); - - //If there is only one subdirectory, run seqential - - if(count($subDirectories) === 1) { - $this->run_serial_groups($subDirectories, $groupConfigurations); - $this->numberOfSerialGroups = 1; - - } else { - - //check to see if this is set to be a parallel run, if not, run the subdirectory groups in sequence. - if($this->processorCount <= 1) { - $this->run_serial_groups($subDirectories, $groupConfigurations); - $this->numberOfSerialGroups = count($subDirectories); - } else { - //At least part of this run can be in parallel, check group configurations to make sure that none are set to be serial. - //This builds parallel and serial task lists. - foreach($groupConfigurations as $key=>$gc) { - if($gc->isSerial()) { - $serialGroups[] = $key; - } else { - $parallelGroups[] = $key; - } - } - - if(isset($serialGroups)) {$this->numberOfSerialGroups = count($serialGroups);} - - $this->numberOfParallelGroups = count($parallelGroups); - - $this->run_parallel_groups($parallelGroups, $groupConfigurations, $this->processorCount); - if($this->numberOfSerialGroups > 0) { - $this->run_serial_groups($serialGroups, $groupConfigurations); - } - } - } - - } - - public function doRedirectedRuns() { - foreach($this->redirectedTestCases as $testCase){ - - $groupConfig = new rtGroupConfiguration(null); - $groupConfig->parseRedirect($testCase); - - $group = $groupConfig->getTestDirectory(); - - $this->run_serial_groups(array($group), array($group=>$groupConfig)); - - $this->numberOfSerialGroups++; - - } - } - - public function run_parallel_groups($testDirectories, $groupConfigurations, $processCount) { - - // create the task-list - $taskList = array(); - foreach($testDirectories as $testGroup) { - $taskList[] = new rtTaskTestGroup($this->runConfiguration, $testGroup, $groupConfigurations[$testGroup]); - } - - // run the task-scheduler - $scheduler = rtTaskScheduler::getInstance(); - $scheduler->setTaskList($taskList); - $scheduler->setProcessCount($processCount); - $scheduler->setReportStatus($this->reportStatus); - $scheduler->run(); - - foreach($scheduler->getResultList() as $groupResult) { - - $this->resultList[] = $groupResult->getTestStatusList(); - - // Debug - get which group was run by which processor and how long each took - // - - if($this->runConfiguration->hasCommandLineOption('debug')) { - $time = round($groupResult->getTime(), 2); - - $absTime = $groupResult->getAbsTime() - $this->runStartTime; - - $absTime = round($absTime, 2); - - echo "\nPARDBG," . $absTime. "," . $time . "," . $groupResult->getProcessorId() . "," . $groupResult->getRunOrder() . "," . $groupResult->getGroupName(); - - } - - $redirects = $groupResult->getRedirectedTestCases(); - foreach($redirects as $testCase) { - $this->redirectedTestCases[] = $testCase; - } - } - - - - } - - public function run_serial_groups($testDirectories, $groupConfigurations) { - - $count = 0; - - - //xdebug_start_trace('/tmp/memorycheck'); - - foreach($testDirectories as $subDirectory) { - - - - - // Memory usage debugging - //$startm = memory_get_usage(); - - - $testGroup = new rtPhpTestGroup($this->runConfiguration, $subDirectory, $groupConfigurations[$subDirectory]); - $testGroup->run(); - - // Memory usage debugging - //$midm = memory_get_usage(); - - - rtTestOutputWriter::flushResult($testGroup->getGroupResults()->getTestStatusList(), $this->reportStatus); - $this->resultList[] = $testGroup->getGroupResults()->getTestStatusList(); - - if($this->runConfiguration->hasCommandLineOption('debug')) { - - $time = round($testGroup->getGroupResults()->getTime(), 2); - - $absTime = ($testGroup->getGroupResults()->getAbsTime()) - $this->runStartTime; - $absTime = round($absTime, 2); - - - echo "\nSERDBG," . $absTime . "," . $time . "," . $testGroup->getGroupResults()->getProcessorId() . "," . $count . "," . $testGroup->getGroupResults()->getGroupName(); - - } - - // Memory usage debugging - //$midm2 = memory_get_usage(); - - $redirects = $testGroup->getGroupResults()->getRedirectedTestCases(); - foreach($redirects as $testCase) { - $this->redirectedTestCases[] = $testCase; - } - - // Memory usage debugging - //$midm3 = memory_get_usage(); - - - $testGroup->__destruct(); - unset($testGroup); - - // Memory usage debugging - //echo "\n" . $startm . ", " . $midm. ", " .$midm2. ", " .$midm3. ", " .memory_get_usage() . ", ". $subDirectory . "\n"; - $count++; - } - - //xdebug_stop_trace(); - } - - public function run_tests($testNames) { - - //This section deals with running single test cases, or lists of test cases. - - foreach ($testNames as $testName) { + */ + if ($this->runConfiguration->getSetting('TestDirectories') != null) { + + $this->doGroupRuns(); + + } else { + + /* + *... the input is a test file, or list of files and are just run as single tests + * and not in parallel + */ + if ($this->runConfiguration->getSetting('TestFiles') == null) { + echo rtText::get('invalidTestFileName'); + exit(); + }else{ + $this->run_tests($this->runConfiguration->getSetting('TestFiles')); + } + } + + if(count($this->redirectedTestCases) > 0) { + $this->doRedirectedRuns(); + } + + if(($this->numberOfSerialGroups != 0) || ($this->numberOfParallelGroups != 0)) { + $this->createRunOutput(); + } + + } + + public function doGroupRuns() { + + $subDirectories = $this->buildSubDirectoryList($this->runConfiguration->getSetting('TestDirectories')); + + //An array of group configuration objects, one for each subdirectory. + $groupConfigurations = $this->buildGroupConfigurations($subDirectories); + + + //If there is only one subdirectory, run seqential + + if(count($subDirectories) === 1) { + $this->run_serial_groups($subDirectories, $groupConfigurations); + $this->numberOfSerialGroups = 1; + + } else { + + //check to see if this is set to be a parallel run, if not, run the subdirectory groups in sequence. + if($this->processorCount <= 1) { + $this->run_serial_groups($subDirectories, $groupConfigurations); + $this->numberOfSerialGroups = count($subDirectories); + } else { + //At least part of this run can be in parallel, check group configurations to make sure that none are set to be serial. + //This builds parallel and serial task lists. + foreach($groupConfigurations as $key=>$gc) { + if($gc->isSerial()) { + $serialGroups[] = $key; + } else { + $parallelGroups[] = $key; + } + } + + if(isset($serialGroups)) {$this->numberOfSerialGroups = count($serialGroups);} + + $this->numberOfParallelGroups = count($parallelGroups); + + $this->run_parallel_groups($parallelGroups, $groupConfigurations, $this->processorCount); + if($this->numberOfSerialGroups > 0) { + $this->run_serial_groups($serialGroups, $groupConfigurations); + } + } + } + + } + + public function doRedirectedRuns() { + foreach($this->redirectedTestCases as $testCase){ + + $groupConfig = new rtGroupConfiguration(null); + $groupConfig->parseRedirect($testCase); + + $group = $groupConfig->getTestDirectory(); + + $this->run_serial_groups(array($group), array($group=>$groupConfig)); + + $this->numberOfSerialGroups++; + + } + } + + public function run_parallel_groups($testDirectories, $groupConfigurations, $processCount) { - if (!file_exists($testName)) { - echo rtText::get('invalidTestFileName', array($testName)); - exit(); - } - - - //Read the test file - $testFile = new rtPhpTestFile(); - $testFile->doRead($testName); - $testFile->normaliseLineEndings(); - - $testStatus = new rtTestStatus($testFile->getTestName()); - - - if ($testFile->arePreconditionsMet()) { - $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); - - //Setup and set the local environment for the test case - $testCase->executeTest($this->runConfiguration); - - $results = new rtTestResults($testCase); - $results->processResults($testCase, $this->runConfiguration); - $summaryResults = array($testFile->getTestName() => $results->getStatus()); - - } elseif (in_array("REDIRECTTEST", $testFile->getSectionHeadings())) { - - //Redirect handler - //Build a list of redirected test cases - - $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); - - $testStatus->setTrue('redirected'); - $testStatus->setMessage('redirected', $testFile->getExitMessage()); - $summaryResults = array($testFile->getTestName() => $testStatus); - - } else { - $testStatus->setTrue('bork'); - $testStatus->setMessage('bork', $testFile->getExitMessage()); - $summaryResults = array($testFile->getTestName() => $testStatus); - } + // create the task-list + $taskList = array(); + foreach($testDirectories as $testGroup) { + $taskList[] = new rtTaskTestGroup($this->runConfiguration, $testGroup, $groupConfigurations[$testGroup]); + } + + // run the task-scheduler + $scheduler = rtTaskScheduler::getInstance(); + $scheduler->setTaskList($taskList); + $scheduler->setProcessCount($processCount); + $scheduler->setReportStatus($this->reportStatus); + $scheduler->run(); + + foreach($scheduler->getResultList() as $groupResult) { + + if($groupResult->isSkipGroup()) { + $this->skippedGroups[] = $groupResult->getGroupName(); + } else { + $this->resultList[] = $groupResult->getTestStatusList(); + } + + // Debug - get which group was run by which processor and how long each took + // + + if($this->runConfiguration->hasCommandLineOption('debug')) { + $time = round($groupResult->getTime(), 2); + + $absTime = $groupResult->getAbsTime() - $this->runStartTime; + + $absTime = round($absTime, 2); + + echo "\nPARDBG," . $absTime. "," . $time . "," . $groupResult->getProcessorId() . "," . $groupResult->getRunOrder() . "," . $groupResult->getGroupName(); + + } + + $redirects = $groupResult->getRedirectedTestCases(); + foreach($redirects as $testCase) { + $this->redirectedTestCases[] = $testCase; + } + } + + + + } + + public function run_serial_groups($testDirectories, $groupConfigurations) { + + $count = 0; + + foreach($testDirectories as $subDirectory) { + + // Memory usage debugging + //$startm = memory_get_usage(); + + + + $testGroup = new rtPhpTestGroup($this->runConfiguration, $subDirectory, $groupConfigurations[$subDirectory]); - rtTestOutputWriter::flushResult($summaryResults, 3); - - } - } - - public function buildSubDirectoryList($testDirectories){ - - - $subDirectories = array(); - foreach ($testDirectories as $testDirectory) { - $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory)); - } - return $subDirectories; - } - - public function requestedProcessorCount() { - // check for the cmd-line-option 'z' which defines parellel-execution - $processCount = 0; - if ($this->runConfiguration->hasCommandLineOption('z')) { - - $processCount = intval($this->runConfiguration->getCommandLineOption('z')); - - if (!is_numeric($processCount) || $processCount < 0) { - $processCount = 2; - } - } - return $processCount; - } - - public function buildGroupConfigurations($subDirectories) { - $groupConfigurations = array(); - foreach($subDirectories as $subDir) { - $groupConfig = new rtGroupConfiguration($subDir); - $groupConfig->parse(); - $groupConfigurations[$subDir] = $groupConfig; - } - return $groupConfigurations; - } - - public function buildRedirectsList($results) { - foreach ($results as $groupResult) { - foreach($groupResult as $testResult) { - if($testResult->getStatus() == 'redirected') { - $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); - } - } - } - } - - public function createRunOutput() { - $type = null; - if ($this->runConfiguration->hasCommandLineOption('o')) { - $type = $this->runConfiguration->getCommandLineOption('o'); - } - - $outputWriter = rtTestOutputWriter::getInstance($type); - $outputWriter->setResultList($this->resultList); - - $outputWriter->printOverview($this->numberOfParallelGroups, $this->numberOfSerialGroups, $this->processorCount); - - $filename = null; - if ($this->runConfiguration->hasCommandLineOption('s')) { - $filename = $this->runConfiguration->getCommandLineOption('s'); - } - - if ($type || $filename) { - $outputWriter->write($filename); - } - } - - public function setReportStatus() { - // check for the cmd-line-option 'v' which defines the report-status - if ($this->runConfiguration->hasCommandLineOption('v')) { - $this->reportStatus = 1; - } else if ($this->runConfiguration->hasCommandLineOption('vv')) { - $this->reportStatus = 2; - } else if ($this->runConfiguration->hasCommandLineOption('vvv')) { - $this->reportStatus = 3; - } - - //Set the default for runs from 'make test' - if ( file_exists(getcwd() . "/sapi/cli/php")) { - $this->reportStatus = 1; - } - } - - public function extractResults($groupResult) { - $groupSummary = array(); - foreach($groupResult as $testResult) { - $groupSummary[$testResult->getName()] = $testResult->getStatus(); - if($testResult->getStatus() == 'redirected') { - $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); - } - } - return $groupSummary; - } - + + if($testGroup->isSkipGroup() == true) { + $this->skippedGroups[] = $testGroup->getGroupName(); + } else { + + + $testGroup->run(); + + + // Memory usage debugging + //$midm = memory_get_usage(); + + rtTestOutputWriter::flushResult($testGroup->getGroupResults()->getTestStatusList(), $this->reportStatus); + $this->resultList[] = $testGroup->getGroupResults()->getTestStatusList(); + + if($this->runConfiguration->hasCommandLineOption('debug')) { + + $time = round($testGroup->getGroupResults()->getTime(), 2); + + $absTime = ($testGroup->getGroupResults()->getAbsTime()) - $this->runStartTime; + $absTime = round($absTime, 2); + + + echo "\nSERDBG," . $absTime . "," . $time . "," . $testGroup->getGroupResults()->getProcessorId() . "," . $count . "," . $testGroup->getGroupResults()->getGroupName(); + + } + + // Memory usage debugging + //$midm2 = memory_get_usage(); + + $redirects = $testGroup->getGroupResults()->getRedirectedTestCases(); + foreach($redirects as $testCase) { + $this->redirectedTestCases[] = $testCase; + } + + + + // Memory usage debugging + //$midm3 = memory_get_usage(); + + + $testGroup->__destruct(); + unset($testGroup); + + // Memory usage debugging + //echo "\n" . $startm . ", " . $midm. ", " .$midm2. ", " .$midm3. ", " .memory_get_usage() . ", ". $subDirectory . "\n"; + $count++; + } + } + + //xdebug_stop_trace(); + } + + public function run_tests($testNames) { + + //This section deals with running single test cases, or lists of test cases. + + foreach ($testNames as $testName) { + + if (!file_exists($testName)) { + echo rtText::get('invalidTestFileName', array($testName)); + exit(); + } + + + //Read the test file + $testFile = new rtPhpTestFile(); + $testFile->doRead($testName); + $testFile->normaliseLineEndings(); + + $testStatus = new rtTestStatus($testFile->getTestName()); + + + if ($testFile->arePreconditionsMet()) { + $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); + + //Setup and set the local environment for the test case + $testCase->executeTest($this->runConfiguration); + + $results = new rtTestResults($testCase); + $results->processResults($testCase, $this->runConfiguration); + $summaryResults = array($testFile->getTestName() => $results->getStatus()); + + } elseif (in_array("REDIRECTTEST", $testFile->getSectionHeadings())) { + + //Redirect handler + //Build a list of redirected test cases + + $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); + + $testStatus->setTrue('redirected'); + $testStatus->setMessage('redirected', $testFile->getExitMessage()); + $summaryResults = array($testFile->getTestName() => $testStatus); + + } else { + $testStatus->setTrue('bork'); + $testStatus->setMessage('bork', $testFile->getExitMessage()); + $summaryResults = array($testFile->getTestName() => $testStatus); + } + + rtTestOutputWriter::flushResult($summaryResults, 3); + + } + } + + public function buildSubDirectoryList($testDirectories){ + + + $subDirectories = array(); + foreach ($testDirectories as $testDirectory) { + $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory)); + } + return $subDirectories; + } + + public function requestedProcessorCount() { + // check for the cmd-line-option 'z' which defines parellel-execution + $processCount = 0; + if ($this->runConfiguration->hasCommandLineOption('z')) { + + $processCount = intval($this->runConfiguration->getCommandLineOption('z')); + + if (!is_numeric($processCount) || $processCount < 0) { + $processCount = 2; + } + } + return $processCount; + } + + public function buildGroupConfigurations($subDirectories) { + $groupConfigurations = array(); + foreach($subDirectories as $subDir) { + $groupConfig = new rtGroupConfiguration($subDir); + $groupConfig->parseConfiguration(); + $groupConfigurations[$subDir] = $groupConfig; + } + return $groupConfigurations; + } + + public function buildRedirectsList($results) { + foreach ($results as $groupResult) { + foreach($groupResult as $testResult) { + if($testResult->getStatus() == 'redirected') { + $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); + } + } + } + } + + public function createRunOutput() { + $type = null; + if ($this->runConfiguration->hasCommandLineOption('o')) { + $type = $this->runConfiguration->getCommandLineOption('o'); + } + + $outputWriter = rtTestOutputWriter::getInstance($type); + $outputWriter->setResultList($this->resultList); + + $outputWriter->printOverview($this->numberOfParallelGroups, $this->numberOfSerialGroups, $this->processorCount, $this->skippedGroups); + + $filename = null; + if ($this->runConfiguration->hasCommandLineOption('s')) { + $filename = $this->runConfiguration->getCommandLineOption('s'); + } + + if ($type || $filename) { + $outputWriter->write($filename); + } + } + + public function setReportStatus() { + // check for the cmd-line-option 'v' which defines the report-status + if ($this->runConfiguration->hasCommandLineOption('v')) { + $this->reportStatus = 1; + } else if ($this->runConfiguration->hasCommandLineOption('vv')) { + $this->reportStatus = 2; + } else if ($this->runConfiguration->hasCommandLineOption('vvv')) { + $this->reportStatus = 3; + } + + //Set the default for runs from 'make test' + if ( file_exists(getcwd() . "/sapi/cli/php")) { + $this->reportStatus = 1; + } + } + + public function extractResults($groupResult) { + $groupSummary = array(); + foreach($groupResult as $testResult) { + $groupSummary[$testResult->getName()] = $testResult->getStatus(); + if($testResult->getStatus() == 'redirected') { + $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); + } + } + return $groupSummary; + } + } ?> diff --git a/tests/rtGroupConfigurationTest.php b/tests/rtGroupConfigurationTest.php index a08e5fb..7d4d6cd 100644 --- a/tests/rtGroupConfigurationTest.php +++ b/tests/rtGroupConfigurationTest.php @@ -3,12 +3,26 @@ require_once dirname(__FILE__) . '/../src/rtAutoload.php'; require_once dirname(__FILE__) . '/rtTestBootstrap.php'; class rtGroupConfigurationTest extends PHPUnit_Framework_TestCase + { + protected $path_to_group; + + public function setUp() { + $this->path_to_group = realpath(dirname(__FILE__) . '/../phpt-tests/group_of_tests'); + } + public function testCreateInstance() { - //$directory = realpath(dirname(__FILE__) . '/../phpt-tests'); $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, 'testgroup')); - $config->configure(); + $config->configure(); + + $groupConfig = new rtGroupConfiguration($this->path_to_group); + + $groupConfig->parseConfiguration(); + + $this->assertTrue(file_exists($groupConfig->getSkipFile())); + $this->assertTrue($groupConfig->hasSkipCode()); + } } \ No newline at end of file diff --git a/tests/rtPhpTestGroupTest.php b/tests/rtPhpTestGroupTest.php index 6fd8a6f..629cd92 100644 --- a/tests/rtPhpTestGroupTest.php +++ b/tests/rtPhpTestGroupTest.php @@ -53,6 +53,20 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase } } + public function testSkipGroup() { + $directory = realpath(dirname(__FILE__) . '/../phpt-tests/group_of_tests'); + $run_config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, $directory)); + + $run_config->configure(); + + $group_config = new rtGroupConfiguration($directory); + $group_config->parseConfiguration(); + + $phpTestGroup = new rtPhpTestGroup($run_config, $directory, $group_config); + $phpTestGroup->init(); + + $this->assertTrue($phpTestGroup->isSkipGroup()); + } }
diff --git a/build/build.xml b/build/build.xml index 5dd285e..8dba21e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -32,7 +32,7 @@ </target> <target name="lint" description="Lint check all PHP files."> - <phplint haltonfailure="true"> + <phplint haltonfailure="true" level="debug"> <fileset dir="src"> <include name="*.php"/> <include name="**/*.php"/> diff --git a/phpt-tests/group_of_tests/sample_test.phpt b/phpt-tests/group_of_tests/sample_test.phpt new file mode 100644 index 0000000..06501aa --- /dev/null +++ b/phpt-tests/group_of_tests/sample_test.phpt @@ -0,0 +1,8 @@ +--TEST-- +Try a sample test +--FILE-- +<?php + echo "Hello world\n"; +?> +--EXPECT-- +Hello world diff --git a/phpt-tests/group_of_tests/skipif.inc b/phpt-tests/group_of_tests/skipif.inc new file mode 100644 index 0000000..67c8d2b --- /dev/null +++ b/phpt-tests/group_of_tests/skipif.inc @@ -0,0 +1,3 @@ +<?php + echo "skip me please \n"; +?> diff --git a/src/run-tests.php b/src/run-tests.php index 3d11d00..a93108c 100644 --- a/src/run-tests.php +++ b/src/run-tests.php @@ -20,8 +20,6 @@ function rtExceptionHandler(Exception $e) { set_exception_handler('rtExceptionHandler'); - - /* * check the version of the running php-executable and * ensure that is 5.3 or higher diff --git a/src/testcase/rtTestOutputWriter.php b/src/testcase/rtTestOutputWriter.php index 0623292..84314d1 100644 --- a/src/testcase/rtTestOutputWriter.php +++ b/src/testcase/rtTestOutputWriter.php @@ -98,7 +98,7 @@ abstract class rtTestOutputWriter * @param integer $processCount * @return string */ - public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount) + public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount, $skippedGroups) { // if the overview was already created retun it if (!is_null($this->overview)) { @@ -134,6 +134,12 @@ abstract class rtTestOutputWriter $str = ''; $str .= "\n\n----------------------------------------\n"; + $str .= "Number of skipped groups:"; + $blanks = 30 - strlen("Number of skipped groups:") - strlen(count($skippedGroups)); + $str = $this->writeBlanks($str, $blanks); + $str .= count($skippedGroups); + $str .= "\n----------------------------------------\n"; + $str .= "Tests:"; $blanks = 30 - strlen("Tests:") - strlen($count); $str = $this->writeBlanks($str, $blanks); @@ -194,9 +200,9 @@ abstract class rtTestOutputWriter } - public function printOverview($parallelGroups=NULL, $serialGroups = NULL, $processCount=NULL) { + public function printOverview($parallelGroups=NULL, $serialGroups = NULL, $processCount=NULL, $skippedGroups=null) { - print $this->getOverview($parallelGroups, $serialGroups, $processCount); + print $this->getOverview($parallelGroups, $serialGroups, $processCount, $skippedGroups); flush(); } diff --git a/src/testgroup/rtGroupConfiguration.php b/src/testgroup/rtGroupConfiguration.php index 4339ee2..c99f34f 100644 --- a/src/testgroup/rtGroupConfiguration.php +++ b/src/testgroup/rtGroupConfiguration.php @@ -21,6 +21,8 @@ class rtGroupConfiguration protected $isRedirect=false; protected $serialGroup=false; protected $redirectFromID = null; + protected $skipFile = ""; + protected $hasSkipCode = false; public function __construct($directory) @@ -29,8 +31,7 @@ class rtGroupConfiguration } public function parseRedirect(rtPHPTest $redirectedTest) { - //Going to assume that we have already parsed the SKIPIF (if it exists) - //var_dump($redirectedTest->getSection('REDIRECTTEST')->getContents()); + $name = $redirectedTest->getName(); $code = implode($redirectedTest->getSection('REDIRECTTEST')->getContents(), "\n"); @@ -75,7 +76,7 @@ class rtGroupConfiguration //Find the key in the full name of the test contains the redirect $position = strpos($name, $key); - //Take the root strng from before the key + //Take the root string from before the key $root=substr($name, 0, $position); $title = $redirectedTest->getSection('TEST')->getContents(); @@ -94,14 +95,22 @@ class rtGroupConfiguration } - public function parse() { - //Here insert code to read a config file from the test directory that determines whether the set of tests shoudl be run + public function parseConfiguration() { + //Here insert code to read a config file from the test directory that determines whether the set of tests should be run //in parallel or not? $this->serialGroup = false; + + + //Code to read the directory skipif, run it and skip the directory + if(file_exists($this->testDirectory. "/skipif.inc")) { + $this->hasSkipCode = true; + $this->skipFile = $this->testDirectory."/skipif.inc"; + } return; } + public function getEnvironmentVariables() { return $this->environmentVariables; } @@ -116,6 +125,12 @@ class rtGroupConfiguration } public function getRedirectFromID() { return $this->redirectFromID; - } + } + public function hasSkipCode() { + return $this->hasSkipCode; + } + public function getSkipFile() { + return $this->skipFile; + } } diff --git a/src/testgroup/rtGroupResults.php b/src/testgroup/rtGroupResults.php index 26e9f90..7218b70 100644 --- a/src/testgroup/rtGroupResults.php +++ b/src/testgroup/rtGroupResults.php @@ -22,6 +22,7 @@ class rtGroupResults protected $runOrder; protected $runByProcessor = 0; protected $absTime; + protected $isSkipGroup = false; public function __construct($gn) { $this->groupName = $gn; @@ -68,6 +69,10 @@ class rtGroupResults public function setProc($p) { $this->runByProcessor = $p; } + public function setSkip($s) { + $this->isSkipGroup = $s; + } + public function getTime() { return $this->timeToRun; } @@ -82,6 +87,9 @@ class rtGroupResults public function getAbsTime() { return $this->absTime; } + public function isSkipGroup() { + return $this->isSkipGroup; + } } \ No newline at end of file diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php index 012560d..900141c 100644 --- a/src/testgroup/rtPhpTestGroup.php +++ b/src/testgroup/rtPhpTestGroup.php @@ -19,112 +19,136 @@ class rtPhpTestGroup extends rtTask implements rtTaskInterface protected $runConfiguration; protected $groupConfiguration; protected $groupResults; - + + public function __construct(rtRuntestsConfiguration $runConfiguration, $directory, $groupConfiguration) { - $this->runConfiguration = $runConfiguration; + $this->runConfiguration = $runConfiguration; $this->testDirectory = $directory; - $this->groupConfiguration = $groupConfiguration; + $this->groupConfiguration = $groupConfiguration; $this->groupResults = new rtGroupResults($directory); $this->init(); } - + public function __destruct() { - unset ($this->testCases); - unset ($this->groupResults); - + unset ($this->testCases); + unset ($this->groupResults); + } - + public function init() - { - if($this->groupConfiguration->isRedirect()) { - //merge in environmental variables (this is for REDEIRRECT). - foreach($this->groupConfiguration->getEnvironmentVariables() as $key=>$value) { - $this->runConfiguration->setEnvironmentVariable($key, $value); - } - } - - - $this->testFiles = rtUtil::getTestList($this->testDirectory); - - $redirectFromID = $this->groupConfiguration->getRedirectFromID(); - - foreach ($this->testFiles as $testFileName) { - //echo "\n" .memory_get_usage() . ", setup start". $testFileName . "\n"; - - //testFiles is a list of file names relative to the current working directory - - if (!file_exists($testFileName)) { - echo rtText::get('invalidTestFileName', array($testFileName)); - exit(); + { + if($this->groupConfiguration->isRedirect()) { + //merge in environmental variables (this is for REDEIRRECT). + foreach($this->groupConfiguration->getEnvironmentVariables() as $key=>$value) { + $this->runConfiguration->setEnvironmentVariable($key, $value); } - - // Create a new test file object; - $testFile = new rtPhpTestFile(); - $testFile->doRead($testFileName); - $testFile->normaliseLineEndings(); - - //The test name is the full path to the test file name without the .phpt - - $testStatus = new rtTestStatus($testFile->getTestName()); - if ($testFile->arePreconditionsMet() ) { - // Create a new test case - $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus, $redirectFromID); - } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){ - //Redirect handler, save the test case for processing after the main groups have finished. - //Check to make sure that it shouldn't be skipped, if skipped don't save it - $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); - if($redirectedTest->hasSection('SKIPIF')) { - $redirectedTest->runSkipif($this->runConfiguration); - if($redirectedTest->getStatus()->getValue('skip')) { - $testStatus->setTrue('skip'); - $testStatus->setMessage('skip', $testFile->getExitMessage(). ' and the skip condition has failed'); - $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); - } else { - $testStatus->setTrue('redirected'); - $testStatus->setMessage('redirected', $testFile->getExitMessage()); - $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); - $this->groupResults->setRedirectedTestCase($redirectedTest); - } - - } + } + + if($this->groupConfiguration->hasSkipCode()) { - }else { - $testStatus->setTrue('bork'); - $testStatus->setMessage('bork', $testFile->getExitMessage()); - $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); - + //If there is some 'skip' code run it to see if the tests should be skipped and then do nothing else + + $phpCommand = $this->runConfiguration->getSetting('PhpExecutable'); + $arguments = preg_replace('/error_reporting=32767/', 'error_reporting=0', $this->runConfiguration->getSetting('PhpCommandLineArguments')); + + $phpCommand .= ' -f '.$this->groupConfiguration->getSkipFile(); + + $runner = new rtPhpRunner($phpCommand); + $result = $runner->runphp(); + + + if (preg_match('/^\s*skip\s*(.+)\s*/i', $result, $matches)) { + $this->groupResults->setSkip(true); + } + } + + + if($this->isSkipGroup() !== true) { + + $this->testFiles = rtUtil::getTestList($this->testDirectory); + + $redirectFromID = $this->groupConfiguration->getRedirectFromID(); + + foreach ($this->testFiles as $testFileName) { + //echo "\n" .memory_get_usage() . ", setup start". $testFileName . "\n"; + + //testFiles is a list of file names relative to the current working directory + + if (!file_exists($testFileName)) { + echo rtText::get('invalidTestFileName', array($testFileName)); + exit(); + } + + // Create a new test file object; + $testFile = new rtPhpTestFile(); + $testFile->doRead($testFileName); + $testFile->normaliseLineEndings(); + + //The test name is the full path to the test file name without the .phpt + + $testStatus = new rtTestStatus($testFile->getTestName()); + if ($testFile->arePreconditionsMet() ) { + // Create a new test case + $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus, $redirectFromID); + } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){ + //Redirect handler, save the test case for processing after the main groups have finished. + //Check to make sure that it shouldn't be skipped, if skipped don't save it + $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); + if($redirectedTest->hasSection('SKIPIF')) { + $redirectedTest->runSkipif($this->runConfiguration); + if($redirectedTest->getStatus()->getValue('skip')) { + $testStatus->setTrue('skip'); + $testStatus->setMessage('skip', $testFile->getExitMessage(). ' and the skip condition has failed'); + $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); + } else { + $testStatus->setTrue('redirected'); + $testStatus->setMessage('redirected', $testFile->getExitMessage()); + $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); + $this->groupResults->setRedirectedTestCase($redirectedTest); + } + + } + + } else { + $testStatus->setTrue('bork'); + $testStatus->setMessage('bork', $testFile->getExitMessage()); + $this->groupResults->setTestStatus($testFile->getTestName(), $testStatus); + + } + //echo "\n" .memory_get_usage() . ", setup complete". $testFileName . "\n"; + } } } public function run() { - $s=microtime(true); - + $s=microtime(true); + if (count($this->testCases) == 0) { return; } - + for($i=0; $i<count($this->testCases); $i++) { - - $testCase = $this->testCases[$i]; + + $testCase = $this->testCases[$i]; $testCase->executeTest($this->runConfiguration); - - + + $testResult = new rtTestResults($testCase); $testResult->processResults($testCase, $this->runConfiguration); - $this->groupResults->setTestStatus($testCase->getName(), $testResult->getStatus()); - - + $this->groupResults->setTestStatus($testCase->getName(), $testResult->getStatus()); + + } - + $e=microtime(true); - + $this->groupResults->setTime($e-$s); $this->groupResults->setAbsTime($e); } @@ -134,19 +158,23 @@ class rtPhpTestGroup extends rtTask implements rtTaskInterface $testOutputWriter = rtTestOutputWriter::getInstance($this->groupResults->getTestStatusList(), $outType); $testOutputWriter->write($this->testDirectory, $cid); } - - + + public function getTestCases() { - return $this->testCases; + return $this->testCases; } - + public function getGroupName() { - return $this->testDirectory; + return $this->testDirectory; } - - public function getGroupResults() { - return $this->groupResults; + + public function getGroupResults() { + return $this->groupResults; } - + + public function isSkipGroup() { + return $this->groupResults->isSkipGroup(); + } + } ?> diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index b95a987..f26b1f3 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -15,397 +15,410 @@ */ class rtPhpTestRun { - protected $commandLineArguments; - protected $runConfiguration; - protected $redirectedTestCases = array(); - protected $resultList = array(); //An array of arrays of Group Results - protected $serialTasks = array(); - protected $parallelTasks = array(); - protected $reportStatus = 0; - protected $numberOfSerialGroups = 0; - protected $numberOfParallelGroups = 0; - protected $processorCount; - protected $runStartTime; - - public function __construct($argv) - { - $this->commandLineArguments = $argv; - } - - public function run() - { + protected $commandLineArguments; + protected $runConfiguration; + protected $redirectedTestCases = array(); + protected $resultList = array(); //An array of arrays of Group Results + protected $serialTasks = array(); + protected $parallelTasks = array(); + protected $reportStatus = 0; + protected $numberOfSerialGroups = 0; + protected $numberOfParallelGroups = 0; + protected $processorCount; + protected $runStartTime; + protected $skippedGroups = array(); + + public function __construct($argv) + { + $this->commandLineArguments = $argv; + } + + public function run() + { $this->runStartTime = microtime(true); - //Set SSH variables - - // check the operation-system (win/unix) - $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix'; - - //Configure the test environment - $this->runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os); - $this->runConfiguration->getUserEnvironment(); - $this->runConfiguration->configure(); - - - - //Check help message - if($this->runConfiguration->hasCommandLineOption('help') || $this->runConfiguration->hasCommandLineOption('h')) { - echo rtText::get('help'); - exit; - } - - //Check the preconditions - $preConditionList = rtPreConditionList::getInstance($os); - $preConditionList->adaptList(); - - // $preConditionList->check($this->commandLine, $this->environmentVariables); - $preConditionList->check($this->runConfiguration); - - //Write PHP executable name to the array of env variables. Some - //test cases expect to be able to use it. - $php = $this->runConfiguration->getSetting('PhpExecutable'); - $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php); - - //Set reporting option - $this->setReportStatus(); - - $this->processorCount = $this->requestedProcessorCount(); - + //Set SSH variables + + // check the operation-system (win/unix) + $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix'; + + //Configure the test environment + $this->runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os); + $this->runConfiguration->getUserEnvironment(); + $this->runConfiguration->configure(); + + + + //Check help message + if($this->runConfiguration->hasCommandLineOption('help') || $this->runConfiguration->hasCommandLineOption('h')) { + echo rtText::get('help'); + exit; + } + + //Check the preconditions + $preConditionList = rtPreConditionList::getInstance($os); + $preConditionList->adaptList(); + + // $preConditionList->check($this->commandLine, $this->environmentVariables); + $preConditionList->check($this->runConfiguration); + + //Write PHP executable name to the array of env variables. Some + //test cases expect to be able to use it. + $php = $this->runConfiguration->getSetting('PhpExecutable'); + $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php); + + //Set reporting option + $this->setReportStatus(); + + $this->processorCount = $this->requestedProcessorCount(); + /* - * Main decision point. Either we start this with a directory (or set of directories, in which case tests are + * Main decision point. Either we start this with a directory (or set of directories, in which case tests are * run as a group (and in parallel if required) or...... - */ - if ($this->runConfiguration->getSetting('TestDirectories') != null) { - - $this->doGroupRuns(); - - } else { - - /* - *... the input is a test file, or list of files and are just run as single tests - * and not in parallel - */ - if ($this->runConfiguration->getSetting('TestFiles') == null) { - echo rtText::get('invalidTestFileName'); - exit(); - }else{ - $this->run_tests($this->runConfiguration->getSetting('TestFiles')); - } - } - - if(count($this->redirectedTestCases) > 0) { - $this->doRedirectedRuns(); - } - - if(($this->numberOfSerialGroups != 0) || ($this->numberOfParallelGroups != 0)) { - $this->createRunOutput(); - } - - } - - public function doGroupRuns() { - - $subDirectories = $this->buildSubDirectoryList($this->runConfiguration->getSetting('TestDirectories')); - $groupConfigurations = $this->buildGroupConfigurations($subDirectories); - - //If there is only one subdirectory, run seqential - - if(count($subDirectories) === 1) { - $this->run_serial_groups($subDirectories, $groupConfigurations); - $this->numberOfSerialGroups = 1; - - } else { - - //check to see if this is set to be a parallel run, if not, run the subdirectory groups in sequence. - if($this->processorCount <= 1) { - $this->run_serial_groups($subDirectories, $groupConfigurations); - $this->numberOfSerialGroups = count($subDirectories); - } else { - //At least part of this run can be in parallel, check group configurations to make sure that none are set to be serial. - //This builds parallel and serial task lists. - foreach($groupConfigurations as $key=>$gc) { - if($gc->isSerial()) { - $serialGroups[] = $key; - } else { - $parallelGroups[] = $key; - } - } - - if(isset($serialGroups)) {$this->numberOfSerialGroups = count($serialGroups);} - - $this->numberOfParallelGroups = count($parallelGroups); - - $this->run_parallel_groups($parallelGroups, $groupConfigurations, $this->processorCount); - if($this->numberOfSerialGroups > 0) { - $this->run_serial_groups($serialGroups, $groupConfigurations); - } - } - } - - } - - public function doRedirectedRuns() { - foreach($this->redirectedTestCases as $testCase){ - - $groupConfig = new rtGroupConfiguration(null); - $groupConfig->parseRedirect($testCase); - - $group = $groupConfig->getTestDirectory(); - - $this->run_serial_groups(array($group), array($group=>$groupConfig)); - - $this->numberOfSerialGroups++; - - } - } - - public function run_parallel_groups($testDirectories, $groupConfigurations, $processCount) { - - // create the task-list - $taskList = array(); - foreach($testDirectories as $testGroup) { - $taskList[] = new rtTaskTestGroup($this->runConfiguration, $testGroup, $groupConfigurations[$testGroup]); - } - - // run the task-scheduler - $scheduler = rtTaskScheduler::getInstance(); - $scheduler->setTaskList($taskList); - $scheduler->setProcessCount($processCount); - $scheduler->setReportStatus($this->reportStatus); - $scheduler->run(); - - foreach($scheduler->getResultList() as $groupResult) { - - $this->resultList[] = $groupResult->getTestStatusList(); - - // Debug - get which group was run by which processor and how long each took - // - - if($this->runConfiguration->hasCommandLineOption('debug')) { - $time = round($groupResult->getTime(), 2); - - $absTime = $groupResult->getAbsTime() - $this->runStartTime; - - $absTime = round($absTime, 2); - - echo "\nPARDBG," . $absTime. "," . $time . "," . $groupResult->getProcessorId() . "," . $groupResult->getRunOrder() . "," . $groupResult->getGroupName(); - - } - - $redirects = $groupResult->getRedirectedTestCases(); - foreach($redirects as $testCase) { - $this->redirectedTestCases[] = $testCase; - } - } - - - - } - - public function run_serial_groups($testDirectories, $groupConfigurations) { - - $count = 0; - - - //xdebug_start_trace('/tmp/memorycheck'); - - foreach($testDirectories as $subDirectory) { - - - - - // Memory usage debugging - //$startm = memory_get_usage(); - - - $testGroup = new rtPhpTestGroup($this->runConfiguration, $subDirectory, $groupConfigurations[$subDirectory]); - $testGroup->run(); - - // Memory usage debugging - //$midm = memory_get_usage(); - - - rtTestOutputWriter::flushResult($testGroup->getGroupResults()->getTestStatusList(), $this->reportStatus); - $this->resultList[] = $testGroup->getGroupResults()->getTestStatusList(); - - if($this->runConfiguration->hasCommandLineOption('debug')) { - - $time = round($testGroup->getGroupResults()->getTime(), 2); - - $absTime = ($testGroup->getGroupResults()->getAbsTime()) - $this->runStartTime; - $absTime = round($absTime, 2); - - - echo "\nSERDBG," . $absTime . "," . $time . "," . $testGroup->getGroupResults()->getProcessorId() . "," . $count . "," . $testGroup->getGroupResults()->getGroupName(); - - } - - // Memory usage debugging - //$midm2 = memory_get_usage(); - - $redirects = $testGroup->getGroupResults()->getRedirectedTestCases(); - foreach($redirects as $testCase) { - $this->redirectedTestCases[] = $testCase; - } - - // Memory usage debugging - //$midm3 = memory_get_usage(); - - - $testGroup->__destruct(); - unset($testGroup); - - // Memory usage debugging - //echo "\n" . $startm . ", " . $midm. ", " .$midm2. ", " .$midm3. ", " .memory_get_usage() . ", ". $subDirectory . "\n"; - $count++; - } - - //xdebug_stop_trace(); - } - - public function run_tests($testNames) { - - //This section deals with running single test cases, or lists of test cases. - - foreach ($testNames as $testName) { + */ + if ($this->runConfiguration->getSetting('TestDirectories') != null) { + + $this->doGroupRuns(); + + } else { + + /* + *... the input is a test file, or list of files and are just run as single tests + * and not in parallel + */ + if ($this->runConfiguration->getSetting('TestFiles') == null) { + echo rtText::get('invalidTestFileName'); + exit(); + }else{ + $this->run_tests($this->runConfiguration->getSetting('TestFiles')); + } + } + + if(count($this->redirectedTestCases) > 0) { + $this->doRedirectedRuns(); + } + + if(($this->numberOfSerialGroups != 0) || ($this->numberOfParallelGroups != 0)) { + $this->createRunOutput(); + } + + } + + public function doGroupRuns() { + + $subDirectories = $this->buildSubDirectoryList($this->runConfiguration->getSetting('TestDirectories')); + + //An array of group configuration objects, one for each subdirectory. + $groupConfigurations = $this->buildGroupConfigurations($subDirectories); + + + //If there is only one subdirectory, run seqential + + if(count($subDirectories) === 1) { + $this->run_serial_groups($subDirectories, $groupConfigurations); + $this->numberOfSerialGroups = 1; + + } else { + + //check to see if this is set to be a parallel run, if not, run the subdirectory groups in sequence. + if($this->processorCount <= 1) { + $this->run_serial_groups($subDirectories, $groupConfigurations); + $this->numberOfSerialGroups = count($subDirectories); + } else { + //At least part of this run can be in parallel, check group configurations to make sure that none are set to be serial. + //This builds parallel and serial task lists. + foreach($groupConfigurations as $key=>$gc) { + if($gc->isSerial()) { + $serialGroups[] = $key; + } else { + $parallelGroups[] = $key; + } + } + + if(isset($serialGroups)) {$this->numberOfSerialGroups = count($serialGroups);} + + $this->numberOfParallelGroups = count($parallelGroups); + + $this->run_parallel_groups($parallelGroups, $groupConfigurations, $this->processorCount); + if($this->numberOfSerialGroups > 0) { + $this->run_serial_groups($serialGroups, $groupConfigurations); + } + } + } + + } + + public function doRedirectedRuns() { + foreach($this->redirectedTestCases as $testCase){ + + $groupConfig = new rtGroupConfiguration(null); + $groupConfig->parseRedirect($testCase); + + $group = $groupConfig->getTestDirectory(); + + $this->run_serial_groups(array($group), array($group=>$groupConfig)); + + $this->numberOfSerialGroups++; + + } + } + + public function run_parallel_groups($testDirectories, $groupConfigurations, $processCount) { - if (!file_exists($testName)) { - echo rtText::get('invalidTestFileName', array($testName)); - exit(); - } - - - //Read the test file - $testFile = new rtPhpTestFile(); - $testFile->doRead($testName); - $testFile->normaliseLineEndings(); - - $testStatus = new rtTestStatus($testFile->getTestName()); - - - if ($testFile->arePreconditionsMet()) { - $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); - - //Setup and set the local environment for the test case - $testCase->executeTest($this->runConfiguration); - - $results = new rtTestResults($testCase); - $results->processResults($testCase, $this->runConfiguration); - $summaryResults = array($testFile->getTestName() => $results->getStatus()); - - } elseif (in_array("REDIRECTTEST", $testFile->getSectionHeadings())) { - - //Redirect handler - //Build a list of redirected test cases - - $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); - - $testStatus->setTrue('redirected'); - $testStatus->setMessage('redirected', $testFile->getExitMessage()); - $summaryResults = array($testFile->getTestName() => $testStatus); - - } else { - $testStatus->setTrue('bork'); - $testStatus->setMessage('bork', $testFile->getExitMessage()); - $summaryResults = array($testFile->getTestName() => $testStatus); - } + // create the task-list + $taskList = array(); + foreach($testDirectories as $testGroup) { + $taskList[] = new rtTaskTestGroup($this->runConfiguration, $testGroup, $groupConfigurations[$testGroup]); + } + + // run the task-scheduler + $scheduler = rtTaskScheduler::getInstance(); + $scheduler->setTaskList($taskList); + $scheduler->setProcessCount($processCount); + $scheduler->setReportStatus($this->reportStatus); + $scheduler->run(); + + foreach($scheduler->getResultList() as $groupResult) { + + if($groupResult->isSkipGroup()) { + $this->skippedGroups[] = $groupResult->getGroupName(); + } else { + $this->resultList[] = $groupResult->getTestStatusList(); + } + + // Debug - get which group was run by which processor and how long each took + // + + if($this->runConfiguration->hasCommandLineOption('debug')) { + $time = round($groupResult->getTime(), 2); + + $absTime = $groupResult->getAbsTime() - $this->runStartTime; + + $absTime = round($absTime, 2); + + echo "\nPARDBG," . $absTime. "," . $time . "," . $groupResult->getProcessorId() . "," . $groupResult->getRunOrder() . "," . $groupResult->getGroupName(); + + } + + $redirects = $groupResult->getRedirectedTestCases(); + foreach($redirects as $testCase) { + $this->redirectedTestCases[] = $testCase; + } + } + + + + } + + public function run_serial_groups($testDirectories, $groupConfigurations) { + + $count = 0; + + foreach($testDirectories as $subDirectory) { + + // Memory usage debugging + //$startm = memory_get_usage(); + + + + $testGroup = new rtPhpTestGroup($this->runConfiguration, $subDirectory, $groupConfigurations[$subDirectory]); - rtTestOutputWriter::flushResult($summaryResults, 3); - - } - } - - public function buildSubDirectoryList($testDirectories){ - - - $subDirectories = array(); - foreach ($testDirectories as $testDirectory) { - $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory)); - } - return $subDirectories; - } - - public function requestedProcessorCount() { - // check for the cmd-line-option 'z' which defines parellel-execution - $processCount = 0; - if ($this->runConfiguration->hasCommandLineOption('z')) { - - $processCount = intval($this->runConfiguration->getCommandLineOption('z')); - - if (!is_numeric($processCount) || $processCount < 0) { - $processCount = 2; - } - } - return $processCount; - } - - public function buildGroupConfigurations($subDirectories) { - $groupConfigurations = array(); - foreach($subDirectories as $subDir) { - $groupConfig = new rtGroupConfiguration($subDir); - $groupConfig->parse(); - $groupConfigurations[$subDir] = $groupConfig; - } - return $groupConfigurations; - } - - public function buildRedirectsList($results) { - foreach ($results as $groupResult) { - foreach($groupResult as $testResult) { - if($testResult->getStatus() == 'redirected') { - $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); - } - } - } - } - - public function createRunOutput() { - $type = null; - if ($this->runConfiguration->hasCommandLineOption('o')) { - $type = $this->runConfiguration->getCommandLineOption('o'); - } - - $outputWriter = rtTestOutputWriter::getInstance($type); - $outputWriter->setResultList($this->resultList); - - $outputWriter->printOverview($this->numberOfParallelGroups, $this->numberOfSerialGroups, $this->processorCount); - - $filename = null; - if ($this->runConfiguration->hasCommandLineOption('s')) { - $filename = $this->runConfiguration->getCommandLineOption('s'); - } - - if ($type || $filename) { - $outputWriter->write($filename); - } - } - - public function setReportStatus() { - // check for the cmd-line-option 'v' which defines the report-status - if ($this->runConfiguration->hasCommandLineOption('v')) { - $this->reportStatus = 1; - } else if ($this->runConfiguration->hasCommandLineOption('vv')) { - $this->reportStatus = 2; - } else if ($this->runConfiguration->hasCommandLineOption('vvv')) { - $this->reportStatus = 3; - } - - //Set the default for runs from 'make test' - if ( file_exists(getcwd() . "/sapi/cli/php")) { - $this->reportStatus = 1; - } - } - - public function extractResults($groupResult) { - $groupSummary = array(); - foreach($groupResult as $testResult) { - $groupSummary[$testResult->getName()] = $testResult->getStatus(); - if($testResult->getStatus() == 'redirected') { - $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); - } - } - return $groupSummary; - } - + + if($testGroup->isSkipGroup() == true) { + $this->skippedGroups[] = $testGroup->getGroupName(); + } else { + + + $testGroup->run(); + + + // Memory usage debugging + //$midm = memory_get_usage(); + + rtTestOutputWriter::flushResult($testGroup->getGroupResults()->getTestStatusList(), $this->reportStatus); + $this->resultList[] = $testGroup->getGroupResults()->getTestStatusList(); + + if($this->runConfiguration->hasCommandLineOption('debug')) { + + $time = round($testGroup->getGroupResults()->getTime(), 2); + + $absTime = ($testGroup->getGroupResults()->getAbsTime()) - $this->runStartTime; + $absTime = round($absTime, 2); + + + echo "\nSERDBG," . $absTime . "," . $time . "," . $testGroup->getGroupResults()->getProcessorId() . "," . $count . "," . $testGroup->getGroupResults()->getGroupName(); + + } + + // Memory usage debugging + //$midm2 = memory_get_usage(); + + $redirects = $testGroup->getGroupResults()->getRedirectedTestCases(); + foreach($redirects as $testCase) { + $this->redirectedTestCases[] = $testCase; + } + + + + // Memory usage debugging + //$midm3 = memory_get_usage(); + + + $testGroup->__destruct(); + unset($testGroup); + + // Memory usage debugging + //echo "\n" . $startm . ", " . $midm. ", " .$midm2. ", " .$midm3. ", " .memory_get_usage() . ", ". $subDirectory . "\n"; + $count++; + } + } + + //xdebug_stop_trace(); + } + + public function run_tests($testNames) { + + //This section deals with running single test cases, or lists of test cases. + + foreach ($testNames as $testName) { + + if (!file_exists($testName)) { + echo rtText::get('invalidTestFileName', array($testName)); + exit(); + } + + + //Read the test file + $testFile = new rtPhpTestFile(); + $testFile->doRead($testName); + $testFile->normaliseLineEndings(); + + $testStatus = new rtTestStatus($testFile->getTestName()); + + + if ($testFile->arePreconditionsMet()) { + $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); + + //Setup and set the local environment for the test case + $testCase->executeTest($this->runConfiguration); + + $results = new rtTestResults($testCase); + $results->processResults($testCase, $this->runConfiguration); + $summaryResults = array($testFile->getTestName() => $results->getStatus()); + + } elseif (in_array("REDIRECTTEST", $testFile->getSectionHeadings())) { + + //Redirect handler + //Build a list of redirected test cases + + $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); + + $testStatus->setTrue('redirected'); + $testStatus->setMessage('redirected', $testFile->getExitMessage()); + $summaryResults = array($testFile->getTestName() => $testStatus); + + } else { + $testStatus->setTrue('bork'); + $testStatus->setMessage('bork', $testFile->getExitMessage()); + $summaryResults = array($testFile->getTestName() => $testStatus); + } + + rtTestOutputWriter::flushResult($summaryResults, 3); + + } + } + + public function buildSubDirectoryList($testDirectories){ + + + $subDirectories = array(); + foreach ($testDirectories as $testDirectory) { + $subDirectories = array_merge($subDirectories, rtUtil::parseDir($testDirectory)); + } + return $subDirectories; + } + + public function requestedProcessorCount() { + // check for the cmd-line-option 'z' which defines parellel-execution + $processCount = 0; + if ($this->runConfiguration->hasCommandLineOption('z')) { + + $processCount = intval($this->runConfiguration->getCommandLineOption('z')); + + if (!is_numeric($processCount) || $processCount < 0) { + $processCount = 2; + } + } + return $processCount; + } + + public function buildGroupConfigurations($subDirectories) { + $groupConfigurations = array(); + foreach($subDirectories as $subDir) { + $groupConfig = new rtGroupConfiguration($subDir); + $groupConfig->parseConfiguration(); + $groupConfigurations[$subDir] = $groupConfig; + } + return $groupConfigurations; + } + + public function buildRedirectsList($results) { + foreach ($results as $groupResult) { + foreach($groupResult as $testResult) { + if($testResult->getStatus() == 'redirected') { + $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); + } + } + } + } + + public function createRunOutput() { + $type = null; + if ($this->runConfiguration->hasCommandLineOption('o')) { + $type = $this->runConfiguration->getCommandLineOption('o'); + } + + $outputWriter = rtTestOutputWriter::getInstance($type); + $outputWriter->setResultList($this->resultList); + + $outputWriter->printOverview($this->numberOfParallelGroups, $this->numberOfSerialGroups, $this->processorCount, $this->skippedGroups); + + $filename = null; + if ($this->runConfiguration->hasCommandLineOption('s')) { + $filename = $this->runConfiguration->getCommandLineOption('s'); + } + + if ($type || $filename) { + $outputWriter->write($filename); + } + } + + public function setReportStatus() { + // check for the cmd-line-option 'v' which defines the report-status + if ($this->runConfiguration->hasCommandLineOption('v')) { + $this->reportStatus = 1; + } else if ($this->runConfiguration->hasCommandLineOption('vv')) { + $this->reportStatus = 2; + } else if ($this->runConfiguration->hasCommandLineOption('vvv')) { + $this->reportStatus = 3; + } + + //Set the default for runs from 'make test' + if ( file_exists(getcwd() . "/sapi/cli/php")) { + $this->reportStatus = 1; + } + } + + public function extractResults($groupResult) { + $groupSummary = array(); + foreach($groupResult as $testResult) { + $groupSummary[$testResult->getName()] = $testResult->getStatus(); + if($testResult->getStatus() == 'redirected') { + $this->redirectedTestCases[] = $testResult->getRedirectedTestCase(); + } + } + return $groupSummary; + } + } ?> diff --git a/tests/rtGroupConfigurationTest.php b/tests/rtGroupConfigurationTest.php index a08e5fb..7d4d6cd 100644 --- a/tests/rtGroupConfigurationTest.php +++ b/tests/rtGroupConfigurationTest.php @@ -3,12 +3,26 @@ require_once dirname(__FILE__) . '/../src/rtAutoload.php'; require_once dirname(__FILE__) . '/rtTestBootstrap.php'; class rtGroupConfigurationTest extends PHPUnit_Framework_TestCase + { + protected $path_to_group; + + public function setUp() { + $this->path_to_group = realpath(dirname(__FILE__) . '/../phpt-tests/group_of_tests'); + } + public function testCreateInstance() { - //$directory = realpath(dirname(__FILE__) . '/../phpt-tests'); $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, 'testgroup')); - $config->configure(); + $config->configure(); + + $groupConfig = new rtGroupConfiguration($this->path_to_group); + + $groupConfig->parseConfiguration(); + + $this->assertTrue(file_exists($groupConfig->getSkipFile())); + $this->assertTrue($groupConfig->hasSkipCode()); + } } \ No newline at end of file diff --git a/tests/rtPhpTestGroupTest.php b/tests/rtPhpTestGroupTest.php index 6fd8a6f..629cd92 100644 --- a/tests/rtPhpTestGroupTest.php +++ b/tests/rtPhpTestGroupTest.php @@ -53,6 +53,20 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase } } + public function testSkipGroup() { + $directory = realpath(dirname(__FILE__) . '/../phpt-tests/group_of_tests'); + $run_config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', RT_PHP_PATH, $directory)); + + $run_config->configure(); + + $group_config = new rtGroupConfiguration($directory); + $group_config->parseConfiguration(); + + $phpTestGroup = new rtPhpTestGroup($run_config, $directory, $group_config); + $phpTestGroup->init(); + + $this->assertTrue($phpTestGroup->isSkipGroup()); + } }