use of spoon.Launcher in project Ex2Amplifier by STAMP-project.
the class AbstractTest method initLauncher.
private Launcher initLauncher(String pathToSources, String pathToTestSources, String dependencies) {
Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
launcher.getEnvironment().setNoClasspath(false);
launcher.getEnvironment().setCommentEnabled(true);
String[] sourcesArray = (pathToSources + AmplificationHelper.PATH_SEPARATOR + pathToTestSources).split(AmplificationHelper.PATH_SEPARATOR);
Arrays.stream(sourcesArray).forEach(launcher::addInputResource);
if (!dependencies.isEmpty()) {
String[] dependenciesArray = dependencies.split(AmplificationHelper.PATH_SEPARATOR);
launcher.getModelBuilder().setSourceClasspath(dependenciesArray);
}
launcher.buildModel();
return launcher;
}
use of spoon.Launcher in project Ex2Amplifier by STAMP-project.
the class ArgumentsExtractorTest method testOnTavern.
@Test
public void testOnTavern() throws Exception {
/*
Test the ArgumentsExtractor on the tavern project
*/
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
launcher.getEnvironment().setNoClasspath(false);
launcher.addInputResource("src/test/resources/tavern/src/test/java/fr/inria/stamp/MainTest.java");
launcher.addInputResource("src/test/resources/tavern/src/main/java/fr/inria/stamp/tavern/Seller.java");
launcher.addInputResource("src/test/resources/tavern/src/main/java/fr/inria/stamp/tavern/Player.java");
launcher.addInputResource("src/test/resources/tavern/src/main/java/fr/inria/stamp/tavern/Item.java");
launcher.buildModel();
final CtClass<Object> testClass = launcher.getFactory().Class().get("fr.inria.stamp.MainTest");
final CtMethod<?> test = testClass.getMethodsByName("test").get(0);
final CtMethod<?> extractedMethod = ArgumentsExtractor.performExtraction(test);
System.out.println(extractedMethod);
// same as the MainGenerator, the resulting method from ArgumentsExtractor should be compilable
testClass.addMethod(extractedMethod);
launcher.getModelBuilder().setBinaryOutputDirectory(new File("target/trash/"));
launcher.getModelBuilder().compile(SpoonModelBuilder.InputType.CTTYPES);
assertEquals(expectMethodTavern, extractedMethod.toString());
assertNotEquals(test.toString(), extractedMethod.toString());
}
use of spoon.Launcher in project spoon by INRIA.
the class ArraysTest method testCtNewArrayInnerCtNewArray.
@Test
public void testCtNewArrayInnerCtNewArray() throws Exception {
final Launcher launcher = new Launcher();
launcher.addInputResource("src/test/java/spoon/test/arrays/testclasses/Foo.java");
launcher.setSourceOutputDirectory("target/foo");
launcher.buildModel();
launcher.prettyprint();
try {
launcher.getModelBuilder().compile();
} catch (Exception e) {
fail(e.getMessage());
}
}
use of spoon.Launcher in project spoon by INRIA.
the class CommentTest method testCommentsInResourcesWithWindowsEOL.
@Test
public void testCommentsInResourcesWithWindowsEOL() throws IOException {
// contract: the WindowsEOL.java contains MS Windows \r\n as EOL
try (InputStream is = new FileInputStream(new File("./src/test/java/spoon/test/comment/testclasses/WindowsEOL.java"))) {
int b;
boolean lastWasCR = false;
while ((b = is.read()) != -1) {
if (lastWasCR) {
// next must be LF
assertTrue(b == '\n');
lastWasCR = false;
}
if (b == '\r') {
lastWasCR = true;
}
}
}
final Launcher launcher = new Launcher();
launcher.run(new String[] { "-i", "./src/test/java/spoon/test/comment/testclasses/WindowsEOL.java", "-o", "./target/spooned/", "-c" });
Factory f = launcher.getFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(WindowsEOL.class);
CtJavaDoc classJavaDoc = (CtJavaDoc) type.getComments().get(0);
// contract: test that java doc is printed correctly
String str = classJavaDoc.toString();
StringTokenizer st = new StringTokenizer(str, System.getProperty("line.separator"));
boolean first = true;
while (st.hasMoreTokens()) {
String line = st.nextToken();
if (first) {
// first
first = false;
assertTrue(line.length() == 3);
assertEquals("/**", line);
} else {
if (st.hasMoreTokens()) {
// in the middle
assertTrue(line.length() >= 2);
assertEquals(" *", line.substring(0, 2));
} else {
// last
assertTrue(line.length() == 3);
assertEquals(" */", line.substring(0, 3));
}
}
}
// This test passes on MS Windows too - why spoon uses `\n` on MS Windows too?
assertEquals("This file contains MS Windows EOL.\n" + "It is here to test whether comments are printed well\n" + "in this case", classJavaDoc.getContent());
}
use of spoon.Launcher in project spoon by INRIA.
the class CtTypeTest method testHasMethodInDefaultMethod.
@Test
public void testHasMethodInDefaultMethod() throws Exception {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/ctType/testclasses/X.java");
launcher.getEnvironment().setComplianceLevel(8);
launcher.run();
final CtClass<?> x = launcher.getFactory().Class().get("spoon.test.ctType.testclasses.W");
final CtInterface<?> z = launcher.getFactory().Interface().get("spoon.test.ctType.testclasses.Z");
final CtMethod<?> superMethod = z.getMethods().iterator().next();
assertTrue(x.hasMethod(superMethod));
}
Aggregations