Be a bit more careful about trailing spaces; don't colorize output
authorWil Mahan <wmahan@users.mediawiki.org>
Fri, 24 Sep 2004 04:19:57 +0000 (04:19 +0000)
committerWil Mahan <wmahan@users.mediawiki.org>
Fri, 24 Sep 2004 04:19:57 +0000 (04:19 +0000)
when stdout is not at terminal; add a reminder to check for
duplicate/invalid test articles.

maintenance/parserTests.php
maintenance/parserTests.sql

index 449af46..8130183 100644 (file)
@@ -46,7 +46,8 @@ class ParserTest {
                } elseif( wfIsWindows() ) {
                        $this->color = false;
                } else {
-                       $this->color = true;
+                       # Only colorize output if stdout is a terminal.
+                       $this->color = posix_isatty(1);
                }
                
                if( isset( $_SERVER['argv'] ) && in_array( '--quick', $_SERVER['argv'] ) ) {
@@ -55,7 +56,19 @@ class ParserTest {
                        $this->showDiffs = true;
                }
        }
-       
+
+       /**
+        * Remove last character if it is a newline
+        * @access private
+        */
+       function chomp($s) {
+               if (substr($s, -1) === "\n") {
+                       return substr($s, 0, -1);
+               }
+               else {
+                       return $s;
+               }
+       }
        
        /**
         * Run a series of tests listed in the given text file.
@@ -91,7 +104,7 @@ class ParserTest {
                                        if( !isset( $data['article'] ) ) {
                                                die( "'endarticle' without 'article' at line $n\n" );
                                        }
-                                       $this->addArticle(rtrim($data['article']), rtrim($data['text']));
+                                       $this->addArticle($this->chomp($data['article']), $this->chomp($data['text']));
                                        $data = array();
                                        $section = null;
                                        continue;
@@ -115,11 +128,14 @@ class ParserTest {
                                        if( !isset( $data['options'] ) ) {
                                                $data['options'] = '';
                                        }
+                                       else {
+                                               $data['options'] = $this->chomp( $data['options'] );
+                                       }
                                        if( $this->runTest(
-                                               rtrim( $data['test'] ),
-                                               rtrim( $data['input'] ),
-                                               rtrim( $data['result'] ),
-                                               rtrim( $data['options'] ) ) ) {
+                                               $this->chomp( $data['test'] ),
+                                               $this->chomp( $data['input'] ),
+                                               $this->chomp( $data['result'] ),
+                                               $this->chomp( $data['options'] ) ) ) {
                                                $success++;
                                        }
                                        $total++;
@@ -181,20 +197,15 @@ class ParserTest {
                        #if (preg_match('/cat/i', $opts)) {
                        #       $out .= $output->getCategoryLinks();
                        #}
-               }
 
-               global $wgUseTidy;
-               if ($wgUseTidy) {
-                       # Using Parser here is probably theoretically
-                       # wrong, because we shouldn't use Parser to
-                       # validate itself, but this should be safe
-                       # in practice.
-                       $result = Parser::tidy($result);
+                       if ($GLOBALS['wgUseTidy']) {
+                               $result = Parser::tidy($result);
+                       }
                }
                
                $this->teardownGlobals();
                
-               if( rtrim($result) === rtrim($out) ) {
+               if( $result === $out ) {
                        return $this->showSuccess( $desc );
                } else {
                        return $this->showFailure( $desc, $result, $out );
@@ -337,7 +348,7 @@ class ParserTest {
         */
        function dumpToFile( $data, $filename ) {
                $file = fopen( $filename, "wt" );
-               fwrite( $file, rtrim( $data ) . "\n" );
+               fwrite( $file, $data . "\n" );
                fclose( $file );
        }
        
@@ -388,6 +399,8 @@ class ParserTest {
         * @access private
         */
        function addArticle($name, $text) {
+               # TODO: check if article exists and die gracefully
+               # if we are trying to insert a duplicate
                $this->setupGlobals();
                $title = Title::newFromText( $name );
                $art = new Article($title);
index 438be85..e93be58 100644 (file)
@@ -1,6 +1,6 @@
 -- HACK: this should go away when there is a better way
 
-CREATE TEMPORARY TEMPORARY TABLE parsertestuser (
+CREATE TEMPORARY TABLE parsertestuser (
   user_id int(5) unsigned NOT NULL auto_increment,
   user_name varchar(255) binary NOT NULL default '',
   user_real_name varchar(255) binary NOT NULL default '',
@@ -13,7 +13,7 @@ CREATE TEMPORARY TEMPORARY TABLE parsertestuser (
   INDEX user_name (user_name(10))
 );
 
-CREATE TEMPORARY TEMPORARY TABLE parsertestcur (
+CREATE TEMPORARY TABLE parsertestcur (
   cur_id int(8) unsigned NOT NULL auto_increment,
   cur_namespace tinyint(2) unsigned NOT NULL default '0',
   cur_title varchar(255) binary NOT NULL default '',
@@ -71,14 +71,14 @@ CREATE TEMPORARY TABLE parsertestlinks (
   KEY (l_to)
 );
 
-CREATE TEMPORARY TEMPORARY TABLE parsertestbrokenlinks (
+CREATE TEMPORARY TABLE parsertestbrokenlinks (
   bl_from int(8) unsigned NOT NULL default '0',
   bl_to varchar(255) binary NOT NULL default '',
   UNIQUE KEY bl_from(bl_from,bl_to),
   KEY (bl_to)
 );
 
-CREATE TEMPORARY TEMPORARY TABLE parsertestimagelinks (
+CREATE TEMPORARY TABLE parsertestimagelinks (
   il_from int(8) unsigned NOT NULL default '0',
   il_to varchar(255) binary NOT NULL default '',
   UNIQUE KEY il_from(il_from,il_to),