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

do not run report interceptors during pre-scan #885

Merged
merged 1 commit into from
Apr 20, 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 @@ -20,7 +20,7 @@ public CompoundInterceptorFactory(List<FeatureSetting> features,
this.features = new FeatureSelector<>(features, filters);
}

public MutationInterceptor createInterceptor(
public CompoundMutationInterceptor createInterceptor(
ReportOptions data,
CoverageDatabase coverage,
ClassByteArraySource source) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.pitest.mutationtest.build;

import static java.util.Comparator.comparing;
import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;
import static java.util.Comparator.comparing;

public class CompoundMutationInterceptor implements MutationInterceptor {

Expand All @@ -24,6 +26,12 @@ public static MutationInterceptor nullInterceptor() {
return new CompoundMutationInterceptor(Collections.emptyList());
}

public CompoundMutationInterceptor filter(Predicate<MutationInterceptor> p) {
return new CompoundMutationInterceptor(children.stream()
.filter(p)
.collect(Collectors.toList()));
}

@Override
public void begin(ClassTree clazz) {
this.children.forEach(each -> each.begin(clazz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.pitest.mutationtest.MutationAnalyser;
import org.pitest.mutationtest.MutationConfig;
import org.pitest.mutationtest.MutationResultListener;
import org.pitest.mutationtest.build.InterceptorType;
import org.pitest.mutationtest.build.MutationAnalysisUnit;
import org.pitest.mutationtest.build.MutationGrouper;
import org.pitest.mutationtest.build.MutationInterceptor;
Expand Down Expand Up @@ -67,6 +68,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;

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

this.timings.registerStart(Timings.Stage.BUILD_MUTATION_TESTS);
final List<MutationAnalysisUnit> tus = buildMutationTests(coverageData, history,
engine, args);
engine, args, allInterceptors());
this.timings.registerEnd(Timings.Stage.BUILD_MUTATION_TESTS);

LOG.info("Created " + tus.size() + " mutation test units");
Expand Down Expand Up @@ -186,6 +188,10 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments
coverageData.createSummary());
}

private Predicate<MutationInterceptor> allInterceptors() {
return i -> true;
}

private List<MutationAnalysisUnit> findMutations(MutationEngine engine, EngineArguments args) {
// Run mutant discovery without coverage data or history.
// Ideally we'd ony discover mutants once, but the process is currently tightly
Expand All @@ -194,11 +200,15 @@ private List<MutationAnalysisUnit> findMutations(MutationEngine engine, EngineAr
// an initial run here we are able to skip coverage generation when no mutants
// are found, e.g if pitest is being run against diffs.
this.timings.registerStart(Timings.Stage.MUTATION_PRE_SCAN);
List<MutationAnalysisUnit> mutants = buildMutationTests(new NoCoverage(), new NullHistoryStore(), engine, args);
List<MutationAnalysisUnit> mutants = buildMutationTests(new NoCoverage(), new NullHistoryStore(), engine, args, noReports());
this.timings.registerEnd(Timings.Stage.MUTATION_PRE_SCAN);
return mutants;
}

private Predicate<MutationInterceptor> noReports() {
return i -> !i.type().equals(InterceptorType.REPORT);
}


private void checkExcludedRunners() {
final Collection<String> excludedRunners = this.data.getExcludedRunners();
Expand Down Expand Up @@ -289,7 +299,8 @@ private void printStats(final MutationStatisticsListener stats) {
private List<MutationAnalysisUnit> buildMutationTests(CoverageDatabase coverageData,
HistoryStore history,
MutationEngine engine,
EngineArguments args) {
EngineArguments args,
Predicate<MutationInterceptor> interceptorFilter) {

final MutationConfig mutationConfig = new MutationConfig(engine, coverage()
.getLaunchOptions());
Expand All @@ -302,7 +313,8 @@ private List<MutationAnalysisUnit> buildMutationTests(CoverageDatabase coverageD
coverageData);

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

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

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

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.engine.MutationDetailsMother.aMutationDetail;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,6 +9,16 @@
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;

import java.util.Arrays;
import java.util.Collection;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.engine.MutationDetailsMother.aMutationDetail;

@RunWith(MockitoJUnitRunner.class)
public class CompoundMutationInterceptorTest {

Expand Down Expand Up @@ -60,6 +61,16 @@ public void shouldNotifyAllChildrenOfNewClass() {
verify(this.filterChild).begin(aClass);
}

@Test
public void shouldFilterChildren() {
this.testee = new CompoundMutationInterceptor(Arrays.asList(this.modifyChild,this.filterChild));
final ClassTree aClass = new ClassTree(null);

this.testee.filter(i -> i == modifyChild).begin(aClass);
verify(this.modifyChild).begin(aClass);
verify(this.filterChild, never()).begin(aClass);
}

@Test
public void shouldChainModifiedMutantListsThroughChildrenInCorrectOrder() {

Expand Down Expand Up @@ -99,4 +110,5 @@ public void shouldNotifyAllChildrenOfEnd() {
verify(this.filterChild).end();
}


}