Skip to content

Commit

Permalink
Merge pull request #955 from hcoles/feature/exclude_mutators
Browse files Browse the repository at this point in the history
support simple mutator exclusion for #954
  • Loading branch information
hcoles authored Nov 1, 2021
2 parents dc0adab + e617c1f commit b3e3ee1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Read all about it at http://pitest.org

### 1.7.3 (unreleased)

* #952 Mutate map return to emptyMap instead of null
* #952 Mutate map return to `emptyMap` instead of null
* #954 Allow mutators to be excluded

### 1.7.2

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

import com.example.HasPrivateStreamMethodUsedOnlyInSingleFlatMap;
import org.junit.Before;
import org.junit.Test;
import org.pitest.classinfo.ClassByteArraySource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MutationEngine createEngine(EngineArguments args) {
createMutatorListFromArrayOrUseDefaults(args.mutators()));
}

public MutationEngine createEngineWithMutators(
MutationEngine createEngineWithMutators(
final Collection<String> excludedMethods,
final Collection<? extends MethodMutatorFactory> mutators) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,23 @@ public static Collection<MethodMutatorFactory> byName(final String name) {
public static Collection<MethodMutatorFactory> fromStrings(
final Collection<String> names) {

List<String> exclusions = names.stream()
.filter(s -> s.startsWith("-"))
.map(s -> s.substring(1))
.collect(Collectors.toList());

List<String> inclusions = names.stream()
.filter(s -> !s.startsWith("-"))
.collect(Collectors.toList());

final Set<MethodMutatorFactory> unique = new TreeSet<>(compareId());
FCollection.flatMapTo(names, fromString(MUTATORS), unique);
FCollection.flatMapTo(inclusions, fromString(MUTATORS), unique);

final Set<MethodMutatorFactory> excluded = new TreeSet<>(compareId());
FCollection.flatMapTo(exclusions, fromString(MUTATORS), excluded);

unique.removeAll(excluded);

return unique;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.pitest.mutationtest.engine.gregor.config;

import org.junit.Test;
import org.pitest.mutationtest.EngineArguments;
import org.pitest.mutationtest.engine.MutationEngine;

import java.util.List;

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

public class GregorEngineFactoryTest {

GregorEngineFactory underTest = new GregorEngineFactory();

@Test
public void parsesSingleMutatorString() {
MutationEngine actual = parseMutators(asList("NULL_RETURNS"));

assertThat(actual.getMutatorNames()).contains("NULL_RETURNS");
}

@Test
public void parsesGroups() {
MutationEngine actual = parseMutators(asList("STRONGER"));

assertThat(actual.getMutatorNames()).contains("NULL_RETURNS", "REMOVE_CONDITIONALS_EQUAL_ELSE");
}

@Test
public void parsesExclusions() {
MutationEngine excluded = parseMutators(asList("STRONGER", "-REMOVE_CONDITIONALS_EQUAL_ELSE"));

assertThat(excluded.getMutatorNames()).doesNotContain("REMOVE_CONDITIONALS_EQUAL_ELSE");
assertThat(excluded.getMutatorNames()).isNotEmpty();
}

@Test
public void excludesGroups() {
MutationEngine excluded = parseMutators(asList("ALL", "-ALL"));
assertThat(excluded.getMutatorNames()).isEmpty();
}

private MutationEngine parseMutators(List<String> mutators) {
return underTest.createEngine(EngineArguments.arguments().withMutators(mutators));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;

import org.junit.Test;
import org.pitest.mutationtest.engine.MutationEngine;
import org.pitest.mutationtest.engine.gregor.MethodMutatorFactory;
import org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator;
import org.pitest.mutationtest.engine.gregor.mutators.InvertNegsMutator;
Expand Down Expand Up @@ -290,6 +291,17 @@ public void overlappingGroupsDoNotCauseDuplicates() {
.hasSameSizeAs(parseStrings("DEFAULTS", "INCREMENTS"));
}

@Test
public void parsesExclusions() {
assertThat(parseStrings("DEFAULTS", "-INCREMENTS"))
.noneMatch(m -> m.getName().equals("INCREMENTS"));
}

@Test
public void excludesGroups() {
assertThat(parseStrings("DEFAULTS", "STRONGER", "-ALL")).isEmpty();
}

private Collection<MethodMutatorFactory> parseStrings(final String... s) {
return Mutator.fromStrings(asList(s));
}
Expand Down

0 comments on commit b3e3ee1

Please sign in to comment.