From dc68b4accb116d40ba47b0d89fe5d8859bd2ca86 Mon Sep 17 00:00:00 2001 From: danglotb Date: Mon, 11 Jan 2021 15:59:11 +0100 Subject: [PATCH] feat: can now run clover on a specific tests list --- .../clover/CloverExecutor.java | 23 ++++++++++++++++--- .../configuration/Configuration.java | 11 +++++++++ .../diff/ModifiedLinesUtils.java | 11 ++++++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/clover/CloverExecutor.java b/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/clover/CloverExecutor.java index 4986a5acd..4bc2d723e 100644 --- a/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/clover/CloverExecutor.java +++ b/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/clover/CloverExecutor.java @@ -7,11 +7,10 @@ import org.apache.maven.shared.invoker.MavenInvocationException; import java.io.File; -import java.util.Arrays; -import java.util.Optional; -import java.util.Properties; +import java.util.*; import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.Collectors; /** * Created by Benjamin DANGLOT @@ -28,6 +27,7 @@ public class CloverExecutor { /** * This class will execute, though maven goals, the instrumentation of Clover and the test of the project + * * @param pathToRootOfProject the path to the root folder of the project */ public void instrumentAndRunTest(String pathToRootOfProject) { @@ -40,6 +40,23 @@ public void instrumentAndRunTest(String pathToRootOfProject) { ); } + public void instrumentAndRunGivenTest(String pathToRootOfProject, Map> tests) { + final String testsOptionsValue = tests.keySet() + .stream() + .map(key -> + key + "#" + String.join("+", tests.get(key)) + ).collect(Collectors.joining(",")); + System.out.println(testsOptionsValue); + setMavenHome(); + runGoals( + pathToRootOfProject, + "clean", + "org.openclover:clover-maven-plugin:4.4.1:setup", + "test", + "-Dtest=" + testsOptionsValue + ); + } + private int runGoals(String pathToRootOfProject, String... goals) { InvocationRequest request = new DefaultInvocationRequest(); diff --git a/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/configuration/Configuration.java b/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/configuration/Configuration.java index 860d6b51f..52d7c2f93 100644 --- a/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/configuration/Configuration.java +++ b/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/configuration/Configuration.java @@ -83,4 +83,15 @@ public enum ReportEnum { } } + @Override + public String toString() { + return "Configuration{" + + "pathToFirstVersion='" + pathToFirstVersion + '\'' + + ", pathToSecondVersion='" + pathToSecondVersion + '\'' + + ", outputPath='" + outputPath + '\'' + + ", reportFormat=" + reportFormat + + ", diff='" + diff + '\'' + + ", enhanced=" + enhanced + + '}'; + } } diff --git a/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/diff/ModifiedLinesUtils.java b/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/diff/ModifiedLinesUtils.java index 6bf472f50..f2d8b96a2 100644 --- a/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/diff/ModifiedLinesUtils.java +++ b/dspot-diff-test-selection/src/main/java/eu/stamp_project/diff_test_selection/diff/ModifiedLinesUtils.java @@ -5,6 +5,7 @@ import spoon.reflect.declaration.CtElement; import java.io.File; +import java.util.concurrent.ExecutionException; public class ModifiedLinesUtils { @@ -20,9 +21,13 @@ public static CtElement filterOperation(Operation operation) { } public static boolean filterOperationFromNode(CtElement element) { - return element.getPosition() != null && - element.getPosition().getCompilationUnit() != null && - element.getPosition().getCompilationUnit().getMainType() != null; + try { + return element.getPosition() != null && + element.getPosition().getCompilationUnit() != null && + element.getPosition().getCompilationUnit().getMainType() != null; + } catch (Exception e) { + return false; + } } public static boolean shouldSkip(String pathToFirstVersion, String file1, String file2) {