use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class MemoryClassLoaderFactory method createMemoryClassLoader.
/*
Here: the factory has the same behavior than @see fr.inria.stamp.test.runner.TestRunnerFactory
We will use the parent of the system classloader in special case
*/
public static MemoryClassLoader createMemoryClassLoader(CtType<?> testClass, InputConfiguration configuration) {
final InputProgram program = configuration.getInputProgram();
final String classesDirectory = program.getProgramDir() + "/" + program.getClassesDir();
final String testClassesDirectory = program.getProgramDir() + "/" + program.getTestClassesDir();
String classpath = AutomaticBuilderFactory.getAutomaticBuilder(configuration).buildClasspath(program.getProgramDir()) + PATH_SEPARATOR + "target/dspot/dependencies/";
ClassLoader classLoader = null;
if (testClass != null && TestRunnerFactory.containsSpecificAnnotation.test(testClass)) {
classLoader = new URLClassLoader(Arrays.stream(classpath.split(":")).map(File::new).map(File::toURI).map(uri -> {
try {
return uri.toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}).toArray(URL[]::new), ClassLoader.getSystemClassLoader().getParent());
} else {
classLoader = new URLClassLoader(Arrays.stream(classpath.split(":")).map(File::new).map(File::toURI).map(uri -> {
try {
return uri.toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}).toArray(URL[]::new), ClassLoader.getSystemClassLoader());
}
final URL[] urls;
try {
urls = new URL[] { new File(classesDirectory).toURI().toURL(), new File(testClassesDirectory).toURI().toURL() };
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
if (configuration.getProperty("additionalClasspathElements") != null) {
return new MemoryClassLoader(Stream.concat(Arrays.stream(configuration.getProperty("additionalClasspathElements").split(PATH_SEPARATOR)).map(configuration.getInputProgram().getProgramDir()::concat).map(File::new).map(File::toURI).map(uri -> {
try {
return uri.toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}), Arrays.stream(urls)).toArray(URL[]::new), classLoader);
} else {
return new MemoryClassLoader(urls, classLoader);
}
}
use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class DSpotUtils method copyResources.
public static void copyResources(InputConfiguration configuration) {
final InputProgram program = configuration.getInputProgram();
String resource = configuration.getProperty("srcResources");
if (resource == null || resource.isEmpty()) {
resource = "src/main/resources/";
} else if (!resource.contains("src/main/resources/")) {
resource += PATH_SEPARATOR + "src/main/resources/";
}
copyGivenResources(resource, program.getClassesDir(), configuration);
resource = configuration.getProperty("testResources");
if (resource == null || resource.isEmpty()) {
resource = "src/test/resources/";
} else if (!resource.contains("src/test/resources/")) {
resource += PATH_SEPARATOR + "src/test/resources/";
}
copyGivenResources(resource, program.getClassesDir(), configuration);
}
use of fr.inria.diversify.utils.sosiefier.InputProgram in project dspot by STAMP-project.
the class AutomaticBuilderFactoryTest method getAutomaticBuilder_whenConfDoesntContainBuilder.
@Test
public void getAutomaticBuilder_whenConfDoesntContainBuilder() throws Exception {
this.configuration = JSAPOptions.parse(getArgsWithNoBuilder());
InputConfiguration inputConfiguration = new InputConfiguration(configuration.pathToConfigurationFile);
InputProgram program = InputConfiguration.initInputProgram(inputConfiguration);
inputConfiguration.setInputProgram(program);
assertTrue(inputConfiguration.getProperty("automaticBuilderName") == null);
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 AutomaticBuilderFactoryTest method getAutomaticBuilder_whenMaven.
@Test
public void getAutomaticBuilder_whenMaven() throws Exception {
this.configuration = JSAPOptions.parse(getArgsWithMavenBuilder());
InputConfiguration inputConfiguration = new InputConfiguration(configuration.pathToConfigurationFile);
InputProgram program = InputConfiguration.initInputProgram(inputConfiguration);
inputConfiguration.setInputProgram(program);
inputConfiguration.getProperties().setProperty("automaticBuilderName", configuration.automaticBuilderName);
assertTrue(inputConfiguration.getProperty("automaticBuilderName").toUpperCase().contains("MAVEN"));
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 AssertGeneratorHelperTest method testNoInstrumentationOnGeneratedObject.
/**
* this test aims at verifying that dspot does not generate assertion for generated object.
* To do this, it will check that the instrumentation does not add observation points on those objects.
* If no observation point is added, any assertion would be generated.
*/
@Test
public void testNoInstrumentationOnGeneratedObject() throws Exception {
final String packageName = "fr.inria.statementaddarray";
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 + ".ClassTargetAmplify"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
final List<CtMethod<?>> instrumentedAmplifiedTests = amplifiedMethods.stream().map(method -> AssertGeneratorHelper.createTestWithLog(method, "fr.inria.statementaddarray")).collect(Collectors.toList());
assertEquals(5, amplifiedMethods.size());
final String expectedInstrumentedBodyAfterAmplification_test_sd6_withlog = "{" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.statementaddarray.ClassTargetAmplify clazz = new fr.inria.statementaddarray.ClassTargetAmplify();" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.diversify.compare.ObjectLog.log(clazz, \"clazz\", \"test_sd6__1\");" + AmplificationHelper.LINE_SEPARATOR + " // StatementAdd: generate variable from return value" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.statementaddarray.ClassParameterAmplify __DSPOT_invoc_3 = clazz.methodWithReturn();" + AmplificationHelper.LINE_SEPARATOR + " // StatementAdd: add invocation of a method" + AmplificationHelper.LINE_SEPARATOR + " __DSPOT_invoc_3.method1();" + AmplificationHelper.LINE_SEPARATOR + " fr.inria.diversify.compare.ObjectLog.log(clazz, \"clazz\", \"test_sd6__1___end\");" + AmplificationHelper.LINE_SEPARATOR + "}";
assertEquals(expectedInstrumentedBodyAfterAmplification_test_sd6_withlog, instrumentedAmplifiedTests.stream().filter(ctMethod1 -> "test_sd6_withlog".equals(ctMethod1.getSimpleName())).findFirst().get().getBody().toString());
}
Aggregations