Forum Discussion

RUDOLF_BOTHMA's avatar
RUDOLF_BOTHMA
Community Hero
6 years ago

Reporting Obsolete script functions

Hi all,

 

I've recently had to change my script structure due to a large amount of code duplication to avoid circular includes.  The structure is better now, but some of the functions get called alot.  Sometimes from scripts, sometimes from Visualizer.  I'm hoping to report to myself - not the user - for a while until all the references are highlighted, which of the KWTs and scripts are running when these obsolte functions where called.  I have experienced that Find Usages on the context menu of the function has missed a few so I thought I'd do something like this to mop up the remaining ones:

 

function CallObsolete()
{  
  Log.Message("Obsolete function used");
  return CallNew();  
}

function CallNew()
{ 
  return true;
}

The new code & structure allows this to work.  What would be handy is if TC could tell me who called this function this time around.  It's one thing getting a message in the log telling me that the obsolete method was called, but trying to pinpoint which specific place in a block of code the 6th instance of this warning comes from is an entirely different matter.  What would be handy would be a call stack :smileytongue:.  It's similar, but not identical to of my previous question here:

 

call stack on application exception not returning full stack

 

It just happens to also include references to the Call stack.  If I Log.Error I get a call stack, but if I Log.Message, there's no call stack.  Problem is though, I don't want the entire test to fail just because somewhere there was a neglected piece of code still calling the obsolete methods, so I stick to Log.Message.  In some cases I have even found that the work involved in redoing some of these old pieces of code isn't justified and a function can happily keep calling the obsolete function.  I could use the page's picture to help pinpoint where in the KWT it happens, but that would slow down the tests more than I would like to.  Any thoughts on how I can better identify these orphan obsolete function calls ?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      I tried this experiment... and here's what I got.

      I created the following code:

      function root(){
          Log.Message(root.caller);
      }
      
      function oneUp(){
          Log.Message(oneUp.caller);
          root();
      }
      
      function twoUp(){
          Log.Message(twoUp.caller);
          oneUp();
      }
      
      function top(){
          Log.Message(top.caller);
          twoUp();
      }
      

      I then ran the top function.  My test log, on completion, looks like this.


       

      If you replace <function>.caller with <function>.caller.name you get just the name of the calling function.

      • RUDOLF_BOTHMA's avatar
        RUDOLF_BOTHMA
        Community Hero

        Hitristaanogre 

         

        We use Jscript.  I have tried a direct implementation of the Javascript call as you suggested, since they are theorhetically just about interchangeable. I have tried .caller before, but it appears there are some differences though. 

         

         

         

        It doesn't encounter errors.  It can't pick up the caller though - it's just null

         

        I thought you'd find it amusing that I also tried ObsoleteFunction().caller - and ended up with a Stackoverflow, doh !