Search in sources :

Example 1 with TestCompiler

use of eu.stamp_project.dspot.common.compilation.TestCompiler in project dspot by STAMP-project.

the class ProjectJSONTest method setUp.

@Before
public void setUp() {
    super.setUp();
    this.configuration = new UserInput();
    this.configuration.setAbsolutePathToProjectRoot(getPathToProjectRoot());
    this.configuration.setOutputDirectory(outputDirectory);
    this.builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
    this.initializeDSpot = new InitializeDSpot();
    String dependencies = initializeDSpot.completeDependencies(configuration, this.builder);
    DSpotUtils.init(CommentEnum.None, outputDirectory, this.configuration.getFullClassPathWithExtraDependencies(), this.getPathToProjectRoot());
    this.compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
    DSpotCache.init(10000);
    Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource(this.getPathToProjectRoot());
    launcher.buildModel();
    this.factory = launcher.getFactory();
    TestFramework.init(this.factory);
    testCompiler = new TestCompiler(0, false, this.getPathToProjectRoot(), this.configuration.getClasspathClassesProject(), 10000, "", false);
    AssertionGeneratorUtils.init(false);
    DSpotPOMCreator.createNewPom(configuration);
    RandomHelper.setSeedRandom(72L);
    ValueCreator.count = 0;
    this.testSelector = new JacocoCoverageSelector(builder, configuration);
    try {
        FileUtils.forceDelete(new File(outputDirectory));
    } catch (Exception ignored) {
    }
}
Also used : TestCompiler(eu.stamp_project.dspot.common.compilation.TestCompiler) JacocoCoverageSelector(eu.stamp_project.dspot.selector.JacocoCoverageSelector) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) Launcher(spoon.Launcher) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) Before(org.junit.Before)

Example 2 with TestCompiler

use of eu.stamp_project.dspot.common.compilation.TestCompiler in project dspot by STAMP-project.

the class InitializeDSpot method init.

public void init(UserInput userInput) {
    this.DSpotState = new DSpotState();
    DSpotState.setUserInput(userInput);
    DSpotState.setOnlyInputAmplification(userInput.isOnlyInputAmplification());
    DSpotState.setDevFriendlyAmplification(userInput.isDevFriendlyAmplification());
    DSpotState.verbose = userInput.isVerbose();
    DSpotState.setStartTime(System.currentTimeMillis());
    DSpotState.setTestFinder(new TestFinder(Arrays.stream(userInput.getExcludedClasses().split(",")).collect(Collectors.toList()), Arrays.stream(userInput.getExcludedTestCases().split(",")).collect(Collectors.toList())));
    DSpotState.setAutomaticBuilder(userInput.getBuilderEnum().getAutomaticBuilder(userInput));
    final String dependencies = completeDependencies(userInput, DSpotState.getAutomaticBuilder());
    DSpotState.setCompiler(DSpotCompiler.createDSpotCompiler(userInput, dependencies));
    userInput.setFactory(DSpotState.getCompiler().getLauncher().getFactory());
    initHelpers(userInput);
    DSpotState.setTestCompiler(new TestCompiler(userInput.getNumberParallelExecutionProcessors(), userInput.shouldExecuteTestsInParallel(), userInput.getAbsolutePathToProjectRoot(), userInput.getClasspathClassesProject(), userInput.getTimeOutInMs(), userInput.getPreGoalsTestExecution(), userInput.shouldUseMavenToExecuteTest()));
    final EmailSender emailSender = new EmailSender(userInput.getSmtpUsername(), userInput.getSmtpPassword(), userInput.getSmtpHost(), userInput.getSmtpPort(), userInput.isSmtpAuth(), userInput.getSmtpTls());
    DSpotState.setCollector(CollectorFactory.build(userInput, emailSender));
    DSpotState.getCollector().reportInitInformation(userInput.getAmplifiers(), userInput.getSelector(), userInput.getNbIteration(), userInput.isGregorMode(), !userInput.isGregorMode(), userInput.getNumberParallelExecutionProcessors());
    DSpotState.setTestClassesToBeAmplified(DSpotState.getTestFinder().findTestClasses(userInput.getTestClasses()));
    DSpotState.setTestMethodsToBeAmplifiedNames(userInput.getTestCases());
    if (DSpotState.getTestMethodsToBeAmplifiedNames().size() == 1 && DSpotState.getTestMethodsToBeAmplifiedNames().get(0).isEmpty()) {
        DSpotState.getTestMethodsToBeAmplifiedNames().clear();
    }
    DSpotState.setTestSelector(userInput.getSelector().buildSelector(DSpotState.getAutomaticBuilder(), userInput));
    final List<Amplifier> amplifiers = userInput.getAmplifiers().stream().map(AmplifierEnum::getAmplifier).filter(Objects::nonNull).collect(Collectors.toList());
    DSpotState.setInputAmplDistributor(userInput.getInputAmplDistributor().getInputAmplDistributor(userInput.getMaxTestAmplified(), amplifiers));
    DSpotState.setOutput(new Output(userInput.getAbsolutePathToProjectRoot(), userInput.getOutputDirectory(), DSpotState.getCollector()));
    DSpotState.setAssertionGenerator(new AssertionGenerator(userInput.getDelta(), DSpotState.getCompiler(), DSpotState.getTestCompiler(), DSpotState.isDevFriendlyAmplification()));
    Checker.postChecking(userInput);
    DSpotState.setCollectData(true);
    DSpotState.setDelta(userInput.getDelta());
    DSpotState.setNbIteration(userInput.getNbIteration());
    DSpotState.verbose = userInput.isVerbose();
}
Also used : TestCompiler(eu.stamp_project.dspot.common.compilation.TestCompiler) AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) Output(eu.stamp_project.dspot.common.report.output.Output) AmplifierEnum(eu.stamp_project.dspot.common.configuration.options.AmplifierEnum) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) EmailSender(eu.stamp_project.dspot.common.collector.smtp.EmailSender) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)

Example 3 with TestCompiler

use of eu.stamp_project.dspot.common.compilation.TestCompiler in project dspot by STAMP-project.

the class AbstractSelectorRemoveOverlapTest method setUp.

@Before
public void setUp() {
    DSpotState.verbose = true;
    this.configuration = new UserInput();
    this.configuration.setAbsolutePathToProjectRoot(getPathToAbsoluteProjectRoot());
    this.configuration.setOutputDirectory(outputDirectory);
    this.builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
    this.initializeDSpot = new InitializeDSpot();
    String dependencies = initializeDSpot.completeDependencies(configuration, this.builder);
    DSpotUtils.init(CommentEnum.None, outputDirectory, this.configuration.getFullClassPathWithExtraDependencies(), this.getPathToAbsoluteProjectRoot());
    this.compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
    DSpotCache.init(10000);
    Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource(this.getPathToAbsoluteProjectRoot());
    launcher.buildModel();
    this.factory = launcher.getFactory();
    TestFramework.init(this.factory);
    this.testCompiler = new TestCompiler(0, false, this.getPathToAbsoluteProjectRoot(), this.configuration.getClasspathClassesProject(), 10000, "", false);
    AssertionGeneratorUtils.init(false);
    DSpotPOMCreator.createNewPom(configuration);
    RandomHelper.setSeedRandom(72L);
    ValueCreator.count = 0;
    this.testSelectorUnderTest = this.getTestSelector();
}
Also used : TestCompiler(eu.stamp_project.dspot.common.compilation.TestCompiler) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) Launcher(spoon.Launcher) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) Before(org.junit.Before)

Example 4 with TestCompiler

use of eu.stamp_project.dspot.common.compilation.TestCompiler in project dspot by STAMP-project.

the class AbstractSelectorTest method setUp.

@Before
public void setUp() throws Exception {
    DSpotState.verbose = true;
    this.configuration = new UserInput();
    this.configuration.setAbsolutePathToProjectRoot(getPathToAbsoluteProjectRoot());
    this.configuration.setOutputDirectory(outputDirectory);
    this.configuration.setGregorMode(true);
    this.builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
    this.initializeDSpot = new InitializeDSpot();
    String dependencies = initializeDSpot.completeDependencies(configuration, this.builder);
    DSpotUtils.init(CommentEnum.None, outputDirectory, this.configuration.getFullClassPathWithExtraDependencies(), this.getPathToAbsoluteProjectRoot());
    this.compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
    DSpotCache.init(10000);
    Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource(this.getPathToAbsoluteProjectRoot());
    launcher.buildModel();
    this.factory = launcher.getFactory();
    TestFramework.init(this.factory);
    this.testRunner = new TestRunner(this.getPathToAbsoluteProjectRoot(), "", false);
    this.testCompiler = new TestCompiler(0, false, this.getPathToAbsoluteProjectRoot(), this.configuration.getClasspathClassesProject(), 10000, "", false);
    AssertionGeneratorUtils.init(false);
    DSpotPOMCreator.createNewPom(configuration);
    RandomHelper.setSeedRandom(72L);
    ValueCreator.count = 0;
    this.testSelectorUnderTest = this.getTestSelector();
}
Also used : TestCompiler(eu.stamp_project.dspot.common.compilation.TestCompiler) TestRunner(eu.stamp_project.dspot.common.execution.TestRunner) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) Launcher(spoon.Launcher) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) Before(org.junit.Before)

Example 5 with TestCompiler

use of eu.stamp_project.dspot.common.compilation.TestCompiler in project dspot by STAMP-project.

the class ProjectJSONTest method test.

@Test
public void test() throws Exception {
    final File file = new File(outputDirectory + "/sample.json");
    if (file.exists()) {
        file.delete();
    }
    final InputAmplDistributor inputAmplDistributor = InputAmplDistributorEnum.RandomInputAmplDistributor.getInputAmplDistributor(200, Collections.emptyList());
    DSpotState dspotState = new DSpotState();
    dspotState.setDelta(0.1f);
    dspotState.setTestFinder(TestFinder.get());
    dspotState.setCompiler(compiler);
    dspotState.setTestSelector(testSelector);
    dspotState.setInputAmplDistributor(inputAmplDistributor);
    dspotState.setOutput(Output.get(configuration));
    dspotState.setNbIteration(1);
    dspotState.setAutomaticBuilder(builder);
    dspotState.setTestCompiler(testCompiler);
    dspotState.setTestClassesToBeAmplified(Collections.singletonList(findClass("fr.inria.amp.TestJavaPoet")));
    dspotState.setAssertionGenerator(new AssertionGenerator(0.1f, compiler, testCompiler));
    DSpot dspot = new DSpot(dspotState);
    final CtClass<?> clone = findClass("fr.inria.amp.TestJavaPoet").clone();
    dspot.run();
    ProjectTimeJSON projectJson = getProjectJson(file);
    assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> "fr.inria.amp.TestJavaPoet".equals(classTimeJSON.fullQualifiedName)));
    assertEquals(1, projectJson.classTimes.size());
    assertEquals("sample", projectJson.projectName);
    dspotState.setTestClassesToBeAmplified(Collections.singletonList(findClass("fr.inria.mutation.ClassUnderTestTest")));
    dspot.run();
    projectJson = getProjectJson(file);
    assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.amp.TestJavaPoet")));
    assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.mutation.ClassUnderTestTest")));
    assertEquals(2, projectJson.classTimes.size());
    assertEquals("sample", projectJson.projectName);
    /* we reinitialize the factory to remove the amplified test class */
    final CtClass<?> amplifiedClassToBeRemoved = findClass("fr.inria.amp.TestJavaPoet");
    final CtPackage aPackage = amplifiedClassToBeRemoved.getPackage();
    aPackage.removeType(amplifiedClassToBeRemoved);
    aPackage.addType(clone);
    dspotState.setTestClassesToBeAmplified(Collections.singletonList(findClass("fr.inria.amp.TestJavaPoet")));
    dspot.run();
    projectJson = getProjectJson(file);
    assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.amp.TestJavaPoet")));
    assertTrue(projectJson.classTimes.stream().anyMatch(classTimeJSON -> classTimeJSON.fullQualifiedName.equals("fr.inria.mutation.ClassUnderTestTest")));
    assertEquals(2, projectJson.classTimes.size());
    assertEquals("sample", projectJson.projectName);
}
Also used : RandomHelper(eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper) AutomaticBuilderEnum(eu.stamp_project.dspot.common.configuration.options.AutomaticBuilderEnum) Launcher(spoon.Launcher) DSpotCompiler(eu.stamp_project.dspot.common.compilation.DSpotCompiler) TestFramework(eu.stamp_project.dspot.common.test_framework.TestFramework) AssertionGeneratorUtils(eu.stamp_project.dspot.assertiongenerator.assertiongenerator.AssertionGeneratorUtils) InputAmplDistributorEnum(eu.stamp_project.dspot.common.configuration.options.InputAmplDistributorEnum) CtPackage(spoon.reflect.declaration.CtPackage) GsonBuilder(com.google.gson.GsonBuilder) DSpotUtils(eu.stamp_project.dspot.common.miscellaneous.DSpotUtils) Gson(com.google.gson.Gson) AutomaticBuilder(eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder) InputAmplDistributor(eu.stamp_project.dspot.amplifier.InputAmplDistributor) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) DSpotPOMCreator(eu.stamp_project.dspot.common.automaticbuilder.maven.DSpotPOMCreator) AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) Before(org.junit.Before) ProjectTimeJSON(eu.stamp_project.dspot.common.report.output.json.ProjectTimeJSON) JacocoCoverageSelector(eu.stamp_project.dspot.selector.JacocoCoverageSelector) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) ValueCreator(eu.stamp_project.dspot.amplifier.amplifiers.value.ValueCreator) TestCompiler(eu.stamp_project.dspot.common.compilation.TestCompiler) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) Factory(spoon.reflect.factory.Factory) CommentEnum(eu.stamp_project.dspot.common.configuration.options.CommentEnum) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) TestSelector(eu.stamp_project.dspot.selector.TestSelector) java.io(java.io) Output(eu.stamp_project.dspot.common.report.output.Output) CtClass(spoon.reflect.declaration.CtClass) AmplificationHelper(eu.stamp_project.dspot.common.miscellaneous.AmplificationHelper) DSpotCache(eu.stamp_project.dspot.common.configuration.DSpotCache) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputAmplDistributor(eu.stamp_project.dspot.amplifier.InputAmplDistributor) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) ProjectTimeJSON(eu.stamp_project.dspot.common.report.output.json.ProjectTimeJSON) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) CtPackage(spoon.reflect.declaration.CtPackage) Test(org.junit.Test)

Aggregations

TestCompiler (eu.stamp_project.dspot.common.compilation.TestCompiler)7 Before (org.junit.Before)6 UserInput (eu.stamp_project.dspot.common.configuration.UserInput)5 InitializeDSpot (eu.stamp_project.dspot.common.configuration.InitializeDSpot)4 Launcher (spoon.Launcher)4 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)2 TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)2 Output (eu.stamp_project.dspot.common.report.output.Output)2 JacocoCoverageSelector (eu.stamp_project.dspot.selector.JacocoCoverageSelector)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 InputAmplDistributor (eu.stamp_project.dspot.amplifier.InputAmplDistributor)1 Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)1 RandomHelper (eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper)1 ValueCreator (eu.stamp_project.dspot.amplifier.amplifiers.value.ValueCreator)1 AssertionGeneratorUtils (eu.stamp_project.dspot.assertiongenerator.assertiongenerator.AssertionGeneratorUtils)1 AutomaticBuilder (eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder)1 DSpotPOMCreator (eu.stamp_project.dspot.common.automaticbuilder.maven.DSpotPOMCreator)1 EmailSender (eu.stamp_project.dspot.common.collector.smtp.EmailSender)1 DSpotCompiler (eu.stamp_project.dspot.common.compilation.DSpotCompiler)1