r29291 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29290‎ | r29291 | r29292 >
Date:12:20, 5 January 2008
Author:tstarling
Status:old
Tags:
Comment:
* Added --keep-uploads option to parserTests.php, to speed up execution.
* Loosened validation for section identifiers in preparation for Parser.php commit with freaky section numbers
Modified paths:
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)
  • /trunk/phase3/maintenance/parserTests.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.inc
@@ -95,6 +95,7 @@
9696 } else {
9797 $this->recorder = new TestRecorder( $this->term );
9898 }
 99+ $this->keepUploads = isset( $options['keep-uploads'] );
99100
100101 $this->hooks = array();
101102 $this->functionHooks = array();
@@ -280,7 +281,7 @@
281282
282283 $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts );
283284
284 - $parser = new Parser();
 285+ $parser = new Parser;
285286 foreach( $this->hooks as $tag => $callback ) {
286287 $parser->setHook( $tag, $callback );
287288 }
@@ -297,11 +298,11 @@
298299 $out = $parser->preSaveTransform( $input, $title, $user, $options );
299300 } elseif (preg_match('/\\bmsg\\b/i', $opts)) {
300301 $out = $parser->transformMsg( $input, $options );
301 - } elseif( preg_match( '/\\bsection=(\d+)\b/i', $opts, $matches ) ) {
302 - $section = intval( $matches[1] );
 302+ } elseif( preg_match( '/\\bsection=([\w-]+)\b/i', $opts, $matches ) ) {
 303+ $section = $matches[1];
303304 $out = $parser->getSection( $input, $section );
304 - } elseif( preg_match( '/\\breplace=(\d+),"(.*?)"/i', $opts, $matches ) ) {
305 - $section = intval( $matches[1] );
 305+ } elseif( preg_match( '/\\breplace=([\w-]+),"(.*?)"/i', $opts, $matches ) ) {
 306+ $section = $matches[1];
306307 $replace = $matches[2];
307308 $out = $parser->replaceSection( $input, $section, $replace );
308309 } else {
@@ -550,7 +551,15 @@
551552 */
552553 private function setupUploadDir() {
553554 global $IP;
554 - $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
 555+ if ( $this->keepUploads ) {
 556+ $dir = wfTempDir() . '/mwParser-images';
 557+ if ( is_dir( $dir ) ) {
 558+ return $dir;
 559+ }
 560+ } else {
 561+ $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
 562+ }
 563+
555564 wfDebug( "Creating upload directory $dir\n" );
556565 mkdir( $dir );
557566 mkdir( $dir . '/3' );
@@ -578,6 +587,10 @@
579588 * Remove the dummy uploads directory
580589 */
581590 private function teardownUploadDir( $dir ) {
 591+ if ( $this->keepUploads ) {
 592+ return;
 593+ }
 594+
582595 // delete the files first, then the dirs.
583596 self::deleteFiles(
584597 array (
Index: trunk/phase3/maintenance/parserTests.php
@@ -42,6 +42,7 @@
4343 --file Run test cases from a custom file instead of parserTests.txt
4444 --record Record tests in database
4545 --compare Compare with recorded results, without updating the database.
 46+ --keep-uploads Re-use the same upload directory for each test, don't delete it
4647 --help Show this help message
4748
4849

Status & tagging log