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

Make coverage data available to interceptors #855

Merged
merged 1 commit into from
Jan 14, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.pitest.mutationtest.commandline;

import java.util.HashMap;

import org.pitest.coverage.CoverageSummary;
import org.pitest.mutationtest.config.PluginServices;
import org.pitest.mutationtest.config.ReportOptions;
Expand All @@ -25,6 +23,8 @@
import org.pitest.mutationtest.tooling.EntryPoint;
import org.pitest.util.Unchecked;

import java.util.HashMap;

/**
* Entry point for command line interface
*/
Expand Down Expand Up @@ -96,7 +96,7 @@ private static CombinedStatistics runReport(ReportOptions data,

final EntryPoint e = new EntryPoint();
final AnalysisResult result = e.execute(null, data, plugins,
new HashMap<String, String>());
new HashMap<>());
if (result.getError().isPresent()) {
throw Unchecked.translateCheckedException(result.getError().get());
}
Expand Down
19 changes: 12 additions & 7 deletions pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

package org.pitest.coverage;

import static java.util.stream.Collectors.toCollection;
import org.pitest.classinfo.ClassInfo;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.CodeSource;
import org.pitest.functional.FCollection;
import org.pitest.testapi.Description;
import org.pitest.util.Log;

import java.math.BigInteger;
import java.util.ArrayList;
Expand All @@ -35,12 +40,7 @@
import java.util.logging.Logger;
import java.util.stream.Stream;

import org.pitest.classinfo.ClassInfo;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.CodeSource;
import org.pitest.functional.FCollection;
import org.pitest.testapi.Description;
import org.pitest.util.Log;
import static java.util.stream.Collectors.toCollection;

public class CoverageData implements CoverageDatabase {

Expand Down Expand Up @@ -185,6 +185,11 @@ public CoverageSummary createSummary() {
return new CoverageSummary(numberOfLines(), coveredLines());
}

@Override
public Map<InstructionLocation, Set<TestInfo>> getInstructionCoverage() {
return Collections.unmodifiableMap(this.instructionCoverage);
}

private BigInteger generateCoverageNumber(
final Map<ClassLine, Set<TestInfo>> coverage) {
BigInteger coverageNumber = BigInteger.ZERO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.pitest.coverage;

import java.math.BigInteger;
import java.util.Collection;

import org.pitest.classinfo.ClassInfo;
import org.pitest.classinfo.ClassName;

import java.math.BigInteger;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

public interface CoverageDatabase {

Collection<ClassInfo> getClassInfo(Collection<ClassName> classes);
Expand All @@ -24,4 +26,7 @@ public interface CoverageDatabase {

CoverageSummary createSummary();

Map<InstructionLocation, Set<TestInfo>> getInstructionCoverage();


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.pitest.mutationtest.build;

import org.pitest.classinfo.ClassByteArraySource;
import org.pitest.coverage.CoverageDatabase;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.plugin.FeatureSelector;
import org.pitest.plugin.FeatureSetting;
Expand All @@ -21,18 +22,22 @@ public CompoundInterceptorFactory(List<FeatureSetting> features,

public MutationInterceptor createInterceptor(
ReportOptions data,
CoverageDatabase coverage,
ClassByteArraySource source) {
final List<MutationInterceptor> interceptors = this.features.getActiveFeatures().stream()
.map(toInterceptor(this.features, data, source))
.map(toInterceptor(this.features, data, coverage, source))
.collect(Collectors.toList());
return new CompoundMutationInterceptor(interceptors);
}


private static Function<MutationInterceptorFactory, MutationInterceptor> toInterceptor(
final FeatureSelector<MutationInterceptorFactory> features, final ReportOptions data, final ClassByteArraySource source) {
FeatureSelector<MutationInterceptorFactory> features,
ReportOptions data,
CoverageDatabase coverage,
ClassByteArraySource source) {

return a -> a.createInterceptor(new InterceptorParameters(features.getSettingForFeature(a.provides().name()), data, source));
return a -> a.createInterceptor(new InterceptorParameters(features.getSettingForFeature(a.provides().name()), data, coverage, source));

}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
package org.pitest.mutationtest.build;

import java.util.Collections;
import java.util.List;

import org.pitest.classinfo.ClassByteArraySource;
import java.util.Optional;
import org.pitest.coverage.CoverageDatabase;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.plugin.FeatureParameter;
import org.pitest.plugin.FeatureSetting;

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

public final class InterceptorParameters {

private final FeatureSetting conf;
private final ReportOptions data;
private final ClassByteArraySource source;
private final CoverageDatabase coverage;


public InterceptorParameters(FeatureSetting conf, ReportOptions data,
public InterceptorParameters(FeatureSetting conf, ReportOptions data, CoverageDatabase coverage,
ClassByteArraySource source) {
this.conf = conf;
this.data = data;
this.coverage = coverage;
this.source = source;
}

public ReportOptions data() {
return this.data;
}

public CoverageDatabase coverage() {
return this.coverage;
}

public Optional<FeatureSetting> settings() {
return Optional.ofNullable(this.conf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private List<MutationAnalysisUnit> buildMutationTests(
coverageData);

final MutationInterceptor interceptor = this.settings.getInterceptor()
.createInterceptor(this.data, bas);
.createInterceptor(this.data, coverageData, bas);

final MutationSource source = new MutationSource(mutationConfig, testPrioritiser, bas, interceptor);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.pitest.mutationtest.build;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.pitest.plugin.FeatureParameter;
import org.pitest.plugin.FeatureSetting;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import java.util.Optional;
import org.pitest.plugin.FeatureParameter;
import org.pitest.plugin.FeatureSetting;

import static org.assertj.core.api.Assertions.assertThat;

public class InterceptorParametersTest {

Expand All @@ -30,7 +30,7 @@ public void shouldReturnNoneWhenValueAbsent() {

@Test
public void shouldReturnNoneWhenFeatureSettingsAbsent() {
this.testee = new InterceptorParameters(null, null, null);
this.testee = new InterceptorParameters(null, null, null, null);
assertThat(this.testee.getString(FeatureParameter.named("foo"))).isEqualTo(Optional.empty());
}

Expand All @@ -49,8 +49,8 @@ public void shouldReturnListsOfStringsWhenPresent() {
private InterceptorParameters makeFor(String key, String ... vals) {
final Map<String, List<String>> values = new HashMap<>();
values.put(key, Arrays.asList(vals));
final FeatureSetting fs = new FeatureSetting(null, null,values);
return new InterceptorParameters(fs, null, null);
final FeatureSetting fs = new FeatureSetting(null, null, values);
return new InterceptorParameters(fs, null, null,null);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package org.pitest.mutationtest.build;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;

import java.util.Collection;
import java.util.Collections;
import java.util.logging.Logger;

import org.junit.Before;
import org.junit.Test;
import org.pitest.classinfo.ClassByteArraySource;
Expand All @@ -27,6 +20,13 @@
import org.pitest.mutationtest.engine.gregor.config.GregorEngineFactory;
import org.pitest.util.ResourceFolderByteArraySource;

import java.util.Collection;
import java.util.Collections;
import java.util.logging.Logger;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;

/**
* Tests discovery of mutants - including the full default interceptor chain
*/
Expand Down Expand Up @@ -261,7 +261,7 @@ MutationSource createSource(ClassByteArraySource source) {
final SettingsFactory settings = new SettingsFactory(this.data,
PluginServices.makeForContextLoader());
final MutationInterceptor interceptor = settings.getInterceptor()
.createInterceptor(this.data, source);
.createInterceptor(this.data, null, source);

final MutationEngine engine = new GregorEngineFactory().createEngine(
EngineArguments.arguments().withExcludedMethods(this.data.getExcludedMethods())
Expand Down