com phpruntests: Changes to discard empty test sections: src/testcase/rtPhpTestFile.php
| From: | David Soria Parra | Date: | Tue, 30 Jun 2009 13:34:56 +0000 |
| Subject: | com phpruntests: Changes to discard empty test sections: src/testcase/rtPhpTestFile.php | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66386@lists.php.net to get a copy of this message | ||
Commit: 49084535a6f448727c8f8d2a077eb9ff0aef3314
Author: Zoe Slattery <zoe@php.net> Tue, 30 Jun 2009 13:34:56 +0000
Parents: 5c66e0dac6be77b1b0967d6c22f2a8a5e1a54a23
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=49084535a6f448727c8f8d2a077eb9ff0aef3314
Log:
Changes to discard empty test sections
Changed paths:
M src/testcase/rtPhpTestFile.php
Diff:
diff --git a/src/testcase/rtPhpTestFile.php b/src/testcase/rtPhpTestFile.php
index b3097f7..554f2f6 100644
--- a/src/testcase/rtPhpTestFile.php
+++ b/src/testcase/rtPhpTestFile.php
@@ -28,71 +28,81 @@ class rtPhpTestFile
'rtHasNoDuplicateSections',
'rtIsValidSectionName',
'rtIsSectionImplemented'
- );
+ );
- /**
- * Reads the contents of the test file and creates an array of the contents.
- *
- * @param string $testFile (file name)
- */
- public function doRead($testFile)
- {
- $this->testFileName = realpath($testFile);
- $this->testName=
dirname($this->testFileName).DIRECTORY_SEPARATOR.basename($this->testFileName,
".phpt");
- $this->testContents = file($this->testFileName);
- }
+ /**
+ * Reads the contents of the test file and creates an array of the contents.
+ *
+ * @param string $testFile (file name)
+ */
+ public function doRead($testFile)
+ {
+ $this->testFileName = realpath($testFile);
+ $this->testName=
dirname($this->testFileName).DIRECTORY_SEPARATOR.basename($this->testFileName,
".phpt");
+ $this->testContents = file($this->testFileName);
+ }
- 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("/--([A-Z]+(_[A-Z]+|))--/", $this->testContents[$i],
$matches)) {
- $this->sectionHeadings[] = $matches[1];
- $this->testContents[$i] = $matches[1];
- } else {
- $this->testContents[$i] = rtrim($this->testContents[$i],
$this->carriageReturn.$this->newLine);
+ 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("/--([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];
+ }
+ }
+ } else {
+ $tempArray[] = rtrim($this->testContents[$i],
$this->carriageReturn.$this->newLine);
+ }
}
+ $this->testContents = $tempArray;
}
- }
-
- public function arePreConditionsMet()
- {
- foreach ($this->preConditions as $preCondition) {
- $condition = new $preCondition;
- if (!$condition->isMet($this->sectionHeadings)) {
- $this->testExitMessage = $condition->getMessage();
- return false;
+
+ public function arePreConditionsMet()
+ {
+ foreach ($this->preConditions as $preCondition) {
+ $condition = new $preCondition;
+ if (!$condition->isMet($this->sectionHeadings)) {
+ $this->testExitMessage = $condition->getMessage();
+ return false;
+ }
}
+ return true;
+ }
+
+ public function getContents()
+ {
+ return $this->testContents;
}
- return true;
- }
- public function getContents()
- {
- return $this->testContents;
- }
-
- public function getSectionHeadings()
- {
- return $this->sectionHeadings;
- }
+ public function getSectionHeadings()
+ {
+ return $this->sectionHeadings;
+ }
- public function getTestName()
- {
- return $this->testName;
- }
+ public function getTestName()
+ {
+ return $this->testName;
+ }
- public function getTestFileName()
- {
- return $this->testFileName;
- }
+ public function getTestFileName()
+ {
+ return $this->testFileName;
+ }
- public function getExitMessage()
- {
- return $this->testExitMessage;
- }
+ public function getExitMessage()
+ {
+ return $this->testExitMessage;
+ }
}
?>