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

feat: can now run clover on a specific tests list #984

Merged
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
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