From 3c37740e9557aba501ca74f2540485e86793bcb2 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 5 Jan 2008 12:20:54 +0000 Subject: [PATCH] * 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 --- maintenance/parserTests.inc | 25 +++++++++++++++++++------ maintenance/parserTests.php | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/maintenance/parserTests.inc b/maintenance/parserTests.inc index b789ebe7c1..563f8d6d39 100644 --- a/maintenance/parserTests.inc +++ b/maintenance/parserTests.inc @@ -95,6 +95,7 @@ class ParserTest { } else { $this->recorder = new TestRecorder( $this->term ); } + $this->keepUploads = isset( $options['keep-uploads'] ); $this->hooks = array(); $this->functionHooks = array(); @@ -280,7 +281,7 @@ class ParserTest { $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts ); - $parser = new Parser(); + $parser = new Parser; foreach( $this->hooks as $tag => $callback ) { $parser->setHook( $tag, $callback ); } @@ -297,11 +298,11 @@ class ParserTest { $out = $parser->preSaveTransform( $input, $title, $user, $options ); } elseif (preg_match('/\\bmsg\\b/i', $opts)) { $out = $parser->transformMsg( $input, $options ); - } elseif( preg_match( '/\\bsection=(\d+)\b/i', $opts, $matches ) ) { - $section = intval( $matches[1] ); + } elseif( preg_match( '/\\bsection=([\w-]+)\b/i', $opts, $matches ) ) { + $section = $matches[1]; $out = $parser->getSection( $input, $section ); - } elseif( preg_match( '/\\breplace=(\d+),"(.*?)"/i', $opts, $matches ) ) { - $section = intval( $matches[1] ); + } elseif( preg_match( '/\\breplace=([\w-]+),"(.*?)"/i', $opts, $matches ) ) { + $section = $matches[1]; $replace = $matches[2]; $out = $parser->replaceSection( $input, $section, $replace ); } else { @@ -550,7 +551,15 @@ class ParserTest { */ private function setupUploadDir() { global $IP; - $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images"; + if ( $this->keepUploads ) { + $dir = wfTempDir() . '/mwParser-images'; + if ( is_dir( $dir ) ) { + return $dir; + } + } else { + $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images"; + } + wfDebug( "Creating upload directory $dir\n" ); mkdir( $dir ); mkdir( $dir . '/3' ); @@ -578,6 +587,10 @@ class ParserTest { * Remove the dummy uploads directory */ private function teardownUploadDir( $dir ) { + if ( $this->keepUploads ) { + return; + } + // delete the files first, then the dirs. self::deleteFiles( array ( diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php index 4f8edc126c..0ee7e8f264 100644 --- a/maintenance/parserTests.php +++ b/maintenance/parserTests.php @@ -42,6 +42,7 @@ Options: --file Run test cases from a custom file instead of parserTests.txt --record Record tests in database --compare Compare with recorded results, without updating the database. + --keep-uploads Re-use the same upload directory for each test, don't delete it --help Show this help message -- 2.20.1