use of com.redhat.ceylon.compiler.java.launcher.Main.ExitState in project ceylon-compiler by ceylon.
the class CompilerTests method assertErrors.
protected void assertErrors(String[] ceylonFiles, List<String> options, Throwable expectedException, boolean includeWarnings, CompilerError... expectedErrors) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
ErrorCollector collector = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(options, collector, ceylonFiles);
boolean expectedToFail = false;
Diagnostic.Kind lowestErrorLevel = includeWarnings ? Diagnostic.Kind.WARNING : Diagnostic.Kind.ERROR;
for (CompilerError expectedError : expectedErrors) {
if (expectedError.kind == Diagnostic.Kind.ERROR) {
expectedToFail = true;
}
// we are interested in WARNING + ERROR kinds
if (lowestErrorLevel.compareTo(expectedError.kind) == -1)
lowestErrorLevel = expectedError.kind;
}
EnumSet<Diagnostic.Kind> kinds = EnumSet.range(Diagnostic.Kind.ERROR, lowestErrorLevel);
// 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 successful (it should have failed!)");
}
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);
}
Set<CompilerError> actualErrors = collector.get(kinds);
compareErrors(actualErrors, expectedErrors);
}
use of com.redhat.ceylon.compiler.java.launcher.Main.ExitState in project ceylon-compiler by ceylon.
the class CompilerTests method compilesWithoutWarnings.
protected void compilesWithoutWarnings(List<String> options, String... ceylon) {
ErrorCollector dl = new ErrorCollector();
ExitState exitState = getCompilerTask(options, dl, ceylon).call2();
Assert.assertEquals(exitState.ceylonState, CeylonState.OK);
Assert.assertEquals("The code compiled with javac warnings", 0, dl.get(Diagnostic.Kind.WARNING).size() + dl.get(Diagnostic.Kind.MANDATORY_WARNING).size());
}
use of com.redhat.ceylon.compiler.java.launcher.Main.ExitState in project ceylon-compiler by ceylon.
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 == Main.EXIT_ERROR);
assert (exitState.ceylonState == CeylonState.ERROR);
TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
compareErrors(actualErrors, expectedErrors);
}
Aggregations