Skip to content

Commit

Permalink
fix amplifyAllTests
Browse files Browse the repository at this point in the history
  • Loading branch information
danglotb committed Dec 20, 2016
1 parent c5bdb66 commit d8b6504
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/main/java/fr/inria/diversify/dspot/DSpot.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import fr.inria.diversify.util.FileUtils;
import fr.inria.diversify.util.InitUtils;
import fr.inria.diversify.util.PrintClassUtils;
import spoon.Launcher;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtType;

import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.*;
import java.util.stream.Collectors;

/**
* User: Simon
Expand All @@ -28,6 +28,11 @@ public class DSpot {

private List<Amplifier> amplifiers;
private int numberOfIterations;

public DiversityCompiler getCompiler() {
return compiler;
}

private DiversityCompiler compiler;
private InputProgram inputProgram;
private DiversifyClassLoader applicationClassLoader;
Expand Down Expand Up @@ -71,31 +76,29 @@ public DSpot(InputConfiguration configuration, int numberOfIterations, List<Ampl
}

public List<CtType> amplifiyAllTests() throws InterruptedException, IOException, ClassNotFoundException {
Launcher launcher = new Launcher();
launcher.addInputResource(this.inputProgram.getAbsoluteTestSourceCodeDir());
launcher.getEnvironment().setNoClasspath(true);
launcher.buildModel();
final List<CtType> amplifiedClassTest = new ArrayList<>();
launcher.getFactory().Class().getAll().forEach(classTest -> {
try {
amplifiedClassTest.add(amplifyTest(classTest.getQualifiedName()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
);
return amplifiedClassTest;
return inputProgram.getFactory().Class().getAll().stream()
.filter(ctClass ->
ctClass.getMethods().stream()
.filter(method ->
AmplificationChecker.isTest(method, inputProgram.getRelativeTestSourceCodeDir()))
.count() > 0)
.map(this::amplifyTest)
.collect(Collectors.toList());
}

public CtType amplifyTest(String fullName) throws InterruptedException, IOException, ClassNotFoundException {
return amplifyTest(inputProgram.getFactory().Type().get(fullName));
}

public CtType amplifyTest(CtType test) throws IOException, InterruptedException, ClassNotFoundException {
File logDir = new File(inputProgram.getProgramDir() + "/log");
Amplification testAmplification = new Amplification(inputProgram, compiler, applicationClassLoader, this.amplifiers, logDir);
List<CtMethod> ampTests = testAmplification.amplification(test, numberOfIterations);
return assertGenerator.generateAsserts(test, ampTests, AmplificationHelper.getAmpTestToParent());
public CtType amplifyTest(CtType test) {
try {
File logDir = new File(inputProgram.getProgramDir() + "/log");
Amplification testAmplification = new Amplification(inputProgram, compiler, applicationClassLoader, this.amplifiers, logDir);
List<CtMethod> ampTests = testAmplification.amplification(test, numberOfIterations);
return assertGenerator.generateAsserts(test, ampTests, AmplificationHelper.getAmpTestToParent());
} catch (IOException | InterruptedException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

public CtType amplifyTest(List<CtMethod> tests, CtType testClass) throws IOException, InterruptedException, ClassNotFoundException {
Expand Down

0 comments on commit d8b6504

Please sign in to comment.