From 3c04a042b40d116d7e6c7f281a15d241a1d1420d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 1 Jun 2006 04:00:41 +0000 Subject: [PATCH] * parserTests.php accepts a --file parameter to run an alternate test sutie * parser tests can now test extensions using !!hooks sections --- RELEASE-NOTES | 3 ++ maintenance/parserTests.inc | 35 ++++++++++++++++++++- maintenance/parserTests.php | 15 ++++++--- maintenance/parserTestsStaticParserHook.php | 4 ++- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a6e8665707..8d7fbe292e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -395,6 +395,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN of lock contention etc. Duplicates are now removed at pop time instead of at insert time. * When showing the "blah has been undeleted" page, make sure it's a blue link +* parserTests.php accepts a --file parameter to run an alternate test sutie +* parser tests can now test extensions using !!hooks sections + == Compatibility == diff --git a/maintenance/parserTests.inc b/maintenance/parserTests.inc index 77d601a7d2..9c98a6113a 100644 --- a/maintenance/parserTests.inc +++ b/maintenance/parserTests.inc @@ -92,6 +92,8 @@ class ParserTest { # Matches anything $this->regex = ''; } + + $this->hooks = array(); } /** @@ -146,6 +148,20 @@ class ParserTest { $section = null; continue; } + if( $section == 'endhooks' ) { + if( !isset( $data['hooks'] ) ) { + wfDie( "'endhooks' without 'hooks' at line $n\n" ); + } + foreach( explode( "\n", $data['hooks'] ) as $line ) { + $line = trim( $line ); + if( $line ) { + $this->requireHook( $line ); + } + } + $data = array(); + $section = null; + continue; + } if( $section == 'end' ) { if( !isset( $data['test'] ) ) { wfDie( "'end' without 'test' at line $n\n" ); @@ -242,6 +258,9 @@ class ParserTest { $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts ); $parser =& new Parser(); + foreach( $this->hooks as $tag => $callback ) { + $parser->setHook( $tag, $callback ); + } wfRunHooks( 'ParserTestParser', array( &$parser ) ); $title =& Title::makeTitle( NS_MAIN, $titleText ); @@ -659,7 +678,6 @@ class ParserTest { * @param string $name the title, including any prefix * @param string $text the article text * @param int $line the input line number, for reporting errors - * @static * @private */ function addArticle($name, $text, $line) { @@ -678,6 +696,21 @@ class ParserTest { $art->insertNewArticle($text, '', false, false ); $this->teardownGlobals(); } + + /** + * Steal a callback function from the primary parser, save it for + * application to our scary parser. If the hook is not installed, + * die a painful dead to warn the others. + * @param string $name + */ + private function requireHook( $name ) { + global $wgParser; + if( isset( $wgParser->mTagHooks[$name] ) ) { + $this->hooks[$name] = $wgParser->mTagHooks[$name]; + } else { + wfDie( "This test suite requires the '$name' hook extension.\n" ); + } + } /* * Run the "tidy" command on text if the $wgUseTidy diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php index 1e3f8b6672..eac7adb045 100644 --- a/maintenance/parserTests.php +++ b/maintenance/parserTests.php @@ -29,13 +29,15 @@ if( isset( $options['help'] ) ) { echo <<] [--help] + [--regex=] [--file=] + [--help] Options: --quick Suppress diff output of failed tests --quiet Suppress notification of passed tests (shows only failed tests) --color Override terminal detection and force color output on or off 'light' option is similar to 'yes' but with color for dark backgrounds --regex Only run tests whose descriptions which match given regex + --file Run test cases from a custom file instead of parserTests.txt --help Show this help message @@ -49,9 +51,14 @@ END; $wgTitle = Title::newFromText( 'Parser test script do not use' ); $tester =& new ParserTest(); -# Note: the command line setup changes the current working directory -# to the parent, which is why we have to put the subdir here: -$ok = $tester->runTestsFromFile( $IP.'/maintenance/parserTests.txt' ); +if( isset( $options['file'] ) ) { + $file = $options['file']; +} else { + # Note: the command line setup changes the current working directory + # to the parent, which is why we have to put the subdir here: + $file = $IP.'/maintenance/parserTests.txt'; +} +$ok = $tester->runTestsFromFile( $file ); exit ($ok ? 0 : -1); ?> diff --git a/maintenance/parserTestsStaticParserHook.php b/maintenance/parserTestsStaticParserHook.php index 09dde63bb7..ac365acafc 100644 --- a/maintenance/parserTestsStaticParserHook.php +++ b/maintenance/parserTestsStaticParserHook.php @@ -36,7 +36,9 @@ function wfParserTestStaticParserHookHook( $in, $argv ) { // wtf? die( "\nCall this extension as string or as" . - " , not in any other way.\n" + " , not in any other way.\n" . + "text: " . var_export( $in, true ) . "\n" . + "argv: " . var_export( $argv, true ) . "\n" ); } ?> -- 2.20.1