From 7e3a05ecb0dc43e45988bd70a1bd108b76fb9927 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 12 Jan 2007 00:35:26 +0000 Subject: [PATCH] Pretty up parser test output: * include old failing tests in --record output, at the end of the changed items * suppress failure notices during run if --record and --quiet are both specified, so they're not duped * show relative paths for the test input files * moved FiveUpgrade::relativize() to wfRelativePath() for wider use; using DIRECTORY_SEPARATOR instead of '/' but might explode on windows, haven't tried it ;) won't handle different drives/UNC servers right, probably --- includes/GlobalFunctions.php | 31 ++++++++++++++++++++++++++ maintenance/FiveUpgrade.inc | 34 +--------------------------- maintenance/parserTests.inc | 43 ++++++++++++++++++++++-------------- 3 files changed, 58 insertions(+), 50 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 08094ca173..c52c346edc 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1843,6 +1843,37 @@ function wfBaseName( $path ) { } } +/** + * Generate a relative path name to the given file. + * May explode on non-matching case-insensitive paths, + * funky symlinks, etc. + * + * @param string $path Absolute destination path including target filename + * @param string $from Absolute source path, directory only + * @return string + */ +function wfRelativePath( $path, $from ) { + $pieces = explode( DIRECTORY_SEPARATOR, dirname( $path ) ); + $against = explode( DIRECTORY_SEPARATOR, $from ); + + // Trim off common prefix + while( count( $pieces ) && count( $against ) + && $pieces[0] == $against[0] ) { + array_shift( $pieces ); + array_shift( $against ); + } + + // relative dots to bump us to the parent + while( count( $against ) ) { + array_unshift( $pieces, '..' ); + array_shift( $against ); + } + + array_push( $pieces, wfBaseName( $path ) ); + + return implode( DIRECTORY_SEPARATOR, $pieces ); +} + /** * Make a URL index, appropriate for the el_index field of externallinks. */ diff --git a/maintenance/FiveUpgrade.inc b/maintenance/FiveUpgrade.inc index d21d8b433a..531f1755d6 100644 --- a/maintenance/FiveUpgrade.inc +++ b/maintenance/FiveUpgrade.inc @@ -765,7 +765,7 @@ END; $this->log( "$oldpath -> $newpath" ); if( rename( $oldpath, $newpath ) ) { - $relpath = $this->relativize( $newpath, dirname( $oldpath ) ); + $relpath = wfRelativePath( $newpath, dirname( $oldpath ) ); if( !symlink( $relpath, $oldpath ) ) { $this->log( "... symlink failed!" ); } @@ -776,38 +776,6 @@ END; } } - /** - * Generate a relative path name to the given file. - * Assumes Unix-style paths, separators, and semantics. - * - * @param string $path Absolute destination path including target filename - * @param string $from Absolute source path, directory only - * @return string - * @access private - * @static - */ - function relativize( $path, $from ) { - $pieces = explode( '/', dirname( $path ) ); - $against = explode( '/', $from ); - - // Trim off common prefix - while( count( $pieces ) && count( $against ) - && $pieces[0] == $against[0] ) { - array_shift( $pieces ); - array_shift( $against ); - } - - // relative dots to bump us to the parent - while( count( $against ) ) { - array_unshift( $pieces, '..' ); - array_shift( $against ); - } - - array_push( $pieces, wfBaseName( $path ) ); - - return implode( '/', $pieces ); - } - function upgradeOldImage() { $tabledef = <<showDiffs = !isset( $options['quick'] ); - $this->quiet = isset( $options['quiet'] ); + $this->showProgress = !isset( $options['quiet'] ); + $this->showFailure = !( + isset( $options['quiet'] ) + && isset( $options['record'] ) ); // redundant output + $this->showOutput = isset( $options['show-output'] ); @@ -152,8 +156,10 @@ class ParserTest { if( !$infile ) { wfDie( "Couldn't open $filename\n" ); } else { + global $IP; + $relative = wfRelativePath( $filename, $IP ); print $this->term->color( 1 ) . - "Reading tests from \"$filename\"..." . + "Reading tests from \"$relative\"..." . $this->term->reset() . "\n"; } @@ -264,7 +270,7 @@ class ParserTest { * @return bool */ function runTest( $desc, $input, $result, $opts ) { - if( !$this->quiet ) { + if( $this->showProgress ) { $this->showTesting( $desc ); } @@ -646,7 +652,7 @@ class ParserTest { * @private */ function showSuccess( $desc ) { - if( !$this->quiet ) { + if( $this->showProgress ) { print $this->term->color( '1;32' ) . 'PASSED' . $this->term->reset() . "\n"; } return true; @@ -663,19 +669,21 @@ class ParserTest { * @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->term->color( '1;31' ) . 'FAILED!' . $this->term->reset() . "\n"; - if ( $this->showOutput ) { - print "--- Expected ---\n$result\n--- Actual ---\n$html\n"; - } - if( $this->showDiffs ) { - print $this->quickDiff( $result, $html ); - if( !$this->wellFormed( $html ) ) { - print "XML error: $this->mXmlError\n"; + if( $this->showFailure ) { + if( !$this->showProgress ) { + # 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->term->color( '1;31' ) . 'FAILED!' . $this->term->reset() . "\n"; + if ( $this->showOutput ) { + print "--- Expected ---\n$result\n--- Actual ---\n$html\n"; + } + if( $this->showDiffs ) { + print $this->quickDiff( $result, $html ); + if( !$this->wellFormed( $html ) ) { + print "XML error: $this->mXmlError\n"; + } } } return false; @@ -1010,6 +1018,7 @@ class DbTestRecorder extends TestRecorder { array( 'previously passing test(s) now FAILING! :(', 1, 0 ), array( 'previously FAILING test(s) removed O_o', 0, null ), array( 'new FAILING test(s) :(', null, 0 ), + array( 'still FAILING test(s) :(', 0, 0 ), ); foreach( $table as $criteria ) { list( $label, $before, $after ) = $criteria; -- 2.20.1