Skip to content

Commit

Permalink
feat: can now run clover on a specific tests list (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
danglotb authored Jan 13, 2021
1 parent 1d17d36 commit 65ad8b9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -40,6 +40,23 @@ public void instrumentAndRunTest(String pathToRootOfProject) {
);
}

public void instrumentAndRunGivenTest(String pathToRootOfProject, Map<String, List<String>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import spoon.reflect.declaration.CtElement;

import java.io.File;
import java.util.concurrent.ExecutionException;

public class ModifiedLinesUtils {

Expand All @@ -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) {
Expand Down

0 comments on commit 65ad8b9

Please sign in to comment.