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 @@ |
372 | 372 | global $wgParserTestFiles; |
373 | 373 | $this->file = $wgParserTestFiles[0]; |
374 | 374 | } |
375 | | - return new ParserTestFileIterator( $this->file, $this ); |
| 375 | + return new TestFileIterator( $this->file, $this ); |
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
— | — | @@ -673,6 +673,10 @@ |
674 | 674 | } |
675 | 675 | } |
676 | 676 | |
| 677 | + public function showRunFile( $file ) { |
| 678 | + /* NOP */ |
| 679 | + } |
| 680 | + |
677 | 681 | //Test options parser functions |
678 | 682 | |
679 | 683 | protected function parseOptions( $instring ) { |
Index: trunk/phase3/tests/testHelpers.inc |
— | — | @@ -451,7 +451,7 @@ |
452 | 452 | private $lineNum; |
453 | 453 | private $eof; |
454 | 454 | |
455 | | - function __construct( $file, $parserTest = null ) { |
| 455 | + function __construct( $file ) { |
456 | 456 | global $IP; |
457 | 457 | |
458 | 458 | $this->file = $file; |
— | — | @@ -462,11 +462,8 @@ |
463 | 463 | } |
464 | 464 | |
465 | 465 | $this->parserTest = $parserTest; |
| 466 | + $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) ); |
466 | 467 | |
467 | | - if ( $this->parserTest ) { |
468 | | - $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) ); |
469 | | - } |
470 | | - |
471 | 468 | $this->lineNum = $this->index = 0; |
472 | 469 | } |
473 | 470 | |
— | — | @@ -524,11 +521,8 @@ |
525 | 522 | wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" ); |
526 | 523 | } |
527 | 524 | |
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 | + |
533 | 527 | $data = array(); |
534 | 528 | $section = null; |
535 | 529 | |
— | — | @@ -544,7 +538,7 @@ |
545 | 539 | $line = trim( $line ); |
546 | 540 | |
547 | 541 | if ( $line ) { |
548 | | - if ( $this->parserTest && !$this->parserTest->requireHook( $line ) ) { |
| 542 | + if ( !$this->parserTest->requireHook( $line ) ) { |
549 | 543 | return false; |
550 | 544 | } |
551 | 545 | } |
— | — | @@ -565,7 +559,7 @@ |
566 | 560 | $line = trim( $line ); |
567 | 561 | |
568 | 562 | if ( $line ) { |
569 | | - if ( $this->parserTest && !$this->parserTest->requireFunctionHook( $line ) ) { |
| 563 | + if ( !$this->parserTest->requireFunctionHook( $line ) ) { |
570 | 564 | return false; |
571 | 565 | } |
572 | 566 | } |
— | — | @@ -597,8 +591,7 @@ |
598 | 592 | if ( !isset( $data['config'] ) ) |
599 | 593 | $data['config'] = ''; |
600 | 594 | |
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 ) |
603 | 596 | || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) ) ) { |
604 | 597 | # disabled test |
605 | 598 | $data = array(); |
— | — | @@ -609,8 +602,7 @@ |
610 | 603 | |
611 | 604 | global $wgUseTeX; |
612 | 605 | |
613 | | - if ( $this->parserTest && |
614 | | - preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) { |
| 606 | + if ( preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) { |
615 | 607 | # don't run math tests if $wgUseTeX is set to false in LocalSettings |
616 | 608 | $data = array(); |
617 | 609 | $section = null; |
— | — | @@ -618,16 +610,12 @@ |
619 | 611 | continue; |
620 | 612 | } |
621 | 613 | |
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'] ) ); |
632 | 620 | |
633 | 621 | return true; |
634 | 622 | } |