Search in sources :

Example 1 with DSpotCompiler

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

the class Main method run.

public static List<CtMethod<?>> run(CtType<?> amplifiedTestClass, UserInput configuration) {
    InitializeDSpot initializeDSpot = new InitializeDSpot();
    final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
    final String dependencies = initializeDSpot.completeDependencies(configuration, automaticBuilder);
    final DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
    configuration.setFactory(compiler.getLauncher().getFactory());
    initializeDSpot.initHelpers(configuration);
    final List<CtMethod<?>> testMethods = TestFramework.getAllTest(amplifiedTestClass);
    Main.report.nbTestMethods = testMethods.size();
    final List<CtMethod<?>> minimizedAmplifiedTestMethods;
    // 1 minimize amplified test methods
    if (configuration.isApplyAllPrettifiers() || configuration.isApplyGeneralMinimizer() || configuration.isApplyPitMinimizer()) {
        minimizedAmplifiedTestMethods = applyMinimization(testMethods, amplifiedTestClass, configuration);
    } else {
        minimizedAmplifiedTestMethods = testMethods;
    }
    // 2 rename test methods
    if (configuration.isApplyAllPrettifiers() || configuration.isRenameTestMethods()) {
        applyCode2Vec(minimizedAmplifiedTestMethods, configuration);
    }
    // 3 rename local variables TODO train one better model
    final List<CtMethod<?>> prettifiedTestMethods;
    if (configuration.isApplyAllPrettifiers() || configuration.isRenameLocalVariables()) {
        prettifiedTestMethods = applyContext2Name(minimizedAmplifiedTestMethods);
    } else {
        prettifiedTestMethods = minimizedAmplifiedTestMethods;
    }
    return prettifiedTestMethods;
}
Also used : AutomaticBuilder(eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder) DSpotCompiler(eu.stamp_project.dspot.common.compilation.DSpotCompiler) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) CtMethod(spoon.reflect.declaration.CtMethod)

Example 2 with DSpotCompiler

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

the class Utils method init.

public static void init(UserInput configuration) {
    InitializeDSpot initializeDSpot = new InitializeDSpot();
    final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
    final String dependencies = initializeDSpot.completeDependencies(configuration, automaticBuilder);
    final DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
    configuration.setFactory(compiler.getLauncher().getFactory());
    initializeDSpot.initHelpers(configuration);
    Utils.configuration = configuration;
}
Also used : AutomaticBuilder(eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder) DSpotCompiler(eu.stamp_project.dspot.common.compilation.DSpotCompiler) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot)

Example 3 with DSpotCompiler

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

the class RecoveryDSpotTest method testThatDSpotCanRecoverFromError.

@Test
public void testThatDSpotCanRecoverFromError() throws Exception {
    /*
            We test here, with different mock, that DSpot can recover for errors, continue and terminate the amplification process.
         */
    final SelectorThatThrowsError selector = new SelectorThatThrowsError(builder, configuration);
    selector.setThrowsToAmplify(true);
    DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, "");
    final TestFinder testFinder = new TestFinder(Collections.emptyList(), Collections.emptyList());
    final CtClass<?> testClassToBeAmplified = findClass("fr.inria.amp.OneLiteralTest");
    final List<CtMethod<?>> testListToBeAmplified = testFinder.findTestMethods(testClassToBeAmplified, Collections.emptyList());
    DSpotState dspotState = new DSpotState();
    dspotState.setDelta(0.1f);
    dspotState.setCompiler(compiler);
    dspotState.setTestSelector(selector);
    dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, Collections.emptyList()));
    dspotState.setNbIteration(1);
    dspotState.setTestCompiler(testCompiler);
    dspotState.setAssertionGenerator(new AssertionGenerator(0.1f, compiler, testCompiler));
    DSpot dspot = new DSpot(dspotState);
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(2, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_PRE_SELECTION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
    selector.setThrowsToAmplify(false);
    selector.setThrowsToKeep(true);
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(2, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_SELECTION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
    final List<Amplifier> amplifiers = Collections.singletonList(new AmplifierThatThrowsError());
    dspotState.setTestSelector(new TakeAllSelector(this.builder, this.configuration));
    dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, amplifiers));
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(1, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_INPUT_AMPLIFICATION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
    dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, Collections.emptyList()));
    dspotState.setAssertionGenerator(new AssertionGeneratorThatThrowsError(compiler));
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(1, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_ASSERT_AMPLIFICATION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
}
Also used : AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) DSpotCompiler(eu.stamp_project.dspot.common.compilation.DSpotCompiler) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) TextualDistanceInputAmplDistributor(eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) TakeAllSelector(eu.stamp_project.dspot.selector.TakeAllSelector) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

DSpotCompiler (eu.stamp_project.dspot.common.compilation.DSpotCompiler)3 AutomaticBuilder (eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder)2 InitializeDSpot (eu.stamp_project.dspot.common.configuration.InitializeDSpot)2 CtMethod (spoon.reflect.declaration.CtMethod)2 TextualDistanceInputAmplDistributor (eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor)1 Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)1 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)1 DSpotState (eu.stamp_project.dspot.common.configuration.DSpotState)1 TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)1 TakeAllSelector (eu.stamp_project.dspot.selector.TakeAllSelector)1 Test (org.junit.Test)1