Search in sources :

Example 16 with UserInput

use of eu.stamp_project.dspot.common.configuration.UserInput in project dspot by STAMP-project.

the class OneTestClassPitScoreMutantSelectorTest method setUp.

@Before
public void setUp() {
    DSpotState.verbose = true;
    this.configuration = new UserInput();
    this.configuration.setAbsolutePathToProjectRoot("src/test/resources/test-projects/");
    this.builder = AutomaticBuilderEnum.Maven.getAutomaticBuilder(configuration);
    this.initializeDSpot = new InitializeDSpot();
    DSpotCompiler.createDSpotCompiler(configuration, initializeDSpot.completeDependencies(configuration, this.builder));
    Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource("src/test/resources/test-projects/");
    launcher.buildModel();
    Factory factory = launcher.getFactory();
    this.configuration.setFactory(factory);
    this.configuration.setTestClasses(Collections.singletonList(FULL_QUALIFIED_NAME_TEST_CLASS));
    this.configuration.setTargetOneTestClass(true);
    this.testRunner = new TestRunner(this.configuration.getAbsolutePathToProjectRoot(), "", false);
}
Also used : TestRunner(eu.stamp_project.dspot.common.execution.TestRunner) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) Before(org.junit.Before)

Example 17 with UserInput

use of eu.stamp_project.dspot.common.configuration.UserInput 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 18 with UserInput

use of eu.stamp_project.dspot.common.configuration.UserInput in project dspot by STAMP-project.

the class MavenAutomaticBuilder method buildMavenHome.

private String buildMavenHome(UserInput configuration) {
    String mavenHome = null;
    if (configuration != null) {
        if (configuration.getMavenHome() != null && !configuration.getMavenHome().isEmpty()) {
            mavenHome = configuration.getMavenHome();
        } else {
            mavenHome = getMavenHome(envVariable -> System.getenv().get(envVariable) != null, envVariable -> System.getenv().get(envVariable), "MAVEN_HOME", "M2_HOME");
            if (mavenHome == null) {
                mavenHome = getMavenHome(path -> new File(path).exists(), Function.identity(), "/usr/share/maven/", "/usr/local/maven-3.3.9/", "/usr/share/maven3/", "/usr/share/apache-maven-3.8.1/");
                if (mavenHome == null) {
                    throw new RuntimeException("Maven home not found, please set properly MAVEN_HOME or M2_HOME.");
                }
            }
            // update the value inside the input configuration
            configuration.setMavenHome(mavenHome);
        }
    }
    return mavenHome;
}
Also used : DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Properties(java.util.Properties) Predicate(java.util.function.Predicate) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) LoggerFactory(org.slf4j.LoggerFactory) FileUtils(org.apache.commons.io.FileUtils) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) File(java.io.File) DSpotUtils(eu.stamp_project.dspot.common.miscellaneous.DSpotUtils) Invoker(org.apache.maven.shared.invoker.Invoker) CtType(spoon.reflect.declaration.CtType) AutomaticBuilder(eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder) NullInputStream(org.apache.commons.io.input.NullInputStream) DefaultInvoker(org.apache.maven.shared.invoker.DefaultInvoker) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) UserInput(eu.stamp_project.dspot.common.configuration.UserInput) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Collections(java.util.Collections) File(java.io.File)

Example 19 with UserInput

use of eu.stamp_project.dspot.common.configuration.UserInput in project dspot by STAMP-project.

the class AbstractTest method setUp.

@Before
public void setUp() throws Exception {
    RandomHelper.setSeedRandom(72L);
    ValueCreator.count = 0;
    this.configuration = new UserInput();
    this.configuration.setAbsolutePathToProjectRoot(this.getAbsolutePathToProjectRoot());
    this.configuration.setVerbose(true);
    this.configuration.setBuilderEnum(AutomaticBuilderEnum.Maven);
    this.configuration.setGregorMode(true);
    DSpotState.verbose = true;
    Utils.init(this.configuration);
}
Also used : UserInput(eu.stamp_project.dspot.common.configuration.UserInput) Before(org.junit.Before)

Example 20 with UserInput

use of eu.stamp_project.dspot.common.configuration.UserInput in project dspot by STAMP-project.

the class TestMethodCallAdder method setUp.

@Before
@Override
public void setUp() {
    super.setUp();
    UserInput configuration = new UserInput();
    configuration.setAbsolutePathToProjectRoot(new File("src/test/resources/sample/").getAbsolutePath());
    DSpotUtils.init(CommentEnum.Amplifier, "target/dspot/", configuration.getFullClassPathWithExtraDependencies(), "src/test/resources/sample/");
}
Also used : UserInput(eu.stamp_project.dspot.common.configuration.UserInput) File(java.io.File) Before(org.junit.Before)

Aggregations

UserInput (eu.stamp_project.dspot.common.configuration.UserInput)26 Before (org.junit.Before)11 Test (org.junit.Test)10 InitializeDSpot (eu.stamp_project.dspot.common.configuration.InitializeDSpot)8 Launcher (spoon.Launcher)8 File (java.io.File)7 AutomaticBuilder (eu.stamp_project.dspot.common.automaticbuilder.AutomaticBuilder)5 TestCompiler (eu.stamp_project.dspot.common.compilation.TestCompiler)4 PitXMLResultParser (eu.stamp_project.dspot.selector.pitmutantscoreselector.PitXMLResultParser)3 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 TestRunner (eu.stamp_project.dspot.common.execution.TestRunner)2 ArrayList (java.util.ArrayList)2 CtMethod (spoon.reflect.declaration.CtMethod)2 DSpot (eu.stamp_project.dspot.DSpot)1 DSpotState (eu.stamp_project.dspot.common.configuration.DSpotState)1 InputErrorException (eu.stamp_project.dspot.common.configuration.check.InputErrorException)1 DSpotUtils (eu.stamp_project.dspot.common.miscellaneous.DSpotUtils)1 JacocoCoverageSelector (eu.stamp_project.dspot.selector.JacocoCoverageSelector)1 IOException (java.io.IOException)1