Search in sources :

Example 36 with CeyloncTaskImpl

use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.

the class CMRTests method testMdlAetherMissingDependenciesOverride.

@Test
public void testMdlAetherMissingDependenciesOverride() throws IOException {
    // Try to compile the ceylon module
    CeyloncTaskImpl ceylonTask = getCompilerTask(Arrays.asList("-out", destDir, "-rep", "aether", "-overrides", getPackagePath() + "/modules/bug1100/overrides.xml"), "modules/bug1100/module.ceylon", "modules/bug1100/test.ceylon");
    assertEquals("Compilation failed", Boolean.TRUE, ceylonTask.call());
}
Also used : CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) Test(org.junit.Test)

Example 37 with CeyloncTaskImpl

use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl 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 38 with CeyloncTaskImpl

use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.

the class CarGenerationTests method testCarResourceAlternativeRoot.

@Test
public void testCarResourceAlternativeRoot() throws IOException {
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "resmodules/altrootdir/source");
    options.add("-res");
    options.add(getPackagePath() + "resmodules/altrootdir/resource");
    options.add("-resroot");
    options.add("ALTROOT");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, null, Arrays.asList("test.altrootdir"));
    Boolean ret = task.call();
    assertTrue(ret);
    File carFile = getModuleArchive("test.altrootdir", "1.0");
    assertTrue(carFile.exists());
    JarFile car = new JarFile(carFile);
    ZipEntry carEntry = car.getEntry("test/altrootdir/README.txt");
    assertNotNull(carEntry);
    carEntry = car.getEntry("rootfile");
    assertNotNull(carEntry);
    carEntry = car.getEntry("test/altrootdir/$module_.class");
    assertNotNull(carEntry);
    car.close();
}
Also used : ZipEntry(java.util.zip.ZipEntry) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 39 with CeyloncTaskImpl

use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.

the class CMRTests method testOverridesCeylonModuleInSourceImport.

@Test
public void testOverridesCeylonModuleInSourceImport() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-continue", "-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-a-version.xml"), collector, "modules/overridesCeylonModule/module.ceylon");
    ModulesRetriever modulesRetriever = new ModulesRetriever(compilerTask.getContext());
    compilerTask.setTaskListener(modulesRetriever);
    Boolean result = compilerTask.call();
    Assert.assertEquals(Boolean.FALSE, result);
    compareErrors(collector.get(Diagnostic.Kind.ERROR), new CompilerError(2, "The module import should not be overriden, since it is explicitely imported by a project source module"));
    assert (modulesRetriever.modules != null);
    Module a = modulesRetriever.modules.get("a");
    Module b = modulesRetriever.modules.get("b");
    Module c = modulesRetriever.modules.get("c");
    assert (a != null);
    assert (b != null);
    assert (c != null);
    assertEquals("The version override should not be applied to modules imported in source code", "2", a.getVersion());
    assertEquals("The version override should not be applied to modules imported in source code", "2", b.getVersion());
    assertEquals("The version override should not be applied to modules imported in source code", "2", c.getVersion());
}
Also used : ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) Module(com.redhat.ceylon.model.typechecker.model.Module) Test(org.junit.Test)

Example 40 with CeyloncTaskImpl

use of com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon-compiler by ceylon.

the class CMRTests method testMdlModuleDefaultIncrementalNoPackage.

@Test
public void testMdlModuleDefaultIncrementalNoPackage() throws IOException {
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "/modules/def");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, null, Collections.<String>emptyList(), "modules/def/A.ceylon");
    Boolean ret = task.call();
    assertTrue(ret);
    task = getCompilerTask(options, null, Collections.<String>emptyList(), "modules/def/RequiresA.ceylon");
    ret = task.call();
    assertTrue(ret);
}
Also used : CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)53 Test (org.junit.Test)43 File (java.io.File)27 JarFile (java.util.jar.JarFile)19 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)18 LinkedList (java.util.LinkedList)18 ZipEntry (java.util.zip.ZipEntry)13 CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)11 ZipFile (java.util.zip.ZipFile)8 ExitState (com.redhat.ceylon.compiler.java.launcher.Main.ExitState)6 CeyloncFileManager (com.redhat.ceylon.compiler.java.tools.CeyloncFileManager)5 CeyloncTool (com.redhat.ceylon.compiler.java.tools.CeyloncTool)5 ArrayList (java.util.ArrayList)5 TaskEvent (com.sun.source.util.TaskEvent)4 TaskListener (com.sun.source.util.TaskListener)4 Module (com.redhat.ceylon.model.typechecker.model.Module)3 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)3 DiagnosticListener (javax.tools.DiagnosticListener)3 Ignore (org.junit.Ignore)3 JavaPositionsRetriever (com.redhat.ceylon.compiler.java.codegen.JavaPositionsRetriever)2