Pretty up parser test output:
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 12 Jan 2007 00:35:26 +0000 (00:35 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 12 Jan 2007 00:35:26 +0000 (00:35 +0000)
* 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
maintenance/FiveUpgrade.inc
maintenance/parserTests.inc

index 08094ca..c52c346 100644 (file)
@@ -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.
  */
index d21d8b4..531f175 100644 (file)
@@ -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 = <<<END
 CREATE TABLE $1 (
index ca8d578..94b0982 100644 (file)
@@ -90,7 +90,11 @@ class ParserTest {
                        : new DummyTermColorer();
 
                $this->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;