zoe Wed, 15 Jul 2009 10:35:04 +0000 URL: http://svn.php.net/viewvc?view=revision&revision=284111
Changed paths: U php/phpruntests/trunk/src/taskScheduler/rtTaskSchedulerFile.php U php/phpruntests/trunk/src/testcase/rtPhpRunner.php U php/phpruntests/trunk/src/testcase/rtPhpTest.php U php/phpruntests/trunk/src/testcase/rtPhpTestFile.php U php/phpruntests/trunk/src/testcase/sections/executablesections/rtCleanSection.php U php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php U php/phpruntests/trunk/src/testcase/sections/executablesections/rtSkipIfSection.php U php/phpruntests/trunk/src/testgroup/rtPhpTestGroup.php U php/phpruntests/trunk/src/testrun/rtPhpTestRun.php Log: Fixing the parser to deal with empty sections
Modified: php/phpruntests/trunk/src/taskScheduler/rtTaskSchedulerFile.php =================================================================== --- php/phpruntests/trunk/src/taskScheduler/rtTaskSchedulerFile.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/taskScheduler/rtTaskSchedulerFile.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -21,18 +21,6 @@ private $groupTasks = false; // are the tasks stored in groups? - /** - * the signal-handler is called by the interrupt- or quit-signal. this is - * necessary to cleanup the tmp files and terminate the script correct. - * - * @param int $signal - */ - public static function signalHandler($signal) - { - exit(0); - } - - /** * sets the task-list which has to be an array of task-objects. * it's also possible to use a multidimensional array. in this case the @@ -88,9 +76,7 @@ if ($this->processCount > sizeof($this->taskList)) { $this->processCount = sizeof($this->taskList); } - - // distribute the task to the children $this->distributeTasks(); @@ -113,14 +99,7 @@ break; } } - - - // register signal-handler - /* - pcntl_signal(SIGINT, "rtTaskSchedulerFile::signalHandler"); - pcntl_signal(SIGQUIT, "rtTaskSchedulerFile::signalHandler"); - */ - + // wait until all child-processes are terminated for ($i=0; $i<$this->processCount; $i++) { pcntl_waitpid($this->pidStore[$i], $status); @@ -195,8 +174,6 @@ unlink(self::TMP_FILE.$cid); } - - $this->pidStore = array(); } Modified: php/phpruntests/trunk/src/testcase/rtPhpRunner.php =================================================================== --- php/phpruntests/trunk/src/testcase/rtPhpRunner.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testcase/rtPhpRunner.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -58,8 +58,6 @@ fclose($pipes[0]); - $counter = 0; - while (true) { /* hide errors from interrupted syscalls */ $r = $pipes; @@ -69,19 +67,14 @@ $n = @stream_select($r, $w, $e, $this->timeOut); if ($n === false) { - throw new rtException('Stream select failure in rtPhpRunner'); + throw new rtPhpRunnerException('Stream select failure in rtPhpRunner'); } else if ($n === 0) { proc_terminate($proc); - throw new rtException('The process running test code has timed out in rtPhpRunner'); + throw new rtPhpRunnerException ('The process running test code has timed out in rtPhpRunner'); } else if ($n > 0) { - $counter++; - if ($counter > 100) { - proc_terminate($proc); - throw new rtException('The process running test code has timed out in rtPhpRunner'); - } - $line = fread($pipes[1], 8192); + $line = fread($pipes[1], 8192); if (strlen($line) == 0) { - // EOF + /* EOF */ break; } $data .= (binary) $line; Modified: php/phpruntests/trunk/src/testcase/rtPhpTest.php =================================================================== --- php/phpruntests/trunk/src/testcase/rtPhpTest.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testcase/rtPhpTest.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -42,7 +42,7 @@ { $lastSection = end($this->sectionHeadings); $start=0; - + foreach($this->sectionHeadings as $keyNumber => $sectionKey) { if($keyNumber < count($this->sectionHeadings) - 1) { @@ -53,9 +53,9 @@ for($index=$start; $index<count($this->contents); $index++) if($this->contents[$index] == "--".$sectionKey."--") { //Found the beginning of the section - + for($contentsLine=$index + 1; $contentsLine<count($this->contents); $contentsLine ++) { - + if( ($this->contents[$contentsLine] == "--".$nextKey."--") || ($contentsLine == count($this->contents))) { //Found the end of the section OR the end of the test $start = $contentsLine - 1; @@ -82,7 +82,6 @@ //Identify the file and expect section types $this->fileSection = $this->setFileSection(); $this->expectSection = $this->setExpectSection(); - $this->fileSection->setExecutableFileName($this->getName()); } Modified: php/phpruntests/trunk/src/testcase/rtPhpTestFile.php =================================================================== --- php/phpruntests/trunk/src/testcase/rtPhpTestFile.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testcase/rtPhpTestFile.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -29,6 +29,21 @@ 'rtIsValidSectionName', 'rtIsSectionImplemented' ); + + private function isSectionHeading($string) { + return preg_match("/^\s*--[A-Z]+(_[A-Z]+|)--/", $string); + } + + private function getUntrimmedSectionHeading($string) { + preg_match("/^\s*(--[A-Z]+(_[A-Z]+|)--)/", $string, $matches); + return $matches[1]; + } + + private function getSectionHeading($string) { + preg_match("/^\s*--([A-Z]+(_[A-Z]+|))--/", $string, $matches); + return $matches[1]; + } + /** * Reads the contents of the test file and creates an array of the contents. @@ -42,18 +57,48 @@ $this->testContents = file($this->testFileName); } + /* + * Trims the lines endings - if the line is a section header it gets trimmed to either side of the --. + * This is to avoid problems with tests that have spurious characters after the header. + */ public function normaliseLineEndings() { for ($i=0; $i<count($this->testContents); $i++) { - //This is not nice but there are a huge number of tests with random spacs at the end of the section header - if (preg_match("/^\s*--([A-Z]+(_[A-Z]+|))--/", $this->testContents[$i], $matches)) { - $this->sectionHeadings[] = $matches[1]; - $this->testContents[$i] = '--' . $matches[1] . '--'; - } else { + //Just trim the contents lines here not the section header lines + if ($this->isSectionHeading($this->testContents[$i])) { + $this->testContents[$i] = $this->getUntrimmedSectionHeading($this->testContents[$i]); + }else { $this->testContents[$i] = rtrim($this->testContents[$i], $this->carriageReturn.$this->newLine); } } } + + /* + * Removes and discards any empty test sections + * Constructs a list of section headingg, stripped of their -- identifiers. + */ + public function removeEmptySections() { + $tempArray = array(); + + for ($i=0; $i<count($this->testContents) - 1; $i++) { + $nextLine = $this->testContents[$i+1]; + $thisLine = $this->testContents[$i]; + if ($this->isSectionHeading($thisLine)) { + if (!$this->isSectionHeading($nextLine)) { + $tempArray[] = $this->getUntrimmedSectionHeading($thisLine); + $this->sectionHeadings[] = $this->getSectionHeading($thisLine); + } + } else { + $tempArray[] = $thisLine; + } + } + + if($this->isSectionHeading(end($this->testContents))) { + $this->sectionHeadings[] = $this->getSectionHeading(end($this->testContents)); + } + $tempArray[] = end($this->testContents); + $this->testContents = $tempArray; + } public function arePreConditionsMet() { @@ -94,5 +139,6 @@ { return $this->testExitMessage; } + } ?> Modified: php/phpruntests/trunk/src/testcase/sections/executablesections/rtCleanSection.php =================================================================== --- php/phpruntests/trunk/src/testcase/sections/executablesections/rtCleanSection.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testcase/sections/executablesections/rtCleanSection.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -43,7 +43,7 @@ $testStatus->setMessage('fail_clean','Execution of clean section failed: '.trim($this->output) ); } - } catch (rtException $e) { + } catch (rtPhpRunnerException $e) { $testStatus->setTrue('fail_clean'); $testStatus->setMessage('fail_clean',$e->getMessage); } Modified: php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php =================================================================== --- php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testcase/sections/executablesections/rtFileSection.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -67,7 +67,7 @@ } - } catch (rtException $e) { + } catch (rtPhpRunnerException $e) { $testStatus->setTrue('fail'); $testStatus->setMessage('fail', $e->getMessage() ); } Modified: php/phpruntests/trunk/src/testcase/sections/executablesections/rtSkipIfSection.php =================================================================== --- php/phpruntests/trunk/src/testcase/sections/executablesections/rtSkipIfSection.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testcase/sections/executablesections/rtSkipIfSection.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -51,7 +51,7 @@ $testStatus->setMessage('warn', $matches[1]); } } - } catch (rtException $e) { + } catch (rtPhpRunnerException $e) { $testStatus->setTrue('fail_skip'); $testStatus->setMessage('fail_skip', 'Failed to execute skipif section' . $e->getMessage()); } Modified: php/phpruntests/trunk/src/testgroup/rtPhpTestGroup.php =================================================================== --- php/phpruntests/trunk/src/testgroup/rtPhpTestGroup.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testgroup/rtPhpTestGroup.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -41,6 +41,7 @@ $testFile = new rtPhpTestFile(); $testFile->doRead($testFileName); $testFile->normaliseLineEndings(); + $testFile->removeEmptySections(); //The test name is the full path to the test file name without the .phpt Modified: php/phpruntests/trunk/src/testrun/rtPhpTestRun.php =================================================================== --- php/phpruntests/trunk/src/testrun/rtPhpTestRun.php 2009-07-15 10:17:04 UTC (rev 284110) +++ php/phpruntests/trunk/src/testrun/rtPhpTestRun.php 2009-07-15 10:35:04 UTC (rev 284111) @@ -124,8 +124,11 @@ $testFile = new rtPhpTestFile(); $testFile->doRead($testName); $testFile->normaliseLineEndings(); - + $testFile->removeEmptySections(); + // var_dump($testFile->getSectionHeadings()); + // var_dump($testFile->getContents()); + $testStatus = new rtTestStatus($testFile->getTestName());
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php