Skip to content

Commit b803017

Browse files
committed
refactoring
1 parent 0c14852 commit b803017

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

src/main/java/instrumentor/JSASTInstrumentor.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,30 +639,58 @@ private void analyzeTestCodeFunctionCallNode(AstNode node) {
639639
t.setNumAssertions(t.getNumAssertions()+1);
640640
System.out.println("Test case " + t.getTestNumber() + " has " + t.getNumAssertions() + " assertions!");
641641
}else{
642-
TestUtilityFunctionInfo tufi = testUtilityFunctionInfoList.get(testUtilityFunctionInfoList.size()-1);
643-
tufi.setNumAssertions(tufi.getNumAssertions()+1);
644-
System.out.println("Test utility function " + tufi.getFuncName() + " has " + tufi.getNumAssertions() + " assertions!");
645-
//System.out.println("An assertion found out of a test case");
642+
// search for a test utility function with the same name as the enclosingFunction
643+
for(TestUtilityFunctionInfo tufi: testUtilityFunctionInfoList){
644+
if (tufi.getFuncName().equals(enclosingFunction)){
645+
tufi.setNumAssertions(tufi.getNumAssertions()+1);
646+
System.out.println("Test utility function " + tufi.getFuncName() + " has " + tufi.getNumAssertions() + " assertions!");
647+
//System.out.println("An assertion found out of a test case");
648+
break;
649+
}
650+
}
651+
//TestUtilityFunctionInfo tufi = testUtilityFunctionInfoList.get(testUtilityFunctionInfoList.size()-1);
646652
}
647653
}
648654

649655
if (ArrayUtils.contains( assertionSkipList, targetNode.toSource() ) || ArrayUtils.contains( otherSkipList, targetNode.toSource() )) {
650656
System.out.println("Not counting the called function: " + functionName);
651657
return;
652658
}else{
653-
System.out.println("Counting the called function: " + functionName);
659+
System.out.println("Counting the called function: " + functionName + " with enclosingFunction: " + enclosingFunction);
654660
if (!functionCalls.contains(functionName)){
655661
functionCalls.add(functionName);
656662
if (testCaseInfoList.size()!=0){
657663
TestCaseInfo t = testCaseInfoList.get(testCaseInfoList.size()-1);
658-
t.setNumFunCall(t.getNumFunCall()+1);
664+
int currentNumFunCalls = t.getNumFunCall();
665+
// search for a test utility function with the same name as the functionName
666+
boolean testUtilFunCall = false;
667+
for(TestUtilityFunctionInfo tufi: testUtilityFunctionInfoList){
668+
if (tufi.getFuncName().equals(functionName)){
669+
System.out.println("The called function " + functionName + " is a test utility function with " + tufi.getNumFunCall() + " function calls! Adding to the test info...");
670+
currentNumFunCalls += tufi.getNumFunCall();
671+
//System.out.println("A function call found out of a test case");
672+
testUtilFunCall = true;
673+
break;
674+
}
675+
}
676+
if (testUtilFunCall==false)
677+
t.setNumFunCall(currentNumFunCalls+1);
678+
else
679+
t.setNumFunCall(currentNumFunCalls); // do not add the call to the test utility function
680+
659681
System.out.println("Test case " + t.getTestNumber() + " has " + t.getNumFunCall() + " function calls!");
660682
funCallCounter++;
661683
}else{
662-
TestUtilityFunctionInfo tufi = testUtilityFunctionInfoList.get(testUtilityFunctionInfoList.size()-1);
663-
tufi.setNumFunCall(tufi.getNumFunCall()+1);
664-
System.out.println("Test utility function " + tufi.getFuncName() + " has " + tufi.getNumFunCall() + " function calls!");
665-
//System.out.println("A function call found out of a test case");
684+
// search for a test utility function with the same name as the enclosingFunction
685+
for(TestUtilityFunctionInfo tufi: testUtilityFunctionInfoList){
686+
if (tufi.getFuncName().equals(enclosingFunction)){
687+
tufi.setNumFunCall(tufi.getNumFunCall()+1);
688+
System.out.println("Test utility function " + tufi.getFuncName() + " has " + tufi.getNumFunCall() + " function calls!");
689+
//System.out.println("A function call found out of a test case");
690+
break;
691+
}
692+
}
693+
//TestUtilityFunctionInfo tufi = testUtilityFunctionInfoList.get(testUtilityFunctionInfoList.size()-1);
666694
}
667695
}else{
668696
System.out.println("Repeated!");

0 commit comments

Comments
 (0)