Search in sources :

Example 1 with AutomaticBuilder

use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.

the class Main method applyMinimization.

public static List<CtMethod<?>> applyMinimization(List<CtMethod<?>> amplifiedTestMethodsToBeMinimized, CtType<?> amplifiedTestClass, UserInput configuration) {
    Main.report.medianNbStatementBefore = Main.getMedian(amplifiedTestMethodsToBeMinimized.stream().map(ctMethod -> ctMethod.getElements(new TypeFilter<>(CtStatement.class))).map(List::size).collect(Collectors.toList()));
    // 1 apply general minimization
    if (configuration.isApplyAllPrettifiers() || configuration.isApplyGeneralMinimizer()) {
        amplifiedTestMethodsToBeMinimized = Main.applyGivenMinimizer(new GeneralMinimizer(), amplifiedTestMethodsToBeMinimized);
        // update the test class with minimized test methods
        final ArrayList<CtMethod<?>> allMethods = new ArrayList<>(amplifiedTestClass.getMethods());
        allMethods.stream().filter(TestFramework.get()::isTest).forEach(amplifiedTestClass::removeMethod);
        amplifiedTestMethodsToBeMinimized.forEach(amplifiedTestClass::addMethod);
    }
    // 2 apply pit minimization
    if (configuration.isApplyAllPrettifiers() || configuration.isApplyPitMinimizer()) {
        final AutomaticBuilder automaticBuilder = configuration.getBuilderEnum().getAutomaticBuilder(configuration);
        amplifiedTestMethodsToBeMinimized = Main.applyGivenMinimizer(new PitMutantMinimizer(amplifiedTestClass, automaticBuilder, configuration.getAbsolutePathToProjectRoot(), configuration.getClasspathClassesProject(), configuration.getAbsolutePathToTestClasses()), amplifiedTestMethodsToBeMinimized);
    }
    Main.report.medianNbStatementAfter = Main.getMedian(amplifiedTestMethodsToBeMinimized.stream().map(ctMethod -> ctMethod.getElements(new TypeFilter<>(CtStatement.class))).map(List::size).collect(Collectors.toList()));
    return amplifiedTestMethodsToBeMinimized;
}
Also used : PitMutantMinimizer(eu.stamp_project.prettifier.minimization.PitMutantMinimizer) GeneralMinimizer(eu.stamp_project.prettifier.minimization.GeneralMinimizer) AutomaticBuilder(eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtMethod(spoon.reflect.declaration.CtMethod)

Example 2 with AutomaticBuilder

use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.

the class MavenAutomaticBuilderTest method testGetDependenciesOf.

@Test
public void testGetDependenciesOf() throws Exception {
    UserInput configuration = new UserInput();
    configuration.setAbsolutePathToProjectRoot(new File("src/test/resources/test-projects/").getAbsolutePath());
    AutomaticBuilder builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
    final String dependenciesOf = builder.buildClasspath();
    assertTrue(dependenciesOf.contains("org" + System.getProperty("file.separator") + "hamcrest" + System.getProperty("file.separator") + "hamcrest-core" + System.getProperty("file.separator") + "1.3" + System.getProperty("file.separator") + "hamcrest-core-1.3.jar"));
    assertTrue(dependenciesOf.contains("junit" + System.getProperty("file.separator") + "junit" + System.getProperty("file.separator") + "4.11" + System.getProperty("file.separator") + "junit-4.11.jar"));
}
Also used : AutomaticBuilder(eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) File(java.io.File) Test(org.junit.Test)

Example 3 with AutomaticBuilder

use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder 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 4 with AutomaticBuilder

use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder in project dspot by STAMP-project.

the class TestCompilerTest method test.

@Test
public void test() {
    final UserInput configuration = new UserInput();
    configuration.setAbsolutePathToProjectRoot(getPathToProjectRoot());
    final AutomaticBuilder builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
    InitializeDSpot initializeDSpot = new InitializeDSpot();
    String dependencies = initializeDSpot.completeDependencies(configuration, builder);
    configuration.setDependencies(dependencies);
    DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, dependencies);
    CtClass<?> testClass = findClass("fr.inria.filter.failing.FailingTest");
    final ArrayList<CtMethod<?>> methods = new ArrayList<>();
    methods.add(findMethod(testClass, "testAssertionError"));
    methods.add(findMethod(testClass, "testFailingWithException"));
    DSpotUtils.init(CommentEnum.None, "target/dspot/", configuration.getFullClassPathWithExtraDependencies(), getPathToProjectRoot());
    TestCompiler testCompiler = new TestCompiler(0, false, getPathToProjectRoot(), configuration.getClasspathClassesProject(), 10000, "", false);
    assertTrue(testCompiler.compileRunAndDiscardUncompilableAndFailingTestMethods(testClass, methods, compiler).isEmpty());
    testClass = findClass("fr.inria.filter.passing.PassingTest");
    methods.clear();
    methods.add(findMethod(testClass, "testAssertion"));
    methods.add(findMethod(testClass, "testNPEExpected"));
    methods.add(findMethod(testClass, "failingTestCase"));
    assertEquals(2, testCompiler.compileRunAndDiscardUncompilableAndFailingTestMethods(testClass, methods, compiler).size());
}
Also used : AutomaticBuilder(eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder) ArrayList(java.util.ArrayList) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 5 with AutomaticBuilder

use of eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder 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)

Aggregations

AutomaticBuilder (eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder)7 InitializeDSpot (eu.stamp_project.dspot.common.configuration.InitializeDSpot)5 UserInput (eu.stamp_project.dspot.common.configuration.UserInput)4 File (java.io.File)3 Test (org.junit.Test)3 CtMethod (spoon.reflect.declaration.CtMethod)3 DSpotCompiler (eu.stamp_project.dspot.common.compilation.DSpotCompiler)2 GeneralMinimizer (eu.stamp_project.prettifier.minimization.GeneralMinimizer)1 PitMutantMinimizer (eu.stamp_project.prettifier.minimization.PitMutantMinimizer)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 Launcher (spoon.Launcher)1 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)1