@@ -52,7 +52,7 @@ public ArrayList<TestUtilityFunctionInfo> getTestUtilityFunctionInfoList() {
5252 return testUtilityFunctionInfoList ;
5353 }
5454
55-
55+
5656 private ArrayList <Integer > coveredStatementLines = new ArrayList <Integer >();
5757 private ArrayList <Integer > missedStatementLines = new ArrayList <Integer >();
5858 public ArrayList <Integer > getMissedStatementLines () {
@@ -447,19 +447,15 @@ private void analyzeProductionCodeFunctionNode(AstNode node) {
447447
448448 }
449449
450-
451-
452450 private void analyzeTestCodeFunctionNode (AstNode node ) {
453451 // Functions in test files are considered as test utility functions
454-
455452 FunctionNode f = (FunctionNode ) node ;
456- int numOfParam = f .getParams ().size ();
457- int lineNumber = node .getLineno ()+1 ;
458- int fLength = f .getEndLineno () - f .getLineno ();
459- int fDepth = node .depth ();
460- String funcLocation = "regular" ;
461453 String functionName = getFunctionName (f );
462- System .out .println ("Test utility function name: " + functionName );
454+ if (!functionName .contains ("anonymous" )){
455+ TestUtilityFunctionInfo tufi = new TestUtilityFunctionInfo (functionName );
456+ testUtilityFunctionInfoList .add (tufi );
457+ System .out .println ("Test utility function name: " + functionName );
458+ }
463459
464460 AstNode parentNode = node .getParent ();
465461 String parentNodeSource = parentNode .toSource ();
@@ -473,12 +469,8 @@ private void analyzeTestCodeFunctionNode(AstNode node) {
473469 }
474470 //System.out.println("enclosingFunction: " + enclosingFunction);
475471
476-
477- TestUtilityFunctionInfo tufi = new TestUtilityFunctionInfo (functionName );
478- testUtilityFunctionInfoList .add (tufi );
479472 }
480473
481-
482474 private void analyzeProductionCodeFunctionCallNode (AstNode node ) {
483475
484476 /**
@@ -608,7 +600,12 @@ private void analyzeTestCodeFunctionCallNode(AstNode node) {
608600 FunctionCall fcall = (FunctionCall ) node ;
609601 AstNode targetNode = fcall .getTarget (); // node evaluating to the function to call. E.g document.getElemenyById(x)
610602 //System.out.println("targetNode.toSource(): " + targetNode.toSource());
611- String functionName = targetNode .toSource ().substring (targetNode .toSource ().lastIndexOf ("." )+1 );
603+ String functionName = targetNode .toSource ();
604+ if (functionName .contains ("{" )){ // ignoring calls by immediately invoked functions
605+ //System.out.println("ignoring calls by immediately invoked functions: " + functionName);
606+ return ;
607+ }
608+ functionName = targetNode .toSource ().substring (targetNode .toSource ().lastIndexOf ("." )+1 );
612609
613610 if (testsFramework .equals ("qunit" )){
614611 if (targetNode .toSource ().equals ("QUnit.test" ) || targetNode .toSource ().equals ("test" )){
@@ -636,18 +633,36 @@ private void analyzeTestCodeFunctionCallNode(AstNode node) {
636633
637634 if (ArrayUtils .contains ( assertionSkipList , targetNode .toSource () )){
638635 assertionCounter ++;
639- TestCaseInfo t = testCaseInfoList .get (testCaseInfoList .size ()-1 );
640- t .setNumAssertions (t .getNumAssertions ()+1 );
641- System .out .println ("Test case " + t .getTestNumber () + " has " + t .getNumAssertions () + " assertions!" );
636+ if (testCaseInfoList .size ()!=0 ){
637+ TestCaseInfo t = testCaseInfoList .get (testCaseInfoList .size ()-1 );
638+ t .setNumAssertions (t .getNumAssertions ()+1 );
639+ System .out .println ("Test case " + t .getTestNumber () + " has " + t .getNumAssertions () + " assertions!" );
640+ }else {
641+ TestUtilityFunctionInfo tufi = testUtilityFunctionInfoList .get (testUtilityFunctionInfoList .size ()-1 );
642+ tufi .setNumAssertions (tufi .getNumAssertions ()+1 );
643+ System .out .println ("Test utility function " + tufi .getFuncName () + " has " + tufi .getNumAssertions () + " assertions!" );
644+ //System.out.println("An assertion found out of a test case");
645+ }
642646 }
643647
644648 if (ArrayUtils .contains ( assertionSkipList , targetNode .toSource () ) || ArrayUtils .contains ( otherSkipList , targetNode .toSource () )) {
645649 System .out .println ("Not counting the called function: " + functionName );
646650 return ;
647651 }else {
648652 System .out .println ("Counting the called function: " + functionName );
649- if (!functionCalls .contains (functionName ))
653+ if (!functionCalls .contains (functionName )){
650654 functionCalls .add (functionName );
655+ if (testCaseInfoList .size ()!=0 ){
656+ TestCaseInfo t = testCaseInfoList .get (testCaseInfoList .size ()-1 );
657+ t .setNumFunCall (t .getNumFunCall ()+1 );
658+ System .out .println ("Test case " + t .getTestNumber () + " has " + t .getNumFunCall () + " function calls!" );
659+ }else {
660+ TestUtilityFunctionInfo tufi = testUtilityFunctionInfoList .get (testUtilityFunctionInfoList .size ()-1 );
661+ tufi .setNumFunCall (tufi .getNumFunCall ()+1 );
662+ System .out .println ("Test utility function " + tufi .getFuncName () + " has " + tufi .getNumFunCall () + " function calls!" );
663+ //System.out.println("A function call found out of a test case");
664+ }
665+ }
651666
652667 }
653668
@@ -1038,7 +1053,9 @@ public void resetTestCodeProperties() {
10381053 this .asyncTestCounter = 0 ;
10391054 this .assertionCounter = 0 ;
10401055 this .newExpressionCounter = 0 ;
1041- this .triggerCounetr = 0 ;
1056+ this .triggerCounetr = 0 ;
1057+ this .functionCalls .clear ();
1058+ this .testCaseInfoList .clear ();
10421059 }
10431060
10441061
0 commit comments