http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82877
Revision: 82877
Author: platonides
Date: 2011-02-26 23:45:35 +0000 (Sat, 26 Feb 2011)
Log Message:
-----------
Remove NewParserHelpers.php and use instead the original TestFileIterator from
which it was copied in r79411.
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.
Modified Paths:
--------------
trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
trunk/phase3/tests/testHelpers.inc
Removed Paths:
-------------
trunk/phase3/tests/phpunit/includes/parser/NewParserHelpers.php
Deleted: trunk/phase3/tests/phpunit/includes/parser/NewParserHelpers.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/parser/NewParserHelpers.php
2011-02-26 23:44:37 UTC (rev 82876)
+++ trunk/phase3/tests/phpunit/includes/parser/NewParserHelpers.php
2011-02-26 23:45:35 UTC (rev 82877)
@@ -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;
- }
-}
Modified: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
2011-02-26 23:44:37 UTC (rev 82876)
+++ trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
2011-02-26 23:45:35 UTC (rev 82877)
@@ -371,7 +371,7 @@
global $wgParserTestFiles;
$this->file = $wgParserTestFiles[0];
}
- return new ParserTestFileIterator( $this->file, $this );
+ return new TestFileIterator( $this->file, $this );
}
/**
@@ -673,6 +673,10 @@
}
}
+ public function showRunFile( $file ) {
+ /* NOP */
+ }
+
//Test options parser functions
protected function parseOptions( $instring ) {
Modified: trunk/phase3/tests/testHelpers.inc
===================================================================
--- trunk/phase3/tests/testHelpers.inc 2011-02-26 23:44:37 UTC (rev 82876)
+++ trunk/phase3/tests/testHelpers.inc 2011-02-26 23:45:35 UTC (rev 82877)
@@ -451,7 +451,7 @@
private $lineNum;
private $eof;
- function __construct( $file, $parserTest = null ) {
+ function __construct( $file ) {
global $IP;
$this->file = $file;
@@ -462,11 +462,8 @@
}
$this->parserTest = $parserTest;
+ $this->parserTest->showRunFile( wfRelativePath( $this->file,
$IP ) );
- if ( $this->parserTest ) {
- $this->parserTest->showRunFile( wfRelativePath(
$this->file, $IP ) );
- }
-
$this->lineNum = $this->index = 0;
}
@@ -524,11 +521,8 @@
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 @@
$line = trim( $line );
if ( $line ) {
- if ( $this->parserTest
&& !$this->parserTest->requireHook( $line ) ) {
+ if (
!$this->parserTest->requireHook( $line ) ) {
return false;
}
}
@@ -565,7 +559,7 @@
$line = trim( $line );
if ( $line ) {
- if ( $this->parserTest
&& !$this->parserTest->requireFunctionHook( $line ) ) {
+ if (
!$this->parserTest->requireFunctionHook( $line ) ) {
return false;
}
}
@@ -597,8 +591,7 @@
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 @@
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 @@
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;
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs