com phpruntests: more work on the parser: src/testcase/rtPhpTest.php src/testcase/rtPhpTestFile.php
| From: | David Soria Parra | Date: | Sun, 05 Jul 2009 22:07:00 +0000 |
| Subject: | com phpruntests: more work on the parser: src/testcase/rtPhpTest.php src/testcase/rtPhpTestFile.php | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66373@lists.php.net to get a copy of this message | ||
Commit: b01b87ed6cd34a35c955ae7ac58017529716ab10
Author: Zoe Slattery <zoe@php.net> Sun, 5 Jul 2009 22:07:00 +0000
Parents: b06df188813ef35de6054090afe8a0ffeab85202
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=b01b87ed6cd34a35c955ae7ac58017529716ab10
Log:
more work on the parser
Changed paths:
M src/testcase/rtPhpTest.php
M src/testcase/rtPhpTestFile.php
Diff:
diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php
index 62cee9c..9662db2 100644
--- a/src/testcase/rtPhpTest.php
+++ b/src/testcase/rtPhpTest.php
@@ -41,35 +41,35 @@ class rtPhpTest
public function parse()
{
$lastSection = end($this->sectionHeadings);
+ $start=0;
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."--") {
+ for($index=$start; $index<count($this->contents); $index++)
+ if($this->contents[$index] == "--".$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))) {
+
+ 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
- $lineNumber --;
- $sectionContents = array();
- foreach($tempArray as $line) {
- //Check for a ===DONE==
- $sectionContents[] = $line;
- if(stripos($line, "===done===") !== false) {
- break;
- }
- }
- $testSection = rtSection::getInstance($sectionKey, $sectionContents);
+ $start = $contentsLine - 1;
+ if($this->isFileSection($sectionKey)) {
+ $tempArray = $this->removeDone($tempArray);
+ }
+
+ if(count($tempArray) > 0) {
+ $testSection = rtSection::getInstance($sectionKey, $tempArray);
$this->sections[$sectionKey] = $testSection;
- break;
- } else {
- $tempArray[] = $this->contents[$contentsLine];
}
+ break;
+ } else {
+ $tempArray[] = $this->contents[$contentsLine];
}
}
}
@@ -84,6 +84,7 @@ class rtPhpTest
$this->expectSection = $this->setExpectSection();
$this->fileSection->setExecutableFileName($this->getName());
+
}
@@ -164,18 +165,33 @@ class rtPhpTest
/**
- * Identify a section heading
+ * Identify a FILE section
*
*/
- private function isSectionKey($line)
+ private function isFileSection($key)
{
- if (in_array($line, $this->sectionHeadings)) {
+ if (strpos($key, "FILE") !== false) {
return true;
}
return false;
}
+ /*
+ * Strip the lines after ===DONE=== from the file section of a test
+ */
+ private function removeDone($array) {
+ $result = array();
+ foreach($array as $line) {
+ $result[] = $line;
+ if(stripos($line, "===done===") !== false) {
+ break;
+ }
+ }
+ return $result;
+ }
+
+
/**
* Set the test's file section
*/
diff --git a/src/testcase/rtPhpTestFile.php b/src/testcase/rtPhpTestFile.php
index f346685..05d1bd2 100644
--- a/src/testcase/rtPhpTestFile.php
+++ b/src/testcase/rtPhpTestFile.php
@@ -44,32 +44,21 @@ class rtPhpTestFile
public function normaliseLineEndings()
{
- $tempArray = array();
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
- //and empty sections.
if (preg_match("/^\s*--([A-Z]+(_[A-Z]+|))--/",
$this->testContents[$i], $matches)) {
- //look ahead to next section unless this is the last test section.
- //if the EXPECT section is empty (missing) it will be caught by preconditions.
- //If the next line is also a section heading than skip adding it to the test
case or headings.
- if($i< count($this->testContents) - 1) {
- if (!preg_match("/--([A-Z]+(_[A-Z]+|))--/",
$this->testContents[$i+1])) {
- $this->sectionHeadings[] = $matches[1];
- $tempArray[] = "--".$matches[1]."--";
- }
- }
+ $this->sectionHeadings[] = $matches[1];
+ $this->testContents[$i] = '--' . $matches[1] . '--';
} else {
- $tempArray[] = rtrim($this->testContents[$i],
$this->carriageReturn.$this->newLine);
+ $this->testContents[$i] = rtrim($this->testContents[$i],
$this->carriageReturn.$this->newLine);
}
}
- $this->testContents = $tempArray;
-
}
public function arePreConditionsMet()
{
foreach ($this->preConditions as $preCondition) {
- $condition = new $preCondition;
+ $condition = new $preCondition;
if (!$condition->isMet($this->sectionHeadings)) {
$this->testExitMessage = $condition->getMessage();
return false;