zoe             Tue Jun 30 13:34:56 2009 UTC

  Modified files:              
    /phpruntests/src/testcase   rtPhpTestFile.php 
  Log:
  Changes to discard empty test sections
  
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/rtPhpTestFile.php?r1=1.4&r2=1.5&diff_format=u
Index: phpruntests/src/testcase/rtPhpTestFile.php
diff -u phpruntests/src/testcase/rtPhpTestFile.php:1.4 
phpruntests/src/testcase/rtPhpTestFile.php:1.5
--- phpruntests/src/testcase/rtPhpTestFile.php:1.4      Mon May 25 12:46:57 2009
+++ phpruntests/src/testcase/rtPhpTestFile.php  Tue Jun 30 13:34:56 2009
@@ -28,71 +28,81 @@
         '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);
-    }
-
-    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);
+        /**
+         * 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()
+        {
+            $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;
+        }
+
+        public function getSectionHeadings()
+        {
+            return $this->sectionHeadings;
         }
-        return true;
-    }
 
-    public function getContents()
-    {
-        return $this->testContents;
-    }
-    
-    public function getSectionHeadings()
-    {
-        return $this->sectionHeadings;
-    }
-
-
-    public function getTestName()
-    {
-        return $this->testName;
-    }
-
-
-    public function getTestFileName()
-    {
-        return $this->testFileName;
-    }
-
-
-    public function getExitMessage()
-    {
-        return $this->testExitMessage;
-    }
+
+        public function getTestName()
+        {
+            return $this->testName;
+        }
+
+
+        public function getTestFileName()
+        {
+            return $this->testFileName;
+        }
+
+
+        public function getExitMessage()
+        {
+            return $this->testExitMessage;
+        }
 }
 ?>



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to