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

Guarantee order of mutation operators #921

Merged
merged 1 commit into from
Aug 12, 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 @@ -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