use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class StatementAddTest method testWithLoop.
@Test
public void testWithLoop() throws Exception {
/*
Test that StatementAdd amplifier is able to add statement inside a loop if this loop has not brackets
*/
final String packageName = "fr.inria.statementadd";
InputProgram inputProgram = Utils.getInputProgram();
final Factory factory = inputProgram.getFactory();
inputProgram.setFactory(factory);
AmplificationHelper.setSeedRandom(32L);
StatementAdd amplifier = new StatementAdd(packageName);
amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "testWithLoop");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
assertEquals("{" + AmplificationHelper.LINE_SEPARATOR + " java.util.ArrayList<fr.inria.statementadd.TestClassTarget.Internal> internalList = new java.util.ArrayList<>();" + AmplificationHelper.LINE_SEPARATOR + " internalList.add(new fr.inria.statementadd.TestClassTarget.Internal());" + AmplificationHelper.LINE_SEPARATOR + " for (fr.inria.statementadd.TestClassTarget.Internal i : internalList) {" + AmplificationHelper.LINE_SEPARATOR + " int __DSPOT_i_0 = -1167796541;" + AmplificationHelper.LINE_SEPARATOR + " i.compute(0);" + AmplificationHelper.LINE_SEPARATOR + " // StatementAdd: add invocation of a method" + AmplificationHelper.LINE_SEPARATOR + " i.compute(__DSPOT_i_0);" + AmplificationHelper.LINE_SEPARATOR + " }" + AmplificationHelper.LINE_SEPARATOR + "}", amplifiedMethods.get(0).getBody().toString());
}
use of fr.inria.diversify.utils.sosiefier.InputProgram 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.InputProgram 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());
}
use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class AutomaticBuilderFactoryTest method getAutomaticBuilder_whenUnknown.
@Test
public void getAutomaticBuilder_whenUnknown() throws Exception {
this.configuration = JSAPOptions.parse(getArgsWithUnknownBuilder());
InputConfiguration inputConfiguration = new InputConfiguration(configuration.pathToConfigurationFile);
inputConfiguration.getProperties().setProperty("automaticBuilderName", configuration.automaticBuilderName);
InputProgram program = InputConfiguration.initInputProgram(inputConfiguration);
inputConfiguration.setInputProgram(program);
assertFalse(inputConfiguration.getProperty("automaticBuilderName") == null);
assertFalse(inputConfiguration.getProperty("automaticBuilderName").toUpperCase().contains("MAVEN"));
assertFalse(inputConfiguration.getProperty("automaticBuilderName").toUpperCase().contains("GRADLE"));
AutomaticBuilder builder = AutomaticBuilderFactory.getAutomaticBuilder(inputConfiguration);
assertNotNull(builder);
assertTrue(builder.getClass().equals(MavenAutomaticBuilder.class));
}
use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class DSpotCompilerTest method testDSpotCompiler.
@Test
public void testDSpotCompiler() throws Exception {
final InputProgram inputProgram = getInputProgram();
final DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(inputProgram, "");
final CtClass<?> aClass = getClass(compiler.getLauncher().getFactory());
final List<CtMethod<?>> compile = TestCompiler.compile(compiler, aClass, "");
assertTrue(compile.isEmpty());
assertEquals(1, aClass.getMethods().size());
final List<CtMethod> tests = new UncompilableAmplifier().apply(aClass.getMethods().stream().findAny().get());
tests.forEach(aClass::addMethod);
assertEquals(3, aClass.getMethods().size());
final CtMethod uncompilableTest = tests.stream().filter(ctMethod -> ctMethod.getSimpleName().equals("uncompilableTest")).findFirst().get();
final List<CtMethod<?>> results = TestCompiler.compile(compiler, aClass, "");
assertEquals(1, results.size());
assertEquals("uncompilableTest", results.get(0).getSimpleName());
assertEquals(uncompilableTest, results.get(0));
// assertEquals(2, aClass.getMethods().size());
// The compile methods is now stateless: using a clone class
assertEquals(3, aClass.getMethods().size());
}
Aggregations