From 08ce3ddaadc992fec5b5b79e00bf639b1813edf7 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 27 Oct 2004 09:21:25 +0000 Subject: [PATCH] * Add --help and --quiet options to parser test runner * Standardize the image: tests on Foobar.jpg * Create a dummy Foobar.jpg during testing --- maintenance/parserTests.php | 91 +++++++++++++++++++++++++++++++++---- maintenance/parserTests.txt | 40 ++++++++-------- 2 files changed, 102 insertions(+), 29 deletions(-) diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php index 1520502185..75f0117f34 100644 --- a/maintenance/parserTests.php +++ b/maintenance/parserTests.php @@ -25,7 +25,7 @@ */ /** */ -$options = array( 'quick', 'color' ); +$options = array( 'quick', 'color', 'quiet', 'help' ); $optionsWithArgs = array( 'regex' ); require_once( 'commandLine.inc' ); @@ -74,6 +74,8 @@ class ParserTest { } $this->showDiffs = !isset( $options['quick'] ); + + $this->quiet = isset( $options['quiet'] ); if (isset($options['regex'])) { $this->regex = $options['regex']; @@ -205,7 +207,9 @@ class ParserTest { * @return bool */ function runTest( $desc, $input, $result, $opts ) { - print "Running test $desc... "; + if( !$this->quiet ) { + $this->showTesting( $desc ); + } $this->setupGlobals($opts); @@ -231,18 +235,15 @@ class ParserTest { if (preg_match('/\\bpst\\b/i', $opts)) { $out = $parser->preSaveTransform( $input, $title, $user, $options ); - } - else if (preg_match('/\\bmsg\\b/i', $opts)) { + } elseif (preg_match('/\\bmsg\\b/i', $opts)) { $out = $parser->transformMsg( $input, $options ); - } - else { + } else { $output =& $parser->parse( $input, $title, $options ); $out = $output->getText(); if (preg_match('/\\bill\\b/i', $opts)) { $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) ); - } - else if (preg_match('/\\bcat\\b/i', $opts)) { + } else if (preg_match('/\\bcat\\b/i', $opts)) { $out = $this->tidy ( implode( ' ', $output->getCategoryLinks() ) ); } @@ -271,6 +272,9 @@ class ParserTest { foreach( $this->listTables() as $table ) { $this->oldTableNames[$table] = $db->tableName( $table ); } + if( !isset( $this->uploadDir ) ) { + $this->uploadDir = $this->setupUploadDir(); + } $settings = array( 'wgServer' => 'http://localhost', @@ -278,6 +282,8 @@ class ParserTest { 'wgScriptPath' => '/', 'wgArticlePath' => '/wiki/$1', 'wgUploadPath' => '/images', + 'wgUploadDirectory' => $this->uploadDir, + 'wgStyleSheetPath' => '/skins', 'wgSitename' => 'MediaWiki', 'wgLanguageCode' => 'en', 'wgUseLatin1' => false, @@ -383,6 +389,23 @@ class ParserTest { } } + /** + * Create a dummy uploads directory which will contain a couple + * of files in order to pass existence tests. + * @return string The directory + * @access private + */ + function setupUploadDir() { + $dir = "/tmp/mwParser-" . mt_rand() . "-images"; + mkdir( $dir ); + mkdir( $dir . '/3' ); + mkdir( $dir . '/3/3a' ); + $f = fopen( $dir . '/3/3a/Foobar.jpg', 'wb' ); + fwrite( $f, 'Dummy file' ); + fclose( $f ); + return $dir; + } + /** * Restore default values and perform any necessary clean-up * after each test runs. @@ -393,6 +416,32 @@ class ParserTest { foreach( $this->savedGlobals as $var => $val ) { $GLOBALS[$var] = $val; } + if( isset( $this->uploadDir ) ) { + $this->teardownUploadDir( $this->uploadDir ); + unset( $this->uploadDir ); + } + } + + /** + * Remove the dummy uploads directory + * @access private + */ + function teardownUploadDir( $dir ) { + unlink( "$dir/3/3a/Foobar.jpg" ); + rmdir( "$dir/3/3a" ); + rmdir( "$dir/3" ); + @rmdir( "$dir/thumb/3/39" ); + @rmdir( "$dir/thumb/3" ); + @rmdir( "$dir/thumb" ); + rmdir( "$dir" ); + } + + /** + * "Running test $desc..." + * @access private + */ + function showTesting( $desc ) { + print "Running test $desc... "; } /** @@ -403,7 +452,9 @@ class ParserTest { * @access private */ function showSuccess( $desc ) { - print $this->termColor( '1;32' ) . 'PASSED' . $this->termReset() . "\n"; + if( !$this->quiet ) { + print $this->termColor( '1;32' ) . 'PASSED' . $this->termReset() . "\n"; + } return true; } @@ -418,6 +469,11 @@ class ParserTest { * @access private */ function showFailure( $desc, $result, $html ) { + if( $this->quiet ) { + # In quiet mode we didn't show the 'Testing' message before the + # test, in case it succeeded. Show it now: + $this->showTesting( $desc ); + } print $this->termColor( '1;31' ) . 'FAILED!' . $this->termReset() . "\n"; if( $this->showDiffs ) { print $this->quickDiff( $result, $html ); @@ -549,6 +605,23 @@ class ParserTest { } } +if( isset( $options['help'] ) ) { + echo <<] [--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 + --regex Only run tests whose descriptions which match given regex + --help Show this help message + + +END; + exit( 0 ); +} + # There is a convention that the parser should never # refer to $wgTitle directly, but instead use the title # passed to it. diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 904be04d2d..0d1f8c9b29 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -1433,27 +1433,27 @@ msg !! test Simple image !! input -[[Image: test]] +[[Image:foobar.jpg]] !! result -

Image: test +

Image:foobar.jpg

!! end !! test Right-aligned image !! input -[[Image:test|right]] +[[Image:foobar.jpg|right]] !! result -
+
!! end !! test Image with caption !! input -[[Image:test|right|Caption text]] +[[Image:foobar.jpg|right|Caption text]] !! result -
Caption text
+
Caption text
!! end @@ -1478,18 +1478,18 @@ Link to image page !! test Frameless image caption with a free URL !! input -[[Image:foo|http://example.com]] +[[Image:foobar.jpg|http://example.com]] !! result -

http://example.com +

http://example.com

!! end !! test Thumbnail image caption with a free URL !! input -[[Image:foo|thumb|http://example.com]] +[[Image:foobar.jpg|thumb|http://example.com]] !! result -
Missing image
Foo
+ !! end @@ -1497,45 +1497,45 @@ Thumbnail image caption with a free URL !! test BUG 648: Frameless image caption with a link !! input -[[Image:foo|text with a [[link]] in it]] +[[Image:foobar.jpg|text with a [[link]] in it]] !! result -

text with a link in it +

text with a link in it

!! end !! test Escape HTML special chars in image alt text !! input -[[Image:example.jpg|& < > "]] +[[Image:foobar.jpg|& < > "]] !! result -

& < > " +

& < > "

!! end !! test BUG 499: Alt text should have Ӓ, not &1234; !! input -[[Image:image.jpg|♀]] +[[Image:foobar.jpg|♀]] !! result -

♀ +

♀

!! end !! test Broken image caption with link !! input -[[Image:Rowan.jpeg|thumb|This is a broken caption. But [[Main Page|this]] is just an ordinary link. +[[Image:Foobar.jpg|thumb|This is a broken caption. But [[Main Page|this]] is just an ordinary link. !! result -

[[Image:Rowan.jpeg|thumb|This is a broken caption. But this is just an ordinary link. +

[[Image:Foobar.jpg|thumb|This is a broken caption. But this is just an ordinary link.

!! end !! test Image caption containing another image !! input -[[Image:Bar.jpeg|thumb|This is a caption with another [[Image:icon.png|image]] inside it!]] +[[Image:Foobar.jpg|thumb|This is a caption with another [[Image:icon.png|image]] inside it!]] !! result -
Missing image
Bar.jpeg
This is a caption with another image inside it!
+
Missing image
Foobar.jpg
This is a caption with another image inside it!
!! end -- 2.20.1