Skip to content

Commit

Permalink
Merge pull request #921 from hcoles/guarantee_mutator_order
Browse files Browse the repository at this point in the history
Guarantee order of mutation operators
  • Loading branch information
hcoles authored Aug 12, 2021
2 parents 0910d03 + b3bfedc commit 2466033
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
Expand All @@ -46,13 +46,13 @@ public class GregorMutater implements Mutater {
private final Map<String, String> computeCache = new HashMap<>();
private final Predicate<MethodInfo> filter;
private final ClassByteArraySource byteSource;
private final Set<MethodMutatorFactory> mutators = new HashSet<>();
private final List<MethodMutatorFactory> mutators;

public GregorMutater(final ClassByteArraySource byteSource,
final Predicate<MethodInfo> filter,
final Collection<MethodMutatorFactory> mutators) {
this.filter = filter;
this.mutators.addAll(mutators);
this.mutators = orderAndDeDuplicate(mutators);
this.byteSource = byteSource;
}

Expand Down Expand Up @@ -134,4 +134,13 @@ private static Predicate<MethodInfo> isGeneratedEnumMethod() {
return MethodInfo::isGeneratedEnumMethod;
}

private List<MethodMutatorFactory> orderAndDeDuplicate(Collection<MethodMutatorFactory> mutators) {
// deduplication is based on object identity, so dubious that this adds any value
// however left in place for now to replicate HashSet behaviour
return mutators.stream()
.distinct()
.sorted(Comparator.comparing(MethodMutatorFactory::getGloballyUniqueId))
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
*/
package org.pitest.mutationtest.engine.gregor;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.function.Predicate;

import org.objectweb.asm.ClassVisitor;
Expand All @@ -32,15 +30,15 @@ class MutatingClassVisitor extends ClassVisitor {

private final Predicate<MethodInfo> filter;
private final ClassContext context;
private final Set<MethodMutatorFactory> methodMutators = new HashSet<>();
private final List<MethodMutatorFactory> methodMutators;

MutatingClassVisitor(final ClassVisitor delegateClassVisitor,
final ClassContext context, final Predicate<MethodInfo> filter,
final Collection<MethodMutatorFactory> mutators) {
final List<MethodMutatorFactory> mutators) {
super(ASMVersion.ASM_VERSION, delegateClassVisitor);
this.context = context;
this.filter = filter;
this.methodMutators.addAll(mutators);
this.methodMutators = mutators;
}

@Override
Expand Down

0 comments on commit 2466033

Please sign in to comment.