r82877 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82876‎ | r82877 | r82878 >
Date:23:45, 26 February 2011
Author:platonides
Status:ok (Comments)
Tags:
Comment:
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/NewParserHelpers.php (deleted) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php (modified) (history)
  • /trunk/phase3/tests/testHelpers.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/parser/NewParserHelpers.php
@@ -1,197 +0,0 @@
2 -<?php
3 -
4 -class ParserTestFileIterator implements Iterator {
5 -
6 - protected $file;
7 - protected $fh;
8 - protected $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
9 - protected $index = 0;
10 - protected $test;
11 - protected $lineNum;
12 - protected $eof;
13 -
14 - function __construct( $file, $parserTest ) {
15 - $this->file = $file;
16 - $this->fh = fopen( $this->file, "rt" );
17 -
18 - if ( !$this->fh ) {
19 - wfDie( "Couldn't open file '$file'\n" );
20 - }
21 -
22 - $this->parserTest = $parserTest;
23 - //$this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
24 -
25 - $this->lineNum = $this->index = 0;
26 - }
27 -
28 - function rewind() {
29 - if ( fseek( $this->fh, 0 ) ) {
30 - wfDie( "Couldn't fseek to the start of '$this->file'\n" );
31 - }
32 -
33 - $this->index = -1;
34 - $this->lineNum = 0;
35 - $this->eof = false;
36 - $this->next();
37 -
38 - return true;
39 - }
40 -
41 - function current() {
42 - return $this->test;
43 - }
44 -
45 - function key() {
46 - return $this->index;
47 - }
48 -
49 - function next() {
50 - if ( $this->readNextTest() ) {
51 - $this->index++;
52 - return true;
53 - } else {
54 - $this->eof = true;
55 - }
56 - }
57 -
58 - function valid() {
59 - return $this->eof != true;
60 - }
61 -
62 - function readNextTest() {
63 - $data = array();
64 - $section = null;
65 -
66 - while ( false !== ( $line = fgets( $this->fh ) ) ) {
67 - $this->lineNum++;
68 - $matches = array();
69 -
70 - if ( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
71 - $section = strtolower( $matches[1] );
72 -
73 - if ( $section == 'endarticle' ) {
74 - if ( !isset( $data['text'] ) ) {
75 - wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
76 - }
77 -
78 - if ( !isset( $data['article'] ) ) {
79 - wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
80 - }
81 -
82 - $this->parserTest->addArticle( $this->parserTest->removeEndingNewline( $data['article'] ), $data['text'], $this->lineNum );
83 -
84 -
85 - $data = array();
86 - $section = null;
87 -
88 - continue;
89 - }
90 -
91 - if ( $section == 'endhooks' ) {
92 - if ( !isset( $data['hooks'] ) ) {
93 - wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
94 - }
95 -
96 - foreach ( explode( "\n", $data['hooks'] ) as $line ) {
97 - $line = trim( $line );
98 -
99 - if ( $line ) {
100 - if ( !$this->parserTest->requireHook( $line ) ) {
101 - return false;
102 - }
103 - }
104 - }
105 -
106 - $data = array();
107 - $section = null;
108 -
109 - continue;
110 - }
111 -
112 - if ( $section == 'endfunctionhooks' ) {
113 - if ( !isset( $data['functionhooks'] ) ) {
114 - wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
115 - }
116 -
117 - foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
118 - $line = trim( $line );
119 -
120 - if ( $line ) {
121 - if ( !$this->parserTest->requireFunctionHook( $line ) ) {
122 - return false;
123 - }
124 - }
125 - }
126 -
127 - $data = array();
128 - $section = null;
129 -
130 - continue;
131 - }
132 -
133 - if ( $section == 'end' ) {
134 - if ( !isset( $data['test'] ) ) {
135 - wfDie( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
136 - }
137 -
138 - if ( !isset( $data['input'] ) ) {
139 - wfDie( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
140 - }
141 -
142 - if ( !isset( $data['result'] ) ) {
143 - wfDie( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
144 - }
145 -
146 - if ( !isset( $data['options'] ) ) {
147 - $data['options'] = '';
148 - }
149 -
150 - if ( !isset( $data['config'] ) )
151 - $data['config'] = '';
152 -
153 - if ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
154 - || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) ) {
155 - # disabled test
156 - $data = array();
157 - $section = null;
158 -
159 - continue;
160 - }
161 -
162 - global $wgUseTeX;
163 -
164 - if ( preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
165 - # don't run math tests if $wgUseTeX is set to false in LocalSettings
166 - $data = array();
167 - $section = null;
168 -
169 - continue;
170 - }
171 -
172 - $this->test = array(
173 - $this->parserTest->removeEndingNewline( $data['test'] ),
174 - $this->parserTest->removeEndingNewline( $data['input'] ),
175 - $this->parserTest->removeEndingNewline( $data['result'] ),
176 - $this->parserTest->removeEndingNewline( $data['options'] ),
177 - $this->parserTest->removeEndingNewline( $data['config'] ) );
178 -
179 - return true;
180 - }
181 -
182 - if ( isset ( $data[$section] ) ) {
183 - wfDie( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
184 - }
185 -
186 - $data[$section] = '';
187 -
188 - continue;
189 - }
190 -
191 - if ( $section ) {
192 - $data[$section] .= $line;
193 - }
194 - }
195 -
196 - return false;
197 - }
198 -}
Index: trunk/phase3/tests/phpunit/includes/parser/NewParserTest.php
@@ -371,7 +371,7 @@
372372 global $wgParserTestFiles;
373373 $this->file = $wgParserTestFiles[0];
374374 }
375 - return new ParserTestFileIterator( $this->file, $this );
 375+ return new TestFileIterator( $this->file, $this );
376376 }
377377
378378 /**
@@ -673,6 +673,10 @@
674674 }
675675 }
676676
 677+ public function showRunFile( $file ) {
 678+ /* NOP */
 679+ }
 680+
677681 //Test options parser functions
678682
679683 protected function parseOptions( $instring ) {
Index: trunk/phase3/tests/testHelpers.inc
@@ -451,7 +451,7 @@
452452 private $lineNum;
453453 private $eof;
454454
455 - function __construct( $file, $parserTest = null ) {
 455+ function __construct( $file ) {
456456 global $IP;
457457
458458 $this->file = $file;
@@ -462,11 +462,8 @@
463463 }
464464
465465 $this->parserTest = $parserTest;
 466+ $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
466467
467 - if ( $this->parserTest ) {
468 - $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
469 - }
470 -
471468 $this->lineNum = $this->index = 0;
472469 }
473470
@@ -524,11 +521,8 @@
525522 wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
526523 }
527524
528 - if ( $this->parserTest ) {
529 - $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
530 - } else {wfDie("JAJA");
531 - ParserTest::addArticle( $data['article'], $data['text'], $this->lineNum );
532 - }
 525+ $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
 526+
533527 $data = array();
534528 $section = null;
535529
@@ -544,7 +538,7 @@
545539 $line = trim( $line );
546540
547541 if ( $line ) {
548 - if ( $this->parserTest && !$this->parserTest->requireHook( $line ) ) {
 542+ if ( !$this->parserTest->requireHook( $line ) ) {
549543 return false;
550544 }
551545 }
@@ -565,7 +559,7 @@
566560 $line = trim( $line );
567561
568562 if ( $line ) {
569 - if ( $this->parserTest && !$this->parserTest->requireFunctionHook( $line ) ) {
 563+ if ( !$this->parserTest->requireFunctionHook( $line ) ) {
570564 return false;
571565 }
572566 }
@@ -597,8 +591,7 @@
598592 if ( !isset( $data['config'] ) )
599593 $data['config'] = '';
600594
601 - if ( $this->parserTest
602 - && ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
 595+ if ( ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
603596 || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) ) ) {
604597 # disabled test
605598 $data = array();
@@ -609,8 +602,7 @@
610603
611604 global $wgUseTeX;
612605
613 - if ( $this->parserTest &&
614 - preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
 606+ if ( preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
615607 # don't run math tests if $wgUseTeX is set to false in LocalSettings
616608 $data = array();
617609 $section = null;
@@ -618,16 +610,12 @@
619611 continue;
620612 }
621613
622 - if ( $this->parserTest ) {
623 - $this->test = array(
624 - 'test' => ParserTest::chomp( $data['test'] ),
625 - 'input' => ParserTest::chomp( $data['input'] ),
626 - 'result' => ParserTest::chomp( $data['result'] ),
627 - 'options' => ParserTest::chomp( $data['options'] ),
628 - 'config' => ParserTest::chomp( $data['config'] ) );
629 - } else {
630 - $this->test['test'] = $data['test'];
631 - }
 614+ $this->test = array(
 615+ 'test' => ParserTest::chomp( $data['test'] ),
 616+ 'input' => ParserTest::chomp( $data['input'] ),
 617+ 'result' => ParserTest::chomp( $data['result'] ),
 618+ 'options' => ParserTest::chomp( $data['options'] ),
 619+ 'config' => ParserTest::chomp( $data['config'] ) );
632620
633621 return true;
634622 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r82878r82877 fixup. It should have only removed the = null bit.platonides23:47, 26 February 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62006PHPUnit now sees individual parser tests as separate tests. This...mah04:01, 5 February 2010
r76149Rename TestFileIterator $parser member. It is unrelated with the Parser object....platonides22:14, 5 November 2010
r79411Start work on porting ParserTests completely into PHPunit....soxred9303:39, 1 January 2011

Comments

#Comment by Platonides (talk | contribs)   15:38, 28 February 2011

x 2,24 speedup when pointing mysqld tmpdir to a tmpfs fs.

Status & tagging log