use of org.eclipse.ceylon.compiler.java.launcher.Main.ExitState in project ceylon by eclipse.
the class CompilerTests method compareWithJavaSourceWithLines.
protected void compareWithJavaSourceWithLines(String name) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
CeyloncTaskImpl task = getCompilerTask(new String[] { name + ".ceylon" });
// grab the CU after we've completed it
class Listener implements TaskListener {
JCCompilationUnit compilationUnit;
private String compilerSrc;
private JavaPositionsRetriever javaPositionsRetriever = new JavaPositionsRetriever();
@Override
public void started(TaskEvent e) {
}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == Kind.ENTER) {
if (compilationUnit == null) {
compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
// for some reason compilationUnit is full here in the listener, but empty as soon
// as the compile task is done. probably to clean up for the gc?
javaPositionsRetriever.retrieve(compilationUnit);
compilerSrc = normalizeLineEndings(javaPositionsRetriever.getJavaSourceCodeWithCeylonLines());
AbstractTransformer.trackNodePositions(null);
}
}
}
}
Listener listener = new Listener();
task.setTaskListener(listener);
// now compile it all the way
ExitState exitState = task.call2();
Assert.assertEquals("Compilation failed", exitState.ceylonState, CeylonState.OK);
// now look at what we expected
String expectedSrc = normalizeLineEndings(readFile(new File(getPackagePath(), name + ".src"))).trim();
String compiledSrc = listener.compilerSrc.trim();
Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
use of org.eclipse.ceylon.compiler.java.launcher.Main.ExitState in project ceylon by eclipse.
the class CompilerTests method compareWithJavaSourceWithPositions.
protected void compareWithJavaSourceWithPositions(String name) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
CeyloncTaskImpl task = getCompilerTask(new String[] { name + ".ceylon" });
// grab the CU after we've completed it
class Listener implements TaskListener {
JCCompilationUnit compilationUnit;
private String compilerSrc;
private JavaPositionsRetriever javaPositionsRetriever = new JavaPositionsRetriever();
@Override
public void started(TaskEvent e) {
AbstractTransformer.trackNodePositions(javaPositionsRetriever);
}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == Kind.ENTER) {
if (compilationUnit == null) {
compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
// for some reason compilationUnit is full here in the listener, but empty as soon
// as the compile task is done. probably to clean up for the gc?
javaPositionsRetriever.retrieve(compilationUnit);
compilerSrc = normalizeLineEndings(javaPositionsRetriever.getJavaSourceCodeWithCeylonPositions());
AbstractTransformer.trackNodePositions(null);
}
}
}
}
Listener listener = new Listener();
task.setTaskListener(listener);
// now compile it all the way
ExitState exitState = task.call2();
Assert.assertEquals("Compilation failed", CeylonState.OK, exitState.ceylonState);
// now look at what we expected
String expectedSrc = normalizeLineEndings(readFile(new File(getPackagePath(), name + ".src"))).trim();
String compiledSrc = listener.compilerSrc.trim();
Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
use of org.eclipse.ceylon.compiler.java.launcher.Main.ExitState in project ceylon by eclipse.
the class CompilerTests method compileErrorTest.
protected ErrorCollector compileErrorTest(String[] ceylonFiles, List<String> options, Throwable expectedException, boolean includeWarnings, boolean expectedToFail) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
ErrorCollector collector = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(options, collector, ceylonFiles);
// now compile it all the way
Throwable ex = null;
ExitState exitState = task.call2();
switch(exitState.ceylonState) {
case OK:
if (expectedToFail) {
Assert.fail("Compilation successful (it should have failed!)");
}
break;
case BUG:
if (expectedException == null) {
throw new AssertionError("Compiler bug", exitState.abortingException);
}
ex = exitState.abortingException;
break;
case ERROR:
if (!expectedToFail) {
Assert.fail("Compilation failed (it should have been successful!)");
}
break;
case SYS:
Assert.fail("System error");
break;
default:
Assert.fail("Unknown exit state");
}
if (ex != null) {
if (expectedException == null) {
throw new AssertionError("Compilation terminated with unexpected error", ex);
} else if (expectedException.getClass() != ex.getClass() || !eq(expectedException.getMessage(), ex.getMessage())) {
throw new AssertionError("Compilation terminated with a different error than the expected " + expectedException, ex);
}
} else if (expectedException != null) {
Assert.fail("Expected compiler exception " + expectedException);
}
return collector;
}
use of org.eclipse.ceylon.compiler.java.launcher.Main.ExitState in project ceylon by eclipse.
the class CompilerTests method compileIgnoringErrors.
protected void compileIgnoringErrors(ExpectedError expectedErrors, String... ceylon) {
ErrorCollector c = new ErrorCollector();
ExitState exitState = getCompilerTask(c, ceylon).call2();
assert (exitState.javacExitCode.exitCode == Main.EXIT_ERROR);
assert (exitState.ceylonState == CeylonState.ERROR);
TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
compareErrors(actualErrors, expectedErrors);
}
use of org.eclipse.ceylon.compiler.java.launcher.Main.ExitState in project ceylon by eclipse.
the class IssuesTests_1500_1999 method testBug1830.
@Test
public void testBug1830() {
ErrorCollector collector = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(defaultOptions, collector, "bug18xx/Bug1830.ceylon");
ExitState call2 = task.call2();
Assert.assertEquals(CeylonState.ERROR, call2.ceylonState);
Assert.assertEquals(Main.EXIT_ERROR, call2.javacExitCode.exitCode);
}
Aggregations