use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.
the class Main method run.
public static void run(Configuration configuration) throws Exception {
InputConfiguration inputConfiguration = new InputConfiguration(configuration.pathToConfigurationFile);
run(configuration, inputConfiguration);
}
use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project Ex2Amplifier by STAMP-project.
the class AbstractTest method initSpoonModel.
private Launcher initSpoonModel(String pathToConfigurationFile) {
try {
this.configuration = new InputConfiguration(pathToConfigurationFile);
final InputProgram program = InputConfiguration.initInputProgram(this.configuration);
this.configuration.setInputProgram(program);
AutomaticBuilder builder = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration);
String dependencies = builder.buildClasspath(program.getProgramDir());
return initLauncher(program.getAbsoluteSourceCodeDir(), program.getAbsoluteTestSourceCodeDir(), dependencies + AmplificationHelper.PATH_SEPARATOR + "lib/catg-dev.jar");
} catch (IOException ignored) {
// should not happen
fail();
}
// make javac happy
return null;
}
use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.
the class MainTest method testOverrideExistingResults.
@Test
public void testOverrideExistingResults() throws Exception {
/*
Test that we can append result in different runs of DSpot, or not, according to the --clean (-q) flag
Here, we run 4 time DSpot.
- 1 time with a lot of Amplifiers: result with a lof of amplified test
- then we if append result of run 2 and run 3, we obtain the same result than the 1
- the fourth is the same of the third time, but not appended to the result of the second
*/
Main.main(new String[] { "--path-to-properties", "src/test/resources/test-projects/test-projects.properties", "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "MethodAdd" + AmplificationHelper.PATH_SEPARATOR + "TestDataMutator" + AmplificationHelper.PATH_SEPARATOR + "StatementAdd", "--iteration", "1", "--randomSeed", "72", "--maven-home", DSpotUtils.buildMavenHome(new InputConfiguration("src/test/resources/test-projects/test-projects.properties")), "--test", "example.TestSuiteExample", "--cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200" });
Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setAutoImports(true);
launcher.addInputResource("target/trash/example/TestSuiteExampleAmpl.java");
launcher.buildModel();
final CtClass<?> testClass1 = launcher.getFactory().Class().get("example.TestSuiteExampleAmpl");
Main.main(new String[] { "--path-to-properties", "src/test/resources/test-projects/test-projects.properties", "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "MethodAdd" + AmplificationHelper.PATH_SEPARATOR + "TestDataMutator", "--iteration", "1", "--randomSeed", "72", "--maven-home", DSpotUtils.buildMavenHome(new InputConfiguration("src/test/resources/test-projects/test-projects.properties")), "--test", "example.TestSuiteExample", "--cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200", "--clean" });
launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setAutoImports(true);
launcher.addInputResource("target/trash/example/TestSuiteExampleAmpl.java");
launcher.buildModel();
final CtClass<?> testClass2 = launcher.getFactory().Class().get("example.TestSuiteExampleAmpl");
// Assert that we do not have result from the first run
Main.main(new String[] { "--path-to-properties", "src/test/resources/test-projects/test-projects.properties", "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "StatementAdd", "--iteration", "1", "--randomSeed", "72", "--maven-home", DSpotUtils.buildMavenHome(new InputConfiguration("src/test/resources/test-projects/test-projects.properties")), "--test", "example.TestSuiteExample", "--cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200" });
launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setAutoImports(true);
launcher.addInputResource("target/trash/example/TestSuiteExampleAmpl.java");
launcher.buildModel();
final CtClass<?> testClass3 = launcher.getFactory().Class().get("example.TestSuiteExampleAmpl");
Main.main(new String[] { "--path-to-properties", "src/test/resources/test-projects/test-projects.properties", "--test-criterion", "JacocoCoverageSelector", "--amplifiers", "StatementAdd", "--iteration", "1", "--randomSeed", "72", "--maven-home", DSpotUtils.buildMavenHome(new InputConfiguration("src/test/resources/test-projects/test-projects.properties")), "--test", "example.TestSuiteExample", "--cases", "test2", "--output-path", "target/trash", "--max-test-amplified", "200", "--clean" });
launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.getEnvironment().setAutoImports(true);
launcher.addInputResource("target/trash/example/TestSuiteExampleAmpl.java");
launcher.buildModel();
final CtClass<?> testClass4 = launcher.getFactory().Class().get("example.TestSuiteExampleAmpl");
assertEquals(5, testClass1.getMethods().size());
assertEquals(4, testClass2.getMethods().size());
assertEquals(5, testClass3.getMethods().size());
assertEquals(1, testClass4.getMethods().size());
}
use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.
the class ChangeMinimizerTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() throws Exception {
/*
ChangeMinimizer keeps only the assertions that trigger the failure on the second version
*/
final CtClass testClass = Utils.findClass("example.TestSuiteExample");
final String configurationPath = Utils.getInputConfiguration().getProperty("configPath");
final String pathToFolder = Utils.getInputConfiguration().getProperty("folderPath");
InputConfiguration inputConfiguration = new InputConfiguration(configurationPath);
InputProgram inputProgram = InputConfiguration.initInputProgram(inputConfiguration);
inputConfiguration.setInputProgram(inputProgram);
String pathToChangedVersionOfProgram = pathToFolder + DSpotUtils.shouldAddSeparator.apply(pathToFolder) + (inputConfiguration.getProperty("targetModule") != null ? inputConfiguration.getProperty("targetModule") + DSpotUtils.shouldAddSeparator.apply(pathToFolder) : "");
inputProgram.setProgramDir(pathToChangedVersionOfProgram);
Initializer.initialize(Utils.getInputConfiguration(), inputProgram);
final HashMap<CtMethod<?>, Failure> failurePerAmplifiedTest = new HashMap<>();
final CtMethod<?> test2 = Utils.findMethod(testClass, "test2");
failurePerAmplifiedTest.put(test2, new Failure(Description.EMPTY, new StringIndexOutOfBoundsException(-1)));
final ChangeMinimizer changeMinimizer = new ChangeMinimizer(testClass, inputConfiguration, inputProgram, pathToChangedVersionOfProgram, failurePerAmplifiedTest);
final CtInvocation assertion = test2.getElements(new TypeFilter<CtInvocation>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation element) {
return AmplificationChecker.isAssert(element);
}
}).get(0);
final CtInvocation clone = assertion.clone();
clone.getElements(new TypeFilter<CtLiteral>(CtLiteral.class) {
@Override
public boolean matches(CtLiteral element) {
return element.getValue() instanceof Integer && super.matches(element);
}
}).get(0).setValue(-1);
test2.getBody().insertEnd(clone);
assertEquals(3, test2.getBody().getStatements().size());
final CtMethod<?> minimize = changeMinimizer.minimize(test2);
assertEquals(2, minimize.getBody().getStatements().size());
}
use of fr.inria.diversify.utils.sosiefier.InputConfiguration in project dspot by STAMP-project.
the class TestLauncherTest method testFromSpoonNodes.
@Test
public void testFromSpoonNodes() throws Exception {
Launcher launcher = new Launcher();
launcher.getEnvironment().setSourceClasspath(System.getProperty("java.class.path").split(System.getProperty("path.separator")));
launcher.addInputResource("src/test/resources/src/");
launcher.addInputResource("src/test/resources/test/");
launcher.buildModel();
final String classpath = "src/test/resources/MockitoDemo-1.0-SNAPSHOT.jar" + System.getProperty("path.separator") + "src/test/resources/MockitoDemo-1.0-SNAPSHOT-tests.jar" + System.getProperty("path.separator") + "src/test/resources/example-0.0.1-SNAPSHOT.jar" + System.getProperty("path.separator") + "src/test/resources/example-0.0.1-SNAPSHOT-tests.jar";
/*
Test that we the same entry point we are able to run all kind of test
*/
InputConfiguration configuration = new InputConfiguration("src/test/resources/mockito/mockito.properties");
configuration.setInputProgram(new InputProgram());
// Mocked
TestListener results = TestLauncher.runFromSpoonNodes(configuration, classpath, launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest"), launcher.getFactory().Class().get("info.sanaulla.dal.BookDALTest").getMethodsByName("testGetBook"));
assertEquals(1, results.getRunningTests().size());
assertEquals(0, results.getFailingTests().size());
assertEquals(1, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
configuration.setInputProgram(new InputProgram());
// Default
results = TestLauncher.runFromSpoonNodes(configuration, classpath, launcher.getFactory().Class().get("example.TestSuiteExample"), launcher.getFactory().Class().get("example.TestSuiteExample").getMethodsByName("test1"));
assertEquals(1, results.getRunningTests().size());
assertEquals(1, results.getFailingTests().size());
assertEquals(0, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
configuration = new InputConfiguration("src/test/resources/sample/sample.properties");
configuration.setInputProgram(new InputProgram());
// will use example.InheriteTest to run the test of AbstractTest
results = TestLauncher.runFromSpoonNodes(configuration, classpath, launcher.getFactory().Class().get("example.AbstractTest"), launcher.getFactory().Class().get("example.AbstractTest").getMethodsByName("abstractTest"));
assertEquals(1, results.getRunningTests().size());
assertEquals(0, results.getFailingTests().size());
assertEquals(1, results.getPassingTests().size());
assertEquals(0, results.getAssumptionFailingTests().size());
assertEquals(0, results.getIgnoredTests().size());
}
Aggregations