Search in sources :

Example 31 with ErrorCollector

use of org.eclipse.ceylon.compiler.java.test.ErrorCollector in project ceylon by eclipse.

the class CarGenerationTests method testCarWithServicesGreetRecompile.

/**
 * Whole module recompilation
 */
@Test
public void testCarWithServicesGreetRecompile() throws IOException {
    // first compile the old version
    testCarWithServicesGreet();
    // then recompile
    ErrorCollector ec = new ErrorCollector();
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "services/greet2/source");
    options.addAll(defaultOptions);
    CeyloncTaskImpl task = getCompilerTask(options, ec, Arrays.asList("services"));
    assertTrue(task.call());
    File carFile = getModuleArchive("services", "1.0");
    assertTrue(carFile.exists());
    Map<String, Set<String>> services = MetaInfServices.parseAllServices(carFile);
    Set<String> impls = services.get("services.Greeter");
    assertNotNull(impls);
    assertContains(impls, "services.HelloWorld");
    assertContains(impls, "services.Gday");
    assertContains(impls, "services.Bonjour");
    assertEquals(3, impls.size());
    assertEquals(1, services.size());
}
Also used : Set(java.util.Set) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 32 with ErrorCollector

use of org.eclipse.ceylon.compiler.java.test.ErrorCollector in project ceylon by eclipse.

the class CMRHTTPTests method assertTimeout.

private void assertTimeout(String[] files, List<String> options) {
    ErrorCollector collector = compileErrorTest(files, options, null, false, true);
    Set<CompilerError> errors = collector.get(Diagnostic.Kind.ERROR);
    Assert.assertTrue("Expecting a single error, got " + errors.size(), errors.size() == 1);
    CompilerError err = errors.iterator().next();
    Assert.assertTrue("Expecting a java.net.SocketTimeoutException, got " + err, err.toString().contains("java.net.SocketTimeoutException"));
}
Also used : ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError)

Example 33 with ErrorCollector

use of org.eclipse.ceylon.compiler.java.test.ErrorCollector in project ceylon by eclipse.

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(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) CeyloncTaskImpl(org.eclipse.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 34 with ErrorCollector

use of org.eclipse.ceylon.compiler.java.test.ErrorCollector in project ceylon by eclipse.

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(20, "incorrect syntax: missing ':' operator at '\"1.0.0\"'"));
    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(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) CeyloncTaskImpl(org.eclipse.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 35 with ErrorCollector

use of org.eclipse.ceylon.compiler.java.test.ErrorCollector in project ceylon by eclipse.

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(org.eclipse.ceylon.compiler.java.test.ErrorCollector)

Aggregations

ErrorCollector (org.eclipse.ceylon.compiler.java.test.ErrorCollector)35 Test (org.junit.Test)31 CeyloncTaskImpl (org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl)23 CompilerError (org.eclipse.ceylon.compiler.java.test.CompilerError)19 File (java.io.File)16 JarFile (java.util.jar.JarFile)12 LinkedList (java.util.LinkedList)11 ZipEntry (java.util.zip.ZipEntry)7 ArrayList (java.util.ArrayList)4 ExitState (org.eclipse.ceylon.compiler.java.launcher.Main.ExitState)4 Set (java.util.Set)3 ZipFile (java.util.zip.ZipFile)3 CeyloncFileManager (org.eclipse.ceylon.compiler.java.tools.CeyloncFileManager)3 CeyloncTool (org.eclipse.ceylon.compiler.java.tools.CeyloncTool)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 Ignore (org.junit.Ignore)3 JarEntry (java.util.jar.JarEntry)2 Manifest (java.util.jar.Manifest)2 StringWriter (java.io.StringWriter)1 TreeSet (java.util.TreeSet)1