Search in sources :

Example 6 with ExitState

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);
}
Also used : ExitState(com.redhat.ceylon.compiler.java.launcher.Main.ExitState) Kind(com.sun.source.util.TaskEvent.Kind) Diagnostic(javax.tools.Diagnostic) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)

Example 7 with ExitState

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());
}
Also used : ExitState(com.redhat.ceylon.compiler.java.launcher.Main.ExitState)

Example 8 with ExitState

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);
}
Also used : ExitState(com.redhat.ceylon.compiler.java.launcher.Main.ExitState)

Aggregations

ExitState (com.redhat.ceylon.compiler.java.launcher.Main.ExitState)8 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)6 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)3 Test (org.junit.Test)3 JavaPositionsRetriever (com.redhat.ceylon.compiler.java.codegen.JavaPositionsRetriever)2 TaskEvent (com.sun.source.util.TaskEvent)2 TaskListener (com.sun.source.util.TaskListener)2 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)2 File (java.io.File)2 DiagnosticListener (javax.tools.DiagnosticListener)2 CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)1 Kind (com.sun.source.util.TaskEvent.Kind)1 Diagnostic (javax.tools.Diagnostic)1