Skip to content

Commit

Permalink
Merge pull request #1321 from hcoles/feature/report_issues
Browse files Browse the repository at this point in the history
Feature/report issues
  • Loading branch information
hcoles authored Apr 8, 2024
2 parents 1cf23ab + e52d86c commit a6a4eec
Show file tree
Hide file tree
Showing 31 changed files with 350 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ private MutationResultListener createResultListener(SourceLocator sourceLocator,
final CodeSource codeSource = this.codeSourceAggregator.createCodeSource();
final ReportCoverage coverageDatabase = calculateCoverage(codeSource);

return new MutationHtmlReportListener(outputCharset, coverageDatabase, this.resultOutputStrategy, mutatorNames, partialCoverage, sourceLocator);
return new MutationHtmlReportListener(outputCharset,
coverageDatabase,
this.resultOutputStrategy,
mutatorNames,
partialCoverage,
Collections.emptyList(),
true,
sourceLocator);
}

private Collection<Path> asPaths(Collection<File> files) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import org.pitest.coverage.ReportCoverage;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.mutationtest.engine.MutationEngine;
import org.pitest.mutationtest.verify.BuildMessage;
import org.pitest.plugin.FeatureSetting;
import org.pitest.util.ResultOutputStrategy;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Data passed to the listener MutationResultListener factories for use when
Expand All @@ -22,15 +26,17 @@ public class ListenerArguments {
private final boolean fullMutationMatrix;
private final ReportOptions data;
private final FeatureSetting setting;
private final List<BuildMessage> issues;

public ListenerArguments(ResultOutputStrategy outputStrategy,
ReportCoverage coverage,
SourceLocator locator,
MutationEngine engine,
long startTime,
boolean fullMutationMatrix,
ReportOptions data) {
this(outputStrategy, coverage, locator, engine, startTime, fullMutationMatrix, data, null);
ReportOptions data,
List<BuildMessage> issues) {
this(outputStrategy, coverage, locator, engine, startTime, fullMutationMatrix, data, null, issues);
}

ListenerArguments(ResultOutputStrategy outputStrategy,
Expand All @@ -40,7 +46,8 @@ public ListenerArguments(ResultOutputStrategy outputStrategy,
long startTime,
boolean fullMutationMatrix,
ReportOptions data,
FeatureSetting setting) {
FeatureSetting setting,
List<BuildMessage> issues) {
this.outputStrategy = outputStrategy;
this.coverage = coverage;
this.locator = locator;
Expand All @@ -49,6 +56,10 @@ public ListenerArguments(ResultOutputStrategy outputStrategy,
this.fullMutationMatrix = fullMutationMatrix;
this.data = data;
this.setting = setting;
this.issues = issues.stream()
.distinct()
.sorted()
.collect(Collectors.toList());
}

public ResultOutputStrategy getOutputStrategy() {
Expand Down Expand Up @@ -83,6 +94,10 @@ public Optional<FeatureSetting> settings() {
return Optional.ofNullable(setting);
}

public List<BuildMessage> issues() {
return Collections.unmodifiableList(issues);
}

public ListenerArguments withSetting(FeatureSetting setting) {
return new ListenerArguments(outputStrategy,
coverage,
Expand All @@ -91,7 +106,8 @@ public ListenerArguments withSetting(FeatureSetting setting) {
startTime,
fullMutationMatrix,
data,
setting);
setting,
issues);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public class ReportOptions {
private Charset inputEncoding;
private Charset outputEncoding;

private boolean arcmutateMissing = true;

// currently used only via maven
private Map<String,String> environmentVariables = new HashMap<>();

Expand Down Expand Up @@ -666,6 +668,14 @@ public Map<String,String> getEnvironmentVariables() {
return environmentVariables;
}

public boolean isArcmutateMissing() {
return arcmutateMissing;
}

public void setArcmutateMissing(boolean arcmutateMissing) {
this.arcmutateMissing = arcmutateMissing;
}

@Override
public String toString() {
return new StringJoiner(", ", ReportOptions.class.getSimpleName() + "[", "]")
Expand Down Expand Up @@ -714,8 +724,8 @@ public String toString() {
.add("inputEncoding=" + inputEncoding)
.add("outputEncoding=" + outputEncoding)
.add("reportCoverage=" + reportCoverage)
.add("arcmutateMissing=" + arcmutateMissing)
.toString();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.pitest.coverage.CoverageSummary;
import org.pitest.mutationtest.statistics.MutationStatistics;
import org.pitest.mutationtest.verify.BuildMessage;

import java.util.List;

Expand All @@ -10,11 +11,11 @@ public class CombinedStatistics {
private final MutationStatistics mutationStatistics;
private final CoverageSummary coverageSummary;

private final List<String> issues;
private final List<BuildMessage> issues;

public CombinedStatistics(MutationStatistics mutationStatistics,
CoverageSummary coverageSummary,
List<String> issues) {
List<BuildMessage> issues) {
this.mutationStatistics = mutationStatistics;
this.coverageSummary = coverageSummary;
this.issues = issues;
Expand All @@ -28,7 +29,7 @@ public CoverageSummary getCoverageSummary() {
return this.coverageSummary;
}

public List<String> getIssues() {
public List<BuildMessage> getIssues() {
return issues;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.pitest.mutationtest.incremental.NullHistory;
import org.pitest.mutationtest.incremental.NullWriterFactory;
import org.pitest.mutationtest.incremental.WriterFactory;
import org.pitest.mutationtest.verify.BuildVerifierArguments;
import org.pitest.plugin.Feature;
import org.pitest.plugin.FeatureParameter;
import org.pitest.plugin.FeatureParser;
Expand Down Expand Up @@ -127,7 +128,7 @@ public AnalysisResult execute(File baseDir, ReportOptions data,
final MutationStrategies strategies = new MutationStrategies(
settings.createEngine(), history, coverageDatabase, reportFactory, settings.getResultInterceptor().add(new HistoryResultInterceptor(history)),
settings.createCoverageTransformer(code),
reportOutput, settings.createVerifier().create(code));
reportOutput, settings.createVerifier().create(new BuildVerifierArguments(code, data)));

final MutationCoverage report = new MutationCoverage(strategies, baseDir,
code, data, settings, timings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.pitest.mutationtest.statistics.MutationStatistics;
import org.pitest.mutationtest.statistics.MutationStatisticsListener;
import org.pitest.mutationtest.statistics.Score;
import org.pitest.mutationtest.verify.BuildMessage;
import org.pitest.util.Log;
import org.pitest.util.StringUtil;
import org.pitest.util.Timings;
Expand Down Expand Up @@ -113,7 +114,7 @@ public CombinedStatistics runReport() throws IOException {

final long t0 = System.nanoTime();

List<String> issues = verifyBuildSuitableForMutationTesting();
List<BuildMessage> issues = verifyBuildSuitableForMutationTesting();

checkExcludedRunners();

Expand Down Expand Up @@ -142,7 +143,7 @@ private CombinedStatistics emptyStatistics() {
return new CombinedStatistics(mutationStatistics, new CoverageSummary(0,0), Collections.emptyList());
}

private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments args, MutationEngine engine, List<String> issues) {
private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments args, MutationEngine engine, List<BuildMessage> issues) {
History history = this.strategies.history();
history.initialize();

Expand Down Expand Up @@ -170,7 +171,7 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments

ReportCoverage modifiedCoverage = transformCoverage(coverageData);
final List<MutationResultListener> config = createConfig(t0, modifiedCoverage, history,
stats, engine);
stats, engine, issues);
final MutationAnalysisExecutor mae = new MutationAnalysisExecutor(
numberOfThreads(), resultInterceptor(), config);
this.timings.registerStart(Timings.Stage.RUN_MUTATION_TESTS);
Expand Down Expand Up @@ -254,14 +255,14 @@ private List<MutationResultListener> createConfig(long t0,
ReportCoverage coverageData,
History history,
MutationStatisticsListener stats,
MutationEngine engine) {
MutationEngine engine, List<BuildMessage> issues) {
final List<MutationResultListener> ls = new ArrayList<>();

ls.add(stats);

final ListenerArguments args = new ListenerArguments(
this.strategies.output(), coverageData, new SmartSourceLocator(
data.getSourcePaths(), this.data.getInputEncoding()), engine, t0, this.data.isFullMutationMatrix(), data);
data.getSourcePaths(), this.data.getInputEncoding()), engine, t0, this.data.isFullMutationMatrix(), data, issues);

final MutationResultListener mutationReportListener = this.strategies
.listenerFactory().getListener(this.data.getFreeFormProperties(), args);
Expand All @@ -279,8 +280,8 @@ private MutationResultInterceptor resultInterceptor() {
return this.strategies.resultInterceptor();
}

private List<String> verifyBuildSuitableForMutationTesting() {
return this.strategies.buildVerifier().verify();
private List<BuildMessage> verifyBuildSuitableForMutationTesting() {
return this.strategies.buildVerifier().verifyBuild();
}

private void printStats(CombinedStatistics combinedStatistics) {
Expand Down Expand Up @@ -314,8 +315,8 @@ private void printStats(CombinedStatistics combinedStatistics) {

if (!combinedStatistics.getIssues().isEmpty()) {
ps.println();
ps.println("!! The following issues were detected during the run !!");
combinedStatistics.getIssues().forEach(ps::println);
ps.println("Build messages:- ");
combinedStatistics.getIssues().forEach(m -> ps.println("* " + m));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.pitest.mutationtest.verify;

import java.util.Objects;
import java.util.Optional;

public final class BuildMessage implements Comparable<BuildMessage> {
private final String text;
private final String url;
private final int priority;

public BuildMessage(String text, String url, int priority) {
this.text = text;
this.url = url;
this.priority = priority;
}

public static BuildMessage buildMessage(String text) {
return new BuildMessage(text, null, 5);
}

public String text() {
return text;
}

public String url() {
return url;
}

public int priority() {
return priority;
}

@Override
public String toString() {
return text + Optional.ofNullable(url)
.map( u -> " (" + u + ")").orElse("");
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BuildMessage that = (BuildMessage) o;
return priority == that.priority && Objects.equals(text, that.text) && Objects.equals(url, that.url);
}

@Override
public int hashCode() {
return Objects.hash(text, url, priority);
}

@Override
public int compareTo(BuildMessage o) {
return Integer.compare(this.priority, o.priority);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.pitest.mutationtest.verify;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Checks project for potential issues. Should throw an exception
Expand All @@ -9,6 +11,15 @@
*/
public interface BuildVerifier {

List<String> verify();
@Deprecated
default List<String> verify() {
return Collections.emptyList();
}

default List<BuildMessage> verifyBuild() {
return verify().stream()
.map(BuildMessage::buildMessage)
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.pitest.mutationtest.verify;

import org.pitest.classpath.CodeSource;
import org.pitest.mutationtest.config.ReportOptions;

public class BuildVerifierArguments {

private final CodeSource code;
private final ReportOptions data;

public BuildVerifierArguments(CodeSource code, ReportOptions data) {
this.code = code;
this.data = data;
}

public ReportOptions data() {
return data;
}

public CodeSource code() {
return code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@

public interface BuildVerifierFactory extends ToolClasspathPlugin {

BuildVerifier create(CodeSource code);
default BuildVerifier create(BuildVerifierArguments args) {
return create(args.code());
}

@Deprecated
default BuildVerifier create(CodeSource code) {
throw new IllegalStateException();
}
}
Loading

0 comments on commit a6a4eec

Please sign in to comment.