* parserTests.php accepts a --file parameter to run an alternate test sutie
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 1 Jun 2006 04:00:41 +0000 (04:00 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 1 Jun 2006 04:00:41 +0000 (04:00 +0000)
* parser tests can now test extensions using !!hooks sections

RELEASE-NOTES
maintenance/parserTests.inc
maintenance/parserTests.php
maintenance/parserTestsStaticParserHook.php

index a6e8665..8d7fbe2 100644 (file)
@@ -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 ==
 
index 77d601a..9c98a61 100644 (file)
@@ -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
index 1e3f8b6..eac7adb 100644 (file)
@@ -29,13 +29,15 @@ if( isset( $options['help'] ) ) {
     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
 
 
@@ -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);
 ?>
index 09dde63..ac365ac 100644 (file)
@@ -36,7 +36,9 @@ function wfParserTestStaticParserHookHook( $in, $argv ) {
                // wtf?
                die(
                        "\nCall this extension as <statictag>string</statictag> or as" .
-                       " <statictag action=flush/>, not in any other way.\n"
+                       " <statictag action=flush/>, not in any other way.\n" .
+                       "text: " . var_export( $in, true ) . "\n" .
+                       "argv: " . var_export( $argv, true ) . "\n"
                );
 }
 ?>