Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pom: bump test-runner to 3.0.0 #1000

Merged
merged 4 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dspot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>eu.stamp-project</groupId>
<artifactId>test-runner</artifactId>
<version>2.3.0</version>
<version>3.0.0</version>
<classifier>jar-with-dependencies</classifier>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -191,13 +190,13 @@ private List<CtMethod<?>> assertPassingAndFailingTests(CtType testClass, List<Ct

private List<CtMethod<?>> addAssertionsOnPassingTests(TestResult testResult, List<CtMethod<?>> tests, CtType testClass){
final List<CtMethod<?>> generatedTestWithAssertion = new ArrayList<>();
final List<String> passingTestsName = testResult.getPassingTests();
final Set<String> passingTestsName = testResult.getPassingTests();
if (!passingTestsName.isEmpty()) {
LOGGER.info("{} test pass, generating assertion...", passingTestsName.size());
final List<CtMethod<?>> passingTestMethods = tests.stream()
.filter(ctMethod ->
passingTestsName.stream()
.anyMatch(passingTestName -> AmplificationHelper.checkMethodName(ctMethod.getSimpleName(), passingTestName))
.anyMatch(passingTestName -> AmplificationHelper.checkMethodName(testClass.getQualifiedName() + "#" + ctMethod.getSimpleName(), passingTestName))
).collect(Collectors.toList());
List<CtMethod<?>> passingTests = this.methodReconstructor.addAssertions(testClass, passingTestMethods)
.stream()
Expand All @@ -219,10 +218,10 @@ private List<CtMethod<?>> addFailStatementOnFailingTests(TestResult testResult,
LOGGER.info("{} test fail, generating try/catch/fail blocks...", failuresMethodName.size());
final List<CtMethod<?>> failingTests = tests.stream()
.filter(ctMethod ->
failuresMethodName.contains(ctMethod.getSimpleName()))
failuresMethodName.contains(ctMethod.getParent(CtClass.class).getQualifiedName() + "#" + ctMethod.getSimpleName()))
.map(ctMethod ->
this.tryCatchFailGenerator
.surroundWithTryCatchFail(ctMethod, testResult.getFailureOf(ctMethod.getSimpleName()))
.surroundWithTryCatchFail(ctMethod, testResult.getFailureOf(ctMethod.getParent(CtClass.class).getQualifiedName() + "#" + ctMethod.getSimpleName()))
)
.filter(Objects::nonNull)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public List<CtMethod<?>> firstSelectorSetup(CtType<?> testClassToBeAmplified,
passingTests = testCompiler.compileRunAndDiscardUncompilableAndFailingTestMethods(
testClassToBeAmplified,
testMethodsToBeAmplified,
compiler);
compiler
);
} catch (Exception | java.lang.Error e) {
GLOBAL_REPORT.addError(new Error(ERROR_EXEC_TEST_BEFORE_AMPLIFICATION, e));
throw new Exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.LoggerFactory;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtType;
Expand Down Expand Up @@ -157,11 +158,11 @@ public static Set<CtType> computeClassProvider(CtType testClass) {
}

public static List<CtMethod<?>> getPassingTests(List<CtMethod<?>> tests, TestResult result) {
final List<String> passingTestNames = result.getPassingTests();
final Set<String> passingTestNames = result.getPassingTests();
if (!passingTestNames.isEmpty()) {
return tests.stream()
.filter(ctMethod -> passingTestNames.stream()
.anyMatch(passingTestName -> checkMethodName(ctMethod.getSimpleName(), passingTestName))
.anyMatch(passingTestName -> checkMethodName(ctMethod.getParent(CtClass.class).getQualifiedName() + "#" +ctMethod.getSimpleName(), passingTestName))
).collect(Collectors.toList());
} else {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import eu.stamp_project.dspot.common.compilation.DSpotCompiler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtType;

Expand Down Expand Up @@ -122,7 +123,7 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
results.getFailingTests()
.forEach(failure -> {
final CtMethod<?> key = amplifiedTestToBeKept.stream()
.filter(ctMethod -> ctMethod.getSimpleName().equals(failure.testCaseName))
.filter(ctMethod -> (ctMethod.getParent(CtClass.class).getQualifiedName() + "#" + ctMethod.getSimpleName()).equals(failure.testCaseName))
.findFirst()
.get();
amplifiedThatWillBeKept.add(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import eu.stamp_project.testrunner.EntryPoint;
import eu.stamp_project.testrunner.listener.CoveragePerTestMethod;
import spoon.reflect.code.CtComment;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.declaration.CtType;
Expand Down Expand Up @@ -61,7 +62,7 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
final List<CtMethod<?>> methodsKept = new ArrayList<>();
for (CtMethod<?> ctMethod : amplifiedTestToBeKept) {
ExtendedCoverage newCoverage = new ExtendedCoverage(coveragePerTestMethod
.getCoverageOf(ctMethod.getSimpleName()));
.getCoverageOf(ctMethod.getParent(CtClass.class).getQualifiedName() + "#" + ctMethod.getSimpleName()));

if (newCoverage.isBetterThan(this.cumulativeAmplifiedCoverage)) {
//note: we still explain the improvement to the coverage before amplification. Maybe we should change?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.commons.io.FileUtils;
import spoon.reflect.code.CtComment;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtNamedElement;
import spoon.reflect.declaration.CtType;
Expand Down Expand Up @@ -82,9 +83,9 @@ public List<CtMethod<?>> selectToAmplify(CtType<?> classTest, List<CtMethod<?>>
final List<String> pathExecuted = new ArrayList<>();
final List<CtMethod<?>> filteredTests = testsToBeAmplified.stream()
.filter(ctMethod -> ctMethod != null &&
coveragePerTestMethod.getCoverageOf(ctMethod.getSimpleName()) != null)
coveragePerTestMethod.getCoverageOf(classTest.getQualifiedName() + "#" + ctMethod.getSimpleName()) != null)
.filter(ctMethod -> {
final String pathByExecInstructions = coveragePerTestMethod.getCoverageOf(ctMethod.getSimpleName()).getExecutionPath();
final String pathByExecInstructions = coveragePerTestMethod.getCoverageOf(classTest.getQualifiedName() + "#" + ctMethod.getSimpleName()).getExecutionPath();
if (pathExecuted.contains(pathByExecInstructions)) {
return false;
} else {
Expand Down Expand Up @@ -129,11 +130,11 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
.filter(ctMethod -> {
final String simpleNameOfFirstParent = getFirstParentThatHasBeenRun(ctMethod).getSimpleName();
return this.selectedToBeAmplifiedCoverageResultsMap.get(simpleNameOfFirstParent) == null ||
coveragePerTestMethod.getCoverageOf(ctMethod.getSimpleName()).isBetterThan(
coveragePerTestMethod.getCoverageOf(this.currentClassTestToBeAmplified.getQualifiedName() + "#" + ctMethod.getSimpleName()).isBetterThan(
this.selectedToBeAmplifiedCoverageResultsMap.get(simpleNameOfFirstParent));
})
.filter(ctMethod -> {
final String pathByExecInstructions = coveragePerTestMethod.getCoverageOf(ctMethod.getSimpleName()).getExecutionPath();
final String pathByExecInstructions = coveragePerTestMethod.getCoverageOf(this.currentClassTestToBeAmplified.getQualifiedName() + "#" + ctMethod.getSimpleName()).getExecutionPath();
if (pathExecuted.contains(pathByExecInstructions)) {
return false;
} else {
Expand All @@ -143,7 +144,7 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
})
.peek(ctMethod -> {
Coverage oldCoverage = this.selectedToBeAmplifiedCoverageResultsMap.get(getFirstParentThatHasBeenRun(ctMethod).getSimpleName());
Coverage newCoverage = coveragePerTestMethod.getCoverageOf(ctMethod.getSimpleName());
Coverage newCoverage = coveragePerTestMethod.getCoverageOf(this.currentClassTestToBeAmplified.getQualifiedName() + "#" + ctMethod.getSimpleName());
if (oldCoverage != null) {
DSpotUtils.addComment(ctMethod, "JacocoCoverageSelector: Improves instruction coverage from "
+ oldCoverage.getInstructionsCovered() + "/" + oldCoverage.getInstructionsTotal(),
Expand All @@ -158,7 +159,7 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
.collect(Collectors.toList());

this.selectedToBeAmplifiedCoverageResultsMap.putAll(methodsKept.stream()
.map(CtNamedElement::getSimpleName)
.map(ctMethod -> ctMethod.getParent(CtClass.class).getQualifiedName() + "#" + ctMethod.getSimpleName())
.collect(
Collectors.toMap(Function.identity(), coveragePerTestMethod.getCoverageResultsMap()::get)
)
Expand Down Expand Up @@ -262,8 +263,8 @@ private TestClassJSON jsonReport(Coverage coverageResults) {
testClassJSON.addTestCase(new TestCaseJSON(ctMethod.getSimpleName(),
Counter.getAssertionOfSinceOrigin(ctMethod),
Counter.getInputOfSinceOrigin(ctMethod),
this.selectedToBeAmplifiedCoverageResultsMap.get(ctMethod.getSimpleName()).getInstructionsCovered(),
this.selectedToBeAmplifiedCoverageResultsMap.get(ctMethod.getSimpleName()).getInstructionsTotal()
this.selectedToBeAmplifiedCoverageResultsMap.get(this.currentClassTestToBeAmplified.getQualifiedName() + "#" + ctMethod.getSimpleName()).getInstructionsCovered(),
this.selectedToBeAmplifiedCoverageResultsMap.get(this.currentClassTestToBeAmplified.getQualifiedName() + "#" + ctMethod.getSimpleName()).getInstructionsTotal()
))
);
// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ protected CtMethod<?> getAmplifiedTest() {
@Override
protected String getContentReportFile() {
return "1 amplified test fails on the new versions." + AmplificationHelper.LINE_SEPARATOR +
"test2(example.TestSuiteExample): String index out of range: -1java.lang.StringIndexOutOfBoundsException: String index out of range: -1" + AmplificationHelper.LINE_SEPARATOR;}
"example.TestSuiteExample#test2(example.TestSuiteExample): String index out of range: -1java.lang.StringIndexOutOfBoundsException: String index out of range: -1" + AmplificationHelper.LINE_SEPARATOR;}
}