(bug 9440) Added "mediawikiwiki" interwiki prefix to MediaWiki.org
[lhc/web/wiklou.git] / maintenance / parserTests.inc
index 7df2c70..3317563 100644 (file)
@@ -20,8 +20,7 @@
 /**
  * @todo Make this more independent of the configuration (and if possible the database)
  * @todo document
- * @package MediaWiki
- * @subpackage Maintenance
+ * @addtogroup Maintenance
  */
 
 /** */
@@ -34,8 +33,7 @@ require_once( "$IP/maintenance/parserTestsStaticParserHook.php" );
 require_once( "$IP/maintenance/parserTestsParserTime.php" );
 
 /**
- * @package MediaWiki
- * @subpackage Maintenance
+ * @addtogroup Maintenance
  */
 class ParserTest {
        /**
@@ -247,7 +245,9 @@ class ParserTest {
                                $data[$section] .= $line;
                        }
                }
-               print "\n";
+               if ( $this->showProgress ) {
+                       print "\n";
+               }
                return $ok;
        }
 
@@ -340,7 +340,7 @@ class ParserTest {
         */
        function setupGlobals($opts = '') {
                # Save the prefixed / quoted table names for later use when we make the temporaries.
-               $db =& wfGetDB( DB_READ );
+               $db = wfGetDB( DB_READ );
                $this->oldTableNames = array();
                foreach( $this->listTables() as $table ) {
                        $this->oldTableNames[$table] = $db->tableName( $table );
@@ -423,14 +423,11 @@ class ParserTest {
                        'objectcache', 'job', 'redirect',
                        'querycachetwo'
                );
-
-               // FIXME manually adding additional table for the tasks extension
-               // we probably need a better software wide system to register new
-               // tables.
-               global $wgExtensionFunctions;
-               if( in_array('wfTasksExtension' , $wgExtensionFunctions ) ) {
-                       $tables[] = 'tasks';
-               }
+               
+               // Allow extensions to add to the list of tables to duplicate;
+               // may be necessary if they hook into page save or other code
+               // which will require them while running tests.
+               wfRunHooks( 'ParserTestTables', array( &$tables ) );
 
                return $tables;
        }
@@ -450,7 +447,7 @@ class ParserTest {
                if (!$setupDB && $wgDBprefix === 'parsertest_') {
                        # oh teh horror
                        $GLOBALS['wgLoadBalancer'] = LoadBalancer::newFromParams( $GLOBALS['wgDBservers'] );
-                       $db =& wfGetDB( DB_MASTER );
+                       $db = wfGetDB( DB_MASTER );
 
                        $tables = $this->listTables();
 
@@ -931,7 +928,8 @@ class TestRecorder {
                if( $success == $total ) {
                        print $this->term->color( 32 ) . "ALL TESTS PASSED!";
                } else {
-                       print $this->term->color( 31 ) . "some tests failed!";
+                       $failed = $total - $success ;
+                       print $this->term->color( 31 ) . "$failed tests failed!";
                }
                print $this->term->reset() . "\n";
                return ($success == $total);
@@ -1019,9 +1017,9 @@ class DbTestRecorder extends TestRecorder  {
                                $differences = $this->compareResult( $before, $after );
                                if( $differences ) {
                                        $count = count($differences);
-                                       printf( "%4d %s\n", $count, $label );
-                                       foreach ($differences as $differing_test_name) {
-                                               print "      * $differing_test_name\n";
+                                       printf( "\n%4d %s\n", $count, $label );
+                                       foreach ($differences as $differing_test_name => $statusInfo) {
+                                               print "      * $differing_test_name  [$statusInfo]\n";
                                        }
                                }
                        }
@@ -1033,8 +1031,8 @@ class DbTestRecorder extends TestRecorder  {
        }
 
        /**
-        ** @desc: Returns an array of the test names with changed results, based on the specified
-        **        before/after criteria.
+        ** Returns an array of the test names with changed results, based on the specified
+        ** before/after criteria.
         */
        private function compareResult( $before, $after ) {
                $testitem = $this->db->tableName( 'testitem' );
@@ -1064,14 +1062,77 @@ class DbTestRecorder extends TestRecorder  {
                $result = $this->db->query( $sql, __METHOD__ );
                $retval = array();
                while ($row = $this->db->fetchObject( $result )) {
-                       $retval[] = $row->t;
+                       $testname = $row->t;
+                       $retval[$testname] = $this->getTestStatusInfo( $testname, $after, $curRun );
                }
                $this->db->freeResult( $result );
                return $retval;
        }
 
        /**
-        ** @desc: Helper function for compareResult() database querying.
+        ** Returns a string giving information about when a test last had a status change.
+        ** Could help to track down when regressions were introduced, as distinct from tests
+        ** which have never passed (which are more change requests than regressions).
+        */
+       private function getTestStatusInfo($testname, $after, $curRun) {
+
+               // If we're looking at a test that has just been removed, then say when it first appeared.
+               if ( is_null( $after ) ) {
+                       $changedRun = $this->db->selectField ( 'testitem',
+                                                                                                  'MIN(ti_run)',
+                                                                                                  array( 'ti_name' => $testname ),
+                                                                                                  __METHOD__ );
+                       $appear = $this->db->selectRow ( 'testrun',
+                                                                                        array( 'tr_date', 'tr_mw_version' ),
+                                                                                        array( 'tr_id' => $changedRun ),
+                                                                                        __METHOD__ );
+                       return "First recorded appearance: "
+                              . date( "d-M-Y H:i:s",  strtotime ( $appear->tr_date ) )
+                              .  ", " . $appear->tr_mw_version;
+               }
+
+               // Otherwise, this test has previous recorded results.
+               // See when this test last had a different result to what we're seeing now.
+               $changedRun = $this->db->selectField ( 'testitem',
+                                                                                          'MAX(ti_run)',
+                                                                                          array( 
+                                                                                              'ti_name'    => $testname,
+                                                                                              'ti_success' => ($after ? "0" : "1"),
+                                                                                              "ti_run != " . $this->db->addQuotes ( $curRun )
+                                                                                               ), 
+                                                                                               __METHOD__ );
+
+               // If no record of ever having had a different result.
+               if ( is_null ( $changedRun ) ) {
+                       if ($after == "0") {
+                               return "Has never passed";
+                       } else {
+                               return "Has never failed";
+                       }
+               }
+
+               // Otherwise, we're looking at a test whose status has changed.
+               // (i.e. it used to work, but now doesn't; or used to fail, but is now fixed.)
+               // In this situation, give as much info as we can as to when it changed status.
+               $pre  = $this->db->selectRow ( 'testrun',
+                                                                               array( 'tr_date', 'tr_mw_version' ),
+                                                                               array( 'tr_id' => $changedRun ),
+                                                                               __METHOD__ );
+               $post = $this->db->selectRow ( 'testrun',
+                                                                               array( 'tr_date', 'tr_mw_version' ),
+                                                                               array( "tr_id > " . $this->db->addQuotes ( $changedRun) ),
+                                                                               __METHOD__,
+                                                                               array( "LIMIT" => 1, "ORDER BY" => 'tr_id' )
+                                                                        );
+
+               return ( $after == "0" ? "Introduced" : "Fixed" ) . " between "
+                               . date( "d-M-Y H:i:s",  strtotime ( $pre->tr_date ) ) .  ", " . $pre->tr_mw_version
+                               . " and "
+                               . date( "d-M-Y H:i:s",  strtotime ( $post->tr_date  ) ) .  ", " . $post->tr_mw_version ;
+       }
+
+       /**
+        ** Helper function for compareResult() database querying.
         */
        private function condition( $value ) {
                if( is_null( $value ) ) {
@@ -1093,4 +1154,4 @@ class DbTestPreviewer extends DbTestRecorder  {
        }
 }
 
-?>
+?>
\ No newline at end of file