Skip to content

Commit

Permalink
Fix issue INRIA#1246.
Browse files Browse the repository at this point in the history
  • Loading branch information
surli committed Apr 3, 2017
1 parent d6fbc97 commit 04e91a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean compile(InputType... types) {
.complianceOptions(new ComplianceOptions().compliance(javaCompliance)) //
.annotationProcessingOptions(new AnnotationProcessingOptions().compileProcessors()) //
.advancedOptions(new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()) //
.sources(new SourceOptions().sources()) // no sources, handled by the JDTBatchCompiler
.sources(new SourceOptions().sources(sources.getAllJavaFiles())) // no sources, handled by the JDTBatchCompiler
.build();

getFactory().getEnvironment().debugMessage("compile args: " + Arrays.toString(args));
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/spoon/test/compilation/CompilationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -376,4 +380,25 @@ public <T> void visitCtTypeReference(CtTypeReference<T> reference) {
assertEquals(3, l.size());
assertTrue(l.contains("KJHKY"));
}

@Test
public void testCompilationInEmptyDir() throws Exception {
// Contract: Spoon can be launched in an empty folder as a working directory
// See: https://github.com/INRIA/spoon/pull/1208 and https://github.com/INRIA/spoon/issues/1246
// This test does not fail (it's not enough to change user.dir we should launch process inside that dir) but it explains the problem
String userDir = System.getProperty("user.dir");
File testFile = new File("src/test/resources/compilation/compilation-tests/IBar.java");
String absoluteTestPath = testFile.getAbsolutePath();

Path tempDirPath = Files.createTempDirectory("test_compilation");

System.setProperty("user.dir", tempDirPath.toFile().getAbsolutePath());
SpoonModelBuilder compiler = new Launcher().createCompiler();
compiler.addInputSource(new File(absoluteTestPath));
compiler.setBinaryOutputDirectory(tempDirPath.toFile());
compiler.compile(SpoonModelBuilder.InputType.FILES);
System.setProperty("user.dir", userDir);

assertThat(tempDirPath.toFile().listFiles().length, not(0));
}
}

0 comments on commit 04e91a2

Please sign in to comment.