Remove NewParserHelpers.php and use instead the original TestFileIterator from which...
authorPlatonides <platonides@users.mediawiki.org>
Sat, 26 Feb 2011 23:45:35 +0000 (23:45 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Sat, 26 Feb 2011 23:45:35 +0000 (23:45 +0000)
Remove the $this->parserTest checks as r79411 did. They are no longer needed. They were here since
TestFileIterator addition in r62006 back when this file was called parserTests.inc, before being renamed twice
without preserving history.
The wfDie(); wasn't intended to fall into trunk. It was marking a dead branch and got committed by error in r76149.

tests/phpunit/includes/parser/NewParserHelpers.php [deleted file]
tests/phpunit/includes/parser/NewParserTest.php
tests/testHelpers.inc

diff --git a/tests/phpunit/includes/parser/NewParserHelpers.php b/tests/phpunit/includes/parser/NewParserHelpers.php
deleted file mode 100644 (file)
index a376277..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-<?php
-
-class ParserTestFileIterator implements Iterator {
-
-       protected $file;
-       protected $fh;
-       protected $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
-       protected $index = 0;
-       protected $test;
-       protected $lineNum;
-       protected $eof;
-
-       function __construct( $file, $parserTest ) {
-               $this->file = $file;
-               $this->fh = fopen( $this->file, "rt" );
-
-               if ( !$this->fh ) {
-                       wfDie( "Couldn't open file '$file'\n" );
-               }
-
-               $this->parserTest = $parserTest;
-               //$this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
-
-               $this->lineNum = $this->index = 0;
-       }
-
-       function rewind() {
-               if ( fseek( $this->fh, 0 ) ) {
-                       wfDie( "Couldn't fseek to the start of '$this->file'\n" );
-               }
-
-               $this->index = -1;
-               $this->lineNum = 0;
-               $this->eof = false;
-               $this->next();
-
-               return true;
-       }
-
-       function current() {
-               return $this->test;
-       }
-
-       function key() {
-               return $this->index;
-       }
-
-       function next() {
-               if ( $this->readNextTest() ) {
-                       $this->index++;
-                       return true;
-               } else {
-                       $this->eof = true;
-               }
-       }
-
-       function valid() {
-               return $this->eof != true;
-       }
-
-       function readNextTest() {
-               $data = array();
-               $section = null;
-
-               while ( false !== ( $line = fgets( $this->fh ) ) ) {
-                       $this->lineNum++;
-                       $matches = array();
-
-                       if ( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
-                               $section = strtolower( $matches[1] );
-
-                               if ( $section == 'endarticle' ) {
-                                       if ( !isset( $data['text'] ) ) {
-                                               wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
-                                       }
-
-                                       if ( !isset( $data['article'] ) ) {
-                                               wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
-                                       }
-
-                                       $this->parserTest->addArticle( $this->parserTest->removeEndingNewline( $data['article'] ), $data['text'], $this->lineNum );
-                                       
-                                       
-                                       $data = array();
-                                       $section = null;
-
-                                       continue;
-                               }
-
-                               if ( $section == 'endhooks' ) {
-                                       if ( !isset( $data['hooks'] ) ) {
-                                               wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
-                                       }
-
-                                       foreach ( explode( "\n", $data['hooks'] ) as $line ) {
-                                               $line = trim( $line );
-
-                                               if ( $line ) {
-                                                       if ( !$this->parserTest->requireHook( $line ) ) {
-                                                               return false;
-                                                       }
-                                               }
-                                       }
-
-                                       $data = array();
-                                       $section = null;
-
-                                       continue;
-                               }
-
-                               if ( $section == 'endfunctionhooks' ) {
-                                       if ( !isset( $data['functionhooks'] ) ) {
-                                               wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
-                                       }
-
-                                       foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
-                                               $line = trim( $line );
-
-                                               if ( $line ) {
-                                                       if ( !$this->parserTest->requireFunctionHook( $line ) ) {
-                                                               return false;
-                                                       }
-                                               }
-                                       }
-
-                                       $data = array();
-                                       $section = null;
-
-                                       continue;
-                               }
-
-                               if ( $section == 'end' ) {
-                                       if ( !isset( $data['test'] ) ) {
-                                               wfDie( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
-                                       }
-
-                                       if ( !isset( $data['input'] ) ) {
-                                               wfDie( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
-                                       }
-
-                                       if ( !isset( $data['result'] ) ) {
-                                               wfDie( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
-                                       }
-
-                                       if ( !isset( $data['options'] ) ) {
-                                               $data['options'] = '';
-                                       }
-
-                                       if ( !isset( $data['config'] ) )
-                                               $data['config'] = '';
-
-                                       if ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
-                                                        || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) ) {
-                                               # disabled test
-                                               $data = array();
-                                               $section = null;
-
-                                               continue;
-                                       }
-
-                                       global $wgUseTeX;
-
-                                       if ( preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
-                                               # don't run math tests if $wgUseTeX is set to false in LocalSettings
-                                               $data = array();
-                                               $section = null;
-
-                                               continue;
-                                       }
-
-                                       $this->test = array(
-                                               $this->parserTest->removeEndingNewline( $data['test'] ),
-                                               $this->parserTest->removeEndingNewline( $data['input'] ),
-                                               $this->parserTest->removeEndingNewline( $data['result'] ),
-                                               $this->parserTest->removeEndingNewline( $data['options'] ),
-                                               $this->parserTest->removeEndingNewline( $data['config'] ) );
-
-                                       return true;
-                               }
-
-                               if ( isset ( $data[$section] ) ) {
-                                       wfDie( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
-                               }
-
-                               $data[$section] = '';
-
-                               continue;
-                       }
-
-                       if ( $section ) {
-                               $data[$section] .= $line;
-                       }
-               }
-
-               return false;
-       }
-}
index fe19341..391e925 100644 (file)
@@ -371,7 +371,7 @@ class NewParserTest extends MediaWikiTestCase {
                        global $wgParserTestFiles;
                        $this->file = $wgParserTestFiles[0];
                }
-               return new ParserTestFileIterator( $this->file, $this );
+               return new TestFileIterator( $this->file, $this );
        }
        
        /**
@@ -673,6 +673,10 @@ class NewParserTest extends MediaWikiTestCase {
                }
        }
 
+       public function showRunFile( $file ) {
+               /* NOP */
+       }
+
        //Test options parser functions
        
        protected function parseOptions( $instring ) {
index c747900..f627e1d 100644 (file)
@@ -451,7 +451,7 @@ class TestFileIterator implements Iterator {
        private $lineNum;
        private $eof;
 
-       function __construct( $file, $parserTest = null ) {
+       function __construct( $file ) {
                global $IP;
 
                $this->file = $file;
@@ -462,10 +462,7 @@ class TestFileIterator implements Iterator {
                }
 
                $this->parserTest = $parserTest;
-
-               if ( $this->parserTest ) {
-                       $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
-               }
+               $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
 
                $this->lineNum = $this->index = 0;
        }
@@ -524,11 +521,8 @@ class TestFileIterator implements Iterator {
                                                wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
                                        }
 
-                                       if ( $this->parserTest ) {
-                                               $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
-                                       } else {wfDie("JAJA");
-                                               ParserTest::addArticle( $data['article'], $data['text'], $this->lineNum );
-                                       }
+                                       $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
+
                                        $data = array();
                                        $section = null;
 
@@ -544,7 +538,7 @@ class TestFileIterator implements Iterator {
                                                $line = trim( $line );
 
                                                if ( $line ) {
-                                                       if ( $this->parserTest && !$this->parserTest->requireHook( $line ) ) {
+                                                       if ( !$this->parserTest->requireHook( $line ) ) {
                                                                return false;
                                                        }
                                                }
@@ -565,7 +559,7 @@ class TestFileIterator implements Iterator {
                                                $line = trim( $line );
 
                                                if ( $line ) {
-                                                       if ( $this->parserTest && !$this->parserTest->requireFunctionHook( $line ) ) {
+                                                       if ( !$this->parserTest->requireFunctionHook( $line ) ) {
                                                                return false;
                                                        }
                                                }
@@ -597,8 +591,7 @@ class TestFileIterator implements Iterator {
                                        if ( !isset( $data['config'] ) )
                                                $data['config'] = '';
 
-                                       if ( $this->parserTest
-                                                && ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
+                                       if ( ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
                                                         || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) )  ) {
                                                # disabled test
                                                $data = array();
@@ -609,8 +602,7 @@ class TestFileIterator implements Iterator {
 
                                        global $wgUseTeX;
 
-                                       if ( $this->parserTest &&
-                                                preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
+                                       if ( preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
                                                # don't run math tests if $wgUseTeX is set to false in LocalSettings
                                                $data = array();
                                                $section = null;
@@ -618,16 +610,12 @@ class TestFileIterator implements Iterator {
                                                continue;
                                        }
 
-                                       if ( $this->parserTest ) {
-                                               $this->test = array(
-                                                       'test' => ParserTest::chomp( $data['test'] ),
-                                                       'input' => ParserTest::chomp( $data['input'] ),
-                                                       'result' => ParserTest::chomp( $data['result'] ),
-                                                       'options' => ParserTest::chomp( $data['options'] ),
-                                                       'config' => ParserTest::chomp( $data['config'] ) );
-                                       } else {
-                                               $this->test['test'] = $data['test'];
-                                       }
+                                       $this->test = array(
+                                               'test' => ParserTest::chomp( $data['test'] ),
+                                               'input' => ParserTest::chomp( $data['input'] ),
+                                               'result' => ParserTest::chomp( $data['result'] ),
+                                               'options' => ParserTest::chomp( $data['options'] ),
+                                               'config' => ParserTest::chomp( $data['config'] ) );
 
                                        return true;
                                }