r14507 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14506‎ | r14507 | r14508 >
Date:04:00, 1 June 2006
Author:brion
Status:old
Tags:
Comment:
* parserTests.php accepts a --file parameter to run an alternate test sutie
* parser tests can now test extensions using !!hooks sections
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)
  • /trunk/phase3/maintenance/parserTests.php (modified) (history)
  • /trunk/phase3/maintenance/parserTestsStaticParserHook.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.inc
@@ -92,6 +92,8 @@
9393 # Matches anything
9494 $this->regex = '';
9595 }
 96+
 97+ $this->hooks = array();
9698 }
9799
98100 /**
@@ -146,6 +148,20 @@
147149 $section = null;
148150 continue;
149151 }
 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+ }
150166 if( $section == 'end' ) {
151167 if( !isset( $data['test'] ) ) {
152168 wfDie( "'end' without 'test' at line $n\n" );
@@ -242,6 +258,9 @@
243259 $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts );
244260
245261 $parser =& new Parser();
 262+ foreach( $this->hooks as $tag => $callback ) {
 263+ $parser->setHook( $tag, $callback );
 264+ }
246265 wfRunHooks( 'ParserTestParser', array( &$parser ) );
247266
248267 $title =& Title::makeTitle( NS_MAIN, $titleText );
@@ -659,7 +678,6 @@
660679 * @param string $name the title, including any prefix
661680 * @param string $text the article text
662681 * @param int $line the input line number, for reporting errors
663 - * @static
664682 * @private
665683 */
666684 function addArticle($name, $text, $line) {
@@ -678,6 +696,21 @@
679697 $art->insertNewArticle($text, '', false, false );
680698 $this->teardownGlobals();
681699 }
 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+ }
682715
683716 /*
684717 * Run the "tidy" command on text if the $wgUseTidy
Index: trunk/phase3/maintenance/parserTests.php
@@ -29,13 +29,15 @@
3030 echo <<<END
3131 MediaWiki $wgVersion parser test suite
3232 Usage: php parserTests.php [--quick] [--quiet] [--color[=(yes|no|light)]]
33 - [--regex <expression>] [--help]
 33+ [--regex=<expression>] [--file=<testfile>]
 34+ [--help]
3435 Options:
3536 --quick Suppress diff output of failed tests
3637 --quiet Suppress notification of passed tests (shows only failed tests)
3738 --color Override terminal detection and force color output on or off
3839 'light' option is similar to 'yes' but with color for dark backgrounds
3940 --regex Only run tests whose descriptions which match given regex
 41+ --file Run test cases from a custom file instead of parserTests.txt
4042 --help Show this help message
4143
4244
@@ -49,9 +51,14 @@
5052 $wgTitle = Title::newFromText( 'Parser test script do not use' );
5153 $tester =& new ParserTest();
5254
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 );
5663
5764 exit ($ok ? 0 : -1);
5865 ?>
Index: trunk/phase3/maintenance/parserTestsStaticParserHook.php
@@ -36,7 +36,9 @@
3737 // wtf?
3838 die(
3939 "\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"
4143 );
4244 }
4345 ?>
Index: trunk/phase3/RELEASE-NOTES
@@ -395,7 +395,10 @@
396396 of lock contention etc. Duplicates are now removed at pop time instead of
397397 at insert time.
398398 * 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
399401
 402+
400403 == Compatibility ==
401404
402405 MediaWiki 1.7 requires PHP 5 (5.1 recommended). PHP 4 is no longer supported.

Status & tagging log