# Matches anything
$this->regex = '';
}
+
+ $this->hooks = array();
}
/**
$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" );
$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 );
* @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) {
$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
echo <<<END
MediaWiki $wgVersion parser test suite
Usage: php parserTests.php [--quick] [--quiet] [--color[=(yes|no|light)]]
- [--regex <expression>] [--help]
+ [--regex=<expression>] [--file=<testfile>]
+ [--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
$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);
?>