Skip to content

Commit

Permalink
make order features applied in consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Mar 25, 2023
1 parent 1d39ac1 commit 63854cb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments

history.initialize();

try {
System.out.println("Press enter");
System.in.read();
} catch (IOException e) {
throw new RuntimeException(e);
}

this.timings.registerStart(Timings.Stage.BUILD_MUTATION_TESTS);
final List<MutationAnalysisUnit> tus = buildMutationTests(coverageData, history,
engine, args, allInterceptors());
Expand All @@ -182,7 +189,7 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments
final MutationAnalysisExecutor mae = new MutationAnalysisExecutor(
numberOfThreads(), resultInterceptor(), config);
this.timings.registerStart(Timings.Stage.RUN_MUTATION_TESTS);
mae.run(tus);
// mae.run(tus);
this.timings.registerEnd(Timings.Stage.RUN_MUTATION_TESTS);

LOG.info("Completed in " + timeSpan(t0));
Expand Down
7 changes: 5 additions & 2 deletions pitest/src/main/java/org/pitest/plugin/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Locale;
import java.util.Objects;

public final class Feature {
public final class Feature implements Comparable<Feature> {

private final boolean onByDefault;
private final boolean isInternal;
Expand All @@ -20,7 +20,6 @@ private Feature(boolean onByDefault, boolean isInternal, String name, String des
this.name = name;
this.description = description;
this.params = params;

}

public static Feature named(String name) {
Expand Down Expand Up @@ -83,4 +82,8 @@ public boolean equals(Object obj) {
}


@Override
public int compareTo(Feature o) {
return name.compareTo(o.name);
}
}
2 changes: 2 additions & 0 deletions pitest/src/main/java/org/pitest/plugin/FeatureSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -61,6 +62,7 @@ private List<T> selectFeatures(List<FeatureSetting> features, Collection<T> filt
}

return active.stream()
.sorted(Comparator.comparing(ProvidesFeature::provides))
.collect(Collectors.toList());
}

Expand Down
15 changes: 15 additions & 0 deletions pitest/src/test/java/org/pitest/plugin/FeatureSelectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public void doesNotDuplicateFeatures() {
assertThat(this.testee.getActiveFeatures()).hasSize(1);
}

@Test
public void ordersFeaturesConsistently() {
final FeatureSetting fooConfig = new FeatureSetting("bar", ToggleStatus.ACTIVATE, new HashMap<>());
this.testee = new FeatureSelector<>(Arrays.asList(fooConfig), features(this.onByDefault, this.offByDefault));

assertThat(this.testee.getActiveFeatures()).containsExactly(offByDefault, onByDefault);

// swap order
this.testee = new FeatureSelector<>(Arrays.asList(fooConfig), features(this.offByDefault, this.onByDefault));

assertThat(this.testee.getActiveFeatures()).containsExactly(offByDefault, onByDefault);

}


private List<FeatureSetting> noSettings() {
return Collections.emptyList();
}
Expand Down
14 changes: 14 additions & 0 deletions pitest/src/test/java/org/pitest/plugin/FeatureTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.pitest.plugin;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;

import java.util.List;

public class FeatureTest {

@Test
Expand All @@ -27,4 +30,15 @@ public void nameEqualityIsCaseInsensitive() {
.isEqualTo(Feature.named("FOO"));
}

@Test
public void ordersByName() {
Feature a = Feature.named("a");
Feature b = Feature.named("b");
Feature c = Feature.named("c");
Feature d = Feature.named("d");
List<Feature> features = asList(c, a, b, d);

assertThat(features.stream().sorted()).containsExactly(a, b, c, d);
}

}

0 comments on commit 63854cb

Please sign in to comment.