Search in sources :

Example 11 with ErrorCollector

use of com.redhat.ceylon.compiler.java.test.ErrorCollector in project ceylon-compiler by ceylon.

the class CMRTests method testMdlAetherMissingDependencies.

@Test
public void testMdlAetherMissingDependencies() throws IOException {
    CompilerError[] expectedErrors = new CompilerError[] { new CompilerError(6, "Error while loading the org.apache.camel:camel-jetty/2.9.4 module:\n" + "   Declaration 'org.apache.camel.component.http.HttpComponent' could not be found in module 'org.apache.camel:camel-jetty' or its imported modules"), new CompilerError(10, "argument must be assignable to parameter 'arg1' of 'addComponent' in 'DefaultCamelContext': 'JettyHttpComponent' is not assignable to 'Component?': Error while loading the org.apache.camel:camel-jetty/2.9.4 module:\n" + "   Declaration 'org.apache.camel.component.http.HttpComponent' could not be found in module 'org.apache.camel:camel-jetty' or its imported modules") };
    ErrorCollector collector = new ErrorCollector();
    // Try to compile the ceylon module
    CeyloncTaskImpl ceylonTask = getCompilerTask(Arrays.asList("-out", destDir, "-rep", "aether"), collector, "modules/bug1100/module.ceylon", "modules/bug1100/test.ceylon");
    assertEquals("Compilation failed", Boolean.FALSE, ceylonTask.call());
    TreeSet<CompilerError> actualErrors = collector.get(Diagnostic.Kind.ERROR);
    compareErrors(actualErrors, expectedErrors);
}
Also used : CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) Test(org.junit.Test)

Example 12 with ErrorCollector

use of com.redhat.ceylon.compiler.java.test.ErrorCollector in project ceylon-compiler by ceylon.

the class RecoveryTests method testSyntaxErrorInModule.

@Test
public void testSyntaxErrorInModule() throws IOException {
    String subPath = "modules/syntaxErrorInModule";
    String srcPath = getPackagePath() + subPath;
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(srcPath);
    options.addAll(defaultOptions);
    options.add("-continue");
    ErrorCollector c = new ErrorCollector();
    CeyloncTaskImpl task = getCompilerTask(options, c, Arrays.asList("okmodule"), subPath + "/someok.ceylon");
    Boolean ret = task.call();
    assertFalse(ret);
    TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
    compareErrors(actualErrors, new CompilerError(-1, "incorrect syntax: no viable alternative at token end of file"), new CompilerError(20, "incorrect syntax: mismatched token 'ERROR' expecting initial-lowercase identifier"), new CompilerError(20, "incorrect syntax: no viable alternative at token '\"1.0.0\"'"), new CompilerError(20, "incorrect syntax: no viable alternative at token 'okmodule'"));
    File carFile = getModuleArchive("default", null);
    assertTrue(carFile.exists());
    JarFile car = new JarFile(carFile);
    ZipEntry moduleClass = car.getEntry("foobar_.class");
    assertNotNull(moduleClass);
    car.close();
    carFile = getModuleArchive("okmodule", "1.0.0");
    assertFalse(carFile.exists());
}
Also used : ZipEntry(java.util.zip.ZipEntry) ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) 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 13 with ErrorCollector

use of com.redhat.ceylon.compiler.java.test.ErrorCollector in project ceylon-compiler by ceylon.

the class RecoveryTests method testErrorSameCompilationUnit.

@Test
public void testErrorSameCompilationUnit() throws IOException {
    String subPath = "modules/errorInSameCompilationUnit";
    String srcPath = getPackagePath() + subPath;
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(srcPath);
    options.addAll(defaultOptions);
    options.add("-continue");
    ErrorCollector c = new ErrorCollector();
    CeyloncTaskImpl task = getCompilerTask(options, c, subPath + "/someok.ceylon");
    Boolean ret = task.call();
    assertFalse(ret);
    TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
    compareErrors(actualErrors, new CompilerError(23, "type does not exist: 'ERROR'"));
    File carFile = getModuleArchive("default", null);
    assertTrue(carFile.exists());
    JarFile car = new JarFile(carFile);
    ZipEntry moduleClass = car.getEntry("a_.class");
    assertNotNull(moduleClass);
    car.close();
}
Also used : ZipEntry(java.util.zip.ZipEntry) ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) 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 14 with ErrorCollector

use of com.redhat.ceylon.compiler.java.test.ErrorCollector in project ceylon-compiler by ceylon.

the class RecoveryTests method testMissingImport.

@Test
public void testMissingImport() throws IOException {
    String subPath = "modules/missingImport";
    String srcPath = getPackagePath() + subPath;
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(srcPath);
    options.addAll(defaultOptions);
    options.add("-continue");
    ErrorCollector c = new ErrorCollector();
    CeyloncTaskImpl task = getCompilerTask(options, c, Arrays.asList("okmodule"), subPath + "/someok.ceylon");
    Boolean ret = task.call();
    assertFalse(ret);
    TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
    compareErrors(actualErrors, new CompilerError(21, "cannot find module artifact notfound-1(.car|.jar)\n  \t- dependency tree: okmodule/1.0.0 -> notfound/1"));
    File carFile = getModuleArchive("default", null);
    assertTrue(carFile.exists());
    JarFile car = new JarFile(carFile);
    ZipEntry moduleClass = car.getEntry("foobar_.class");
    assertNotNull(moduleClass);
    car.close();
    carFile = getModuleArchive("okmodule", "1.0.0");
    assertFalse(carFile.exists());
}
Also used : ZipEntry(java.util.zip.ZipEntry) ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) 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 15 with ErrorCollector

use of com.redhat.ceylon.compiler.java.test.ErrorCollector in project ceylon-compiler by ceylon.

the class RecoveryTests method compileIgnoringCeylonErrors.

private ErrorCollector compileIgnoringCeylonErrors(String... ceylon) {
    ErrorCollector c = new ErrorCollector();
    getCompilerTask(defaultOptions, c, ceylon).call2();
    Assert.assertTrue("Expected only ceylon errors: " + c.getAssertionFailureMessage(), 0 == c.getNumBackendErrors());
    return c;
}
Also used : ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector)

Aggregations

ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)26 Test (org.junit.Test)23 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)18 CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)15 File (java.io.File)10 JarFile (java.util.jar.JarFile)7 LinkedList (java.util.LinkedList)6 ZipEntry (java.util.zip.ZipEntry)6 ArrayList (java.util.ArrayList)4 ExitState (com.redhat.ceylon.compiler.java.launcher.Main.ExitState)3 CeyloncFileManager (com.redhat.ceylon.compiler.java.tools.CeyloncFileManager)3 CeyloncTool (com.redhat.ceylon.compiler.java.tools.CeyloncTool)3 Module (com.redhat.ceylon.model.typechecker.model.Module)3 ZipFile (java.util.zip.ZipFile)2 Ignore (org.junit.Ignore)2 ModuleImport (com.redhat.ceylon.model.typechecker.model.ModuleImport)1 StringWriter (java.io.StringWriter)1