https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114667

Revision: 114667
Author:   platonides
Date:     2012-04-02 22:01:02 +0000 (Mon, 02 Apr 2012)
Log Message:
-----------
Detect when tests call $this->hideDeprecated() when they're about to
call a deprecated function, and place those usage-of-deprecated in a 
different class disabled by default.
Currently, there's only one function benefitted by this, which is 
BlockTest::testBug29116LoadWithEmptyIp(), testing the old block interface.

Modified Paths:
--------------
    trunk/tools/code-utils/check-vars.php

Modified: trunk/tools/code-utils/check-vars.php
===================================================================
--- trunk/tools/code-utils/check-vars.php       2012-04-02 21:37:07 UTC (rev 
114666)
+++ trunk/tools/code-utils/check-vars.php       2012-04-02 22:01:02 UTC (rev 
114667)
@@ -127,6 +127,7 @@
                'undefined-constant' => true,
                'missing-requires' => true,
                'deprecated-calls' => true,
+               'hidden-deprecated-calls' => false,
                'deprecated-might' => true,
                'poisoned-function' => true,
                'error' => true,
@@ -435,6 +436,7 @@
                                                $this->mAfterProfileOut = 0;
                                                $this->mFunctionGlobals = 
array();
                                                $this->mLocalVariableTypes = 
array();
+                                               $this->mHiddenDeprecatedCalls = 
array(); // Deprecated functions called which we should not warn about
                                                $currentToken[0] = 
self::FUNCTION_DEFINITION;
                                                $this->mKnownFunctions[] = 
$this->mClass ? $this->mClass . "::" . $this->mFunction : $this->mFunction;
 
@@ -530,7 +532,7 @@
                                                                $this->warning( 
'profileout', "$token[1] in line $token[2] is not preceded by wfProfileOut" );
                                                        }
                                                } elseif ( $token[0] == 
T_FUNCTION ) {
-                                                       $this->warning( 
'function-function', "Uh? Function inside function? A lamda function?" );
+                                                       $this->warning( 
'function-function', "Uh? Function inside function? A lambda function?" );
                                                        $this->error( $token );
                                                } elseif ( $token[0] == 
T_SWITCH ) {
                                                        if ( !$this->mInSwitch )
@@ -549,6 +551,8 @@
 
                                                        $this->checkClassName( 
$token );
                                                        $currentToken[0] = 
self::CLASS_NAME;
+                                               } elseif ( $token[0] == 
T_CONSTANT_ENCAPSED_STRING && is_array( $lastMeaningfulToken ) && 
$lastMeaningfulToken[1] == 'hideDeprecated()' ) {
+                                                       
$this->mHiddenDeprecatedCalls[] = substr( $token[1], 1, -1 );
                                                } elseif ( in_array( $token[0], 
array( T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE ) ) ) {
                                                        $this->mStatus = 
self::IN_FUNCTION_REQUIRE;
                                                        $requirePath = '';
@@ -602,6 +606,11 @@
                                                        }
                                                } else if ( 
$lastMeaningfulToken[0] == self::CLASS_MEMBER ) {
                                                        
$this->checkDeprecation( $lastMeaningfulToken );
+                                                       
+                                                       if ( 
$lastMeaningfulToken[1] == 'hideDeprecated' ) {
+                                                               // 
$this->hideDeprecated() used in tests to knowingly test a deprecated function.
+                                                               
$lastMeaningfulToken[1] = 'hideDeprecated()';
+                                                       }
                                                }
                                        }
 
@@ -800,7 +809,12 @@
                                $class = $token['class'];
                                do {
                                        if ( in_array( $class, 
$mwDeprecatedFunctions[ $token[1] ] ) ) {
-                                               $this->warning( 
'deprecated-calls', "Non deprecated function $this->mFunction calls deprecated 
function {$token['class']}::{$token[1]} in line {$token[2]}" );
+                                               $name = 
"{$token['class']}::{$token[1]}";
+                                               
+                                               if ( in_array( $name, 
$this->mHiddenDeprecatedCalls ) )
+                                                       $this->warning( 
'hidden-deprecated-calls', "Non deprecated function $this->mFunction calls 
deprecated function $name in line {$token[2]} (hidden warning)" );
+                                               else
+                                                       $this->warning( 
'deprecated-calls', "Non deprecated function $this->mFunction calls deprecated 
function $name in line {$token[2]}" );
                                                return;
                                        }
                                        if ( !isset( $mwParentClasses[ $class ] 
) ) {


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to