Index: trunk/phase3/maintenance/parserTests.inc |
— | — | @@ -92,6 +92,8 @@ |
93 | 93 | # Matches anything |
94 | 94 | $this->regex = ''; |
95 | 95 | } |
| 96 | + |
| 97 | + $this->hooks = array(); |
96 | 98 | } |
97 | 99 | |
98 | 100 | /** |
— | — | @@ -146,6 +148,20 @@ |
147 | 149 | $section = null; |
148 | 150 | continue; |
149 | 151 | } |
| 152 | + if( $section == 'endhooks' ) { |
| 153 | + if( !isset( $data['hooks'] ) ) { |
| 154 | + wfDie( "'endhooks' without 'hooks' at line $n\n" ); |
| 155 | + } |
| 156 | + foreach( explode( "\n", $data['hooks'] ) as $line ) { |
| 157 | + $line = trim( $line ); |
| 158 | + if( $line ) { |
| 159 | + $this->requireHook( $line ); |
| 160 | + } |
| 161 | + } |
| 162 | + $data = array(); |
| 163 | + $section = null; |
| 164 | + continue; |
| 165 | + } |
150 | 166 | if( $section == 'end' ) { |
151 | 167 | if( !isset( $data['test'] ) ) { |
152 | 168 | wfDie( "'end' without 'test' at line $n\n" ); |
— | — | @@ -242,6 +258,9 @@ |
243 | 259 | $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts ); |
244 | 260 | |
245 | 261 | $parser =& new Parser(); |
| 262 | + foreach( $this->hooks as $tag => $callback ) { |
| 263 | + $parser->setHook( $tag, $callback ); |
| 264 | + } |
246 | 265 | wfRunHooks( 'ParserTestParser', array( &$parser ) ); |
247 | 266 | |
248 | 267 | $title =& Title::makeTitle( NS_MAIN, $titleText ); |
— | — | @@ -659,7 +678,6 @@ |
660 | 679 | * @param string $name the title, including any prefix |
661 | 680 | * @param string $text the article text |
662 | 681 | * @param int $line the input line number, for reporting errors |
663 | | - * @static |
664 | 682 | * @private |
665 | 683 | */ |
666 | 684 | function addArticle($name, $text, $line) { |
— | — | @@ -678,6 +696,21 @@ |
679 | 697 | $art->insertNewArticle($text, '', false, false ); |
680 | 698 | $this->teardownGlobals(); |
681 | 699 | } |
| 700 | + |
| 701 | + /** |
| 702 | + * Steal a callback function from the primary parser, save it for |
| 703 | + * application to our scary parser. If the hook is not installed, |
| 704 | + * die a painful dead to warn the others. |
| 705 | + * @param string $name |
| 706 | + */ |
| 707 | + private function requireHook( $name ) { |
| 708 | + global $wgParser; |
| 709 | + if( isset( $wgParser->mTagHooks[$name] ) ) { |
| 710 | + $this->hooks[$name] = $wgParser->mTagHooks[$name]; |
| 711 | + } else { |
| 712 | + wfDie( "This test suite requires the '$name' hook extension.\n" ); |
| 713 | + } |
| 714 | + } |
682 | 715 | |
683 | 716 | /* |
684 | 717 | * Run the "tidy" command on text if the $wgUseTidy |
Index: trunk/phase3/maintenance/parserTests.php |
— | — | @@ -29,13 +29,15 @@ |
30 | 30 | echo <<<END |
31 | 31 | MediaWiki $wgVersion parser test suite |
32 | 32 | Usage: php parserTests.php [--quick] [--quiet] [--color[=(yes|no|light)]] |
33 | | - [--regex <expression>] [--help] |
| 33 | + [--regex=<expression>] [--file=<testfile>] |
| 34 | + [--help] |
34 | 35 | Options: |
35 | 36 | --quick Suppress diff output of failed tests |
36 | 37 | --quiet Suppress notification of passed tests (shows only failed tests) |
37 | 38 | --color Override terminal detection and force color output on or off |
38 | 39 | 'light' option is similar to 'yes' but with color for dark backgrounds |
39 | 40 | --regex Only run tests whose descriptions which match given regex |
| 41 | + --file Run test cases from a custom file instead of parserTests.txt |
40 | 42 | --help Show this help message |
41 | 43 | |
42 | 44 | |
— | — | @@ -49,9 +51,14 @@ |
50 | 52 | $wgTitle = Title::newFromText( 'Parser test script do not use' ); |
51 | 53 | $tester =& new ParserTest(); |
52 | 54 | |
53 | | -# Note: the command line setup changes the current working directory |
54 | | -# to the parent, which is why we have to put the subdir here: |
55 | | -$ok = $tester->runTestsFromFile( $IP.'/maintenance/parserTests.txt' ); |
| 55 | +if( isset( $options['file'] ) ) { |
| 56 | + $file = $options['file']; |
| 57 | +} else { |
| 58 | + # Note: the command line setup changes the current working directory |
| 59 | + # to the parent, which is why we have to put the subdir here: |
| 60 | + $file = $IP.'/maintenance/parserTests.txt'; |
| 61 | +} |
| 62 | +$ok = $tester->runTestsFromFile( $file ); |
56 | 63 | |
57 | 64 | exit ($ok ? 0 : -1); |
58 | 65 | ?> |
Index: trunk/phase3/maintenance/parserTestsStaticParserHook.php |
— | — | @@ -36,7 +36,9 @@ |
37 | 37 | // wtf? |
38 | 38 | die( |
39 | 39 | "\nCall this extension as <statictag>string</statictag> or as" . |
40 | | - " <statictag action=flush/>, not in any other way.\n" |
| 40 | + " <statictag action=flush/>, not in any other way.\n" . |
| 41 | + "text: " . var_export( $in, true ) . "\n" . |
| 42 | + "argv: " . var_export( $argv, true ) . "\n" |
41 | 43 | ); |
42 | 44 | } |
43 | 45 | ?> |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -395,7 +395,10 @@ |
396 | 396 | of lock contention etc. Duplicates are now removed at pop time instead of |
397 | 397 | at insert time. |
398 | 398 | * When showing the "blah has been undeleted" page, make sure it's a blue link |
| 399 | +* parserTests.php accepts a --file parameter to run an alternate test sutie |
| 400 | +* parser tests can now test extensions using !!hooks sections |
399 | 401 | |
| 402 | + |
400 | 403 | == Compatibility == |
401 | 404 | |
402 | 405 | MediaWiki 1.7 requires PHP 5 (5.1 recommended). PHP 4 is no longer supported. |