com phpruntests: rewritten parser - was failing on some sections: src/testcase/rtPhpTest.php src/testcase/rtPhpTestFile.php
tests/testcase/rtPhpTestFileTest.php tests/testcase/rtPhpTestTest.php
| From: | David Soria Parra | Date: | Sun, 05 Jul 2009 17:22:58 +0000 |
| Subject: | com phpruntests: rewritten parser - was failing on some sections: src/testcase/rtPhpTest.php src/testcase/rtPhpTestFile.php tests/testcase/rtPhpTestFileTest.php tests/testcase/rtPhpTestTest.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66379@lists.php.net to get a copy of this message | ||
Commit: 316b3e479683fdb1748e1117871340759ad77a7b
Author: Zoe Slattery <zoe@php.net> Sun, 5 Jul 2009 17:22:58 +0000
Parents: b3547cf9fb0878eeb9a04f42d104f2673bc3a1d4
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=316b3e479683fdb1748e1117871340759ad77a7b
Log:
rewritten parser - was failing on some sections
Changed paths:
M src/testcase/rtPhpTest.php
M src/testcase/rtPhpTestFile.php
M tests/testcase/rtPhpTestFileTest.php
M tests/testcase/rtPhpTestTest.php
Diff:
diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php
index dc33ad5..62cee9c 100644
--- a/src/testcase/rtPhpTest.php
+++ b/src/testcase/rtPhpTest.php
@@ -40,30 +40,44 @@ class rtPhpTest
*/
public function parse()
{
- for ($i=0; $i<count($this->contents); $i++) {
- //Create an array of section objects
- if ($this->isSectionKey($this->contents[$i])) {
- $sectionKey = $this->contents[$i];
-
- $tempArray = array();
- for ($j=$i+1; $j<count($this->contents); $j++) {
-
- if ($this->isSectionKey($this->contents[$j]) ||
stripos($this->contents[$j], "===done===") !== false) {
- if(stripos($this->contents[$j], "===done===") !== false) {
- $tempArray[] = trim($this->contents[$j]);
+ $lastSection = end($this->sectionHeadings);
+
+ foreach($this->sectionHeadings as $keyNumber => $sectionKey) {
+ if($keyNumber < count($this->sectionHeadings) - 1) {
+ $nextKey = $this->sectionHeadings[$keyNumber + 1];
+ }
+ $tempArray=array();
+ foreach($this->contents as $lineNumber => $line) {
+ if($line == "--".$sectionKey."--") {
+ //Found the beginning of the section
+
+ for($contentsLine=$lineNumber + 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
+ $lineNumber --;
+ $sectionContents = array();
+ foreach($tempArray as $line) {
+ //Check for a ===DONE==
+ $sectionContents[] = $line;
+ if(stripos($line, "===done===") !== false) {
+ break;
+ }
+ }
+ $testSection = rtSection::getInstance($sectionKey, $sectionContents);
+ $this->sections[$sectionKey] = $testSection;
+ break;
+ } else {
+ $tempArray[] = $this->contents[$contentsLine];
}
- $testSection = rtSection::getInstance($sectionKey, $tempArray);
- $this->sections[$sectionKey] = $testSection;
- break;
}
- $tempArray[] = $this->contents[$j];
}
}
}
+
+ $testSection = rtSection::getInstance($lastSection, $tempArray);
+ $this->sections[$lastSection] = $testSection;
- $testSection = rtSection::getInstance($sectionKey, $tempArray);
- $this->sections[$sectionKey] = $testSection;
-
//Identify the file and expect section types
$this->fileSection = $this->setFileSection();
@@ -71,23 +85,23 @@ class rtPhpTest
$this->fileSection->setExecutableFileName($this->getName());
}
-
+
/**
* Initialises the configuration for this test. Uses the configuration sections from teh test
case
- *
+ *
* @param rtRunTEstsConfiuration $runConfiguration
- *
+ *
*/
public function init(rtRuntestsConfiguration $runConfiguration)
{
$this->testConfiguration = new rtTestConfiguration($runConfiguration,
$this->sections, $this->sectionHeadings, $this->fileSection);
}
-
+
/**
* Executes the test case
- *
+ *
* @param rtRunTEstsConfiuration $runConfiguration
*/
public function executeTest(rtRuntestsConfiguration $runConfiguration)
@@ -119,7 +133,7 @@ class rtPhpTest
/**
* Test the output against the expect section
- *
+ *
*/
public function compareOutput()
{
@@ -132,10 +146,10 @@ class rtPhpTest
}
}
-
+
/**
* Test the expected headers against actual headers. Only relevant for CGI tests.
- *
+ *
*/
public function compareHeaders()
{
@@ -148,10 +162,10 @@ class rtPhpTest
}
}
-
+
/**
* Identify a section heading
- *
+ *
*/
private function isSectionKey($line)
{
@@ -180,7 +194,7 @@ class rtPhpTest
}
}
-
+
/**
* Sets the test's expect section
*/
@@ -223,9 +237,9 @@ class rtPhpTest
{
return $this->sections[$sectionKey];
}
-
+
/*
- * Return the object containing all test status
+ * Return the object containing all test status
*/
public function getStatus()
{
diff --git a/src/testcase/rtPhpTestFile.php b/src/testcase/rtPhpTestFile.php
index f5766f9..f346685 100644
--- a/src/testcase/rtPhpTestFile.php
+++ b/src/testcase/rtPhpTestFile.php
@@ -55,7 +55,7 @@ class rtPhpTestFile
if($i< count($this->testContents) - 1) {
if (!preg_match("/--([A-Z]+(_[A-Z]+|))--/",
$this->testContents[$i+1])) {
$this->sectionHeadings[] = $matches[1];
- $tempArray[] = $matches[1];
+ $tempArray[] = "--".$matches[1]."--";
}
}
} else {
diff --git a/tests/testcase/rtPhpTestFileTest.php b/tests/testcase/rtPhpTestFileTest.php
index a421cf9..1814fe5 100644
--- a/tests/testcase/rtPhpTestFileTest.php
+++ b/tests/testcase/rtPhpTestFileTest.php
@@ -26,7 +26,7 @@ class rtPhpTestFileTest extends PHPUnit_Framework_TestCase
$testFile->doRead($this->sample_test);
$testFile->normaliseLineEndings();
$fileArray = $testFile->getContents();
- $this->assertEquals('TEST', $fileArray[0]);
+ $this->assertEquals('--TEST--', $fileArray[0]);
$this->assertEquals($this->path_to_tests."/sample_test",
$testFile->getTestName());
}
diff --git a/tests/testcase/rtPhpTestTest.php b/tests/testcase/rtPhpTestTest.php
index a96dbca..6f5e689 100644
--- a/tests/testcase/rtPhpTestTest.php
+++ b/tests/testcase/rtPhpTestTest.php
@@ -9,15 +9,15 @@ class rtPhpTestTest extends PHPUnit_Framework_TestCase
{
$this->php = trim(shell_exec("which php"));
$this->testCase = array (
- 'TEST',
+ '--TEST--',
'This is a test',
- 'FILE',
+ '--FILE--',
'<?php',
' echo "hello world"; ',
'?>',
'===Done===',
'blah blah blah',
- 'EXPECTF',
+ '--EXPECTF--',
'hello world',
);
}