Search in sources :

Example 21 with ErrorCollector

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

the class IssuesTests_1500_1999 method testBug1969.

@SuppressWarnings("deprecation")
@Test
public void testBug1969() {
    java.util.List<File> sourceFiles = new ArrayList<File>(1);
    sourceFiles.add(new File(getPackagePath(), "bug19xx/Bug1969.ceylon"));
    CeyloncTool runCompiler = makeCompiler();
    StringWriter writer = new StringWriter();
    CeyloncFileManager runFileManager = (CeyloncFileManager) runCompiler.getStandardFileManager(writer, null, null, null);
    // make sure the destination repo exists
    new File(destDir).mkdirs();
    List<String> options = new LinkedList<String>();
    options.addAll(defaultOptions);
    if (!options.contains("-src"))
        options.addAll(Arrays.asList("-src", getSourcePath()));
    if (!options.contains("-cacherep"))
        options.addAll(Arrays.asList("-cacherep", getCachePath()));
    if (!options.contains("-sysrep"))
        options.addAll(Arrays.asList("-sysrep", getSysRepPath()));
    if (!options.contains("-cp"))
        options.addAll(Arrays.asList("-cp", getClassPathAsPath()));
    options.add("-verbose");
    Iterable<? extends JavaFileObject> compilationUnits1 = runFileManager.getJavaFileObjectsFromFiles(sourceFiles);
    CeyloncTaskImpl task = runCompiler.getTask(writer, runFileManager, null, options, null, compilationUnits1);
    ErrorCollector collector = new ErrorCollector();
    assertCompilesOk(collector, task.call2());
    Assert.assertTrue(writer.toString().length() > 0);
}
Also used : ArrayList(java.util.ArrayList) CeyloncTool(org.eclipse.ceylon.compiler.java.tools.CeyloncTool) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) LinkedList(java.util.LinkedList) StringWriter(java.io.StringWriter) File(java.io.File) CeyloncFileManager(org.eclipse.ceylon.compiler.java.tools.CeyloncFileManager) Test(org.junit.Test)

Example 22 with ErrorCollector

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

the class IssuesTests_1500_1999 method testBug1773.

@Test
public void testBug1773() {
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl task = getCompilerTask(defaultOptions, collector, "bug17xx/Bug1773.ceylon");
    // now compile it all the way
    ExitState exitState = task.call2();
    Assert.assertEquals(ExitState.CeylonState.ERROR, exitState.ceylonState);
    // make sure we only got one, do not trust actualErrors.size() for that since it's a Set so
    // two methods with same contents would count as one.
    Assert.assertEquals(1, exitState.errorCount);
    TreeSet<CompilerError> actualErrors = collector.get(Diagnostic.Kind.ERROR);
    compareErrors(actualErrors, new CompilerError(22, "dynamic is not supported on the JVM"));
}
Also used : ExitState(org.eclipse.ceylon.compiler.java.launcher.Main.ExitState) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) Test(org.junit.Test)

Example 23 with ErrorCollector

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

the class IssuesTests_6000_6499 method testBug6422.

@Ignore("Requires Android")
@Test
public void testBug6422() {
    String project = "../../../AndroidStudioProjects/MyApplication2/app";
    String src = project + "/src/main/ceylon";
    List<String> options = Arrays.asList("-jdk-provider", "android/23", "-src", src, "-rep", project + "/build/intermediates/ceylon-android/repository");
    ErrorCollector c = new ErrorCollector();
    List<String> modules = Arrays.asList("com.example.android.myapplication");
    assertCompilesOk(c, getCompilerTask(options, c, modules).call2());
}
Also used : ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with ErrorCollector

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

the class IssuesTests_6500_6999 method testBug6592.

@Test
public void testBug6592() {
    CompilationAssertion expectSysError = new CompilationAssertion() {

        public void onError(ErrorCollector collector, ExitState exitState) {
            TreeSet<CompilerError> treeSet = collector.get(Kind.ERROR);
            assertEquals(1, treeSet.size());
            CompilerError e = treeSet.iterator().next();
            assertTrue(e.message.contains("No such overrides file: "));
            assertTrue(e.message.contains("doesNotExist.xml"));
        }
    };
    assertCompiles(Arrays.asList("-overrides", "doesNotExist.xml"), new String[] { "bug65xx/bug6592/bug6592.ceylon" }, expectSysError);
    expectSysError = new CompilationAssertion() {

        public void onError(ErrorCollector collector, ExitState exitState) {
            TreeSet<CompilerError> treeSet = collector.get(Kind.ERROR);
            assertEquals(1, treeSet.size());
            CompilerError e = treeSet.iterator().next();
            assertTrue(e.message.contains("overrides.xml:2:12: Missing 'module' attribute in element [module: null]."));
        }
    };
    assertCompiles(Arrays.asList("-overrides", "test/src/org/eclipse/ceylon/compiler/java/test/issues/bug65xx/bug6592/overrides.xml"), new String[] { "bug65xx/bug6592/bug6592.ceylon" }, expectSysError);
}
Also used : ExitState(org.eclipse.ceylon.compiler.java.launcher.Main.ExitState) TreeSet(java.util.TreeSet) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) Test(org.junit.Test)

Example 25 with ErrorCollector

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

the class InteropTests method testJava9Module.

/**
 * Warning: this test requires a build with "ant -Djigsaw=true clean dist" and to run on Java 9+Jigsaw
 */
@Test
public void testJava9Module() throws Throwable {
    Assume.assumeTrue("Runs on JDK9", JDKUtils.jdk == JDKUtils.JDK.JDK9);
    assertErrors(new String[] { "java9/user/runError.ceylon", "java9/user/package.ceylon" }, Arrays.asList("-out", destDir, "-rep", "test/java9/modules"), null, new CompilerError(1, "imported package is not shared: 'com.ceylon.java9.internal'"));
    ErrorCollector c = new ErrorCollector();
    assertCompilesOk(c, getCompilerTask(Arrays.asList("-out", destDir, "-rep", "test/java9/modules"), c, "java9/user/run.ceylon", "java9/user/package.ceylon").call2());
    // check that we do not have a module-info.class
    File archive = getModuleArchive("org.eclipse.ceylon.compiler.java.test.interop.java9.user", "1");
    try (ZipFile zf = new ZipFile(archive)) {
        ZipEntry entry = zf.getEntry("module-info.class");
        assertNull(entry);
    }
    c = new ErrorCollector();
    assertCompilesOk(c, getCompilerTask(Arrays.asList("-out", destDir, "-rep", "test/java9/modules", "-module-info"), c, "java9/user/run.ceylon", "java9/user/package.ceylon").call2());
    // check that we do have a module-info.class
    try (ZipFile zf = new ZipFile(archive)) {
        ZipEntry entry = zf.getEntry("module-info.class");
        assertNotNull(entry);
    }
    run("org.eclipse.ceylon.compiler.java.test.interop.java9.user.run", new ModuleWithArtifact("org.eclipse.ceylon.compiler.java.test.interop.java9.user", "1"), new ModuleWithArtifact("com.ceylon.java9", "123", "test/java9/modules", "jar"));
    assertEquals(0, runInJava9(new String[] { destDir, "test/java9/modules", "../dist/dist/repo" }, new ModuleSpec(null, "org.eclipse.ceylon.compiler.java.test.interop.java9.user", "1"), Collections.<String>emptyList()));
}
Also used : ZipFile(java.util.zip.ZipFile) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ZipEntry(java.util.zip.ZipEntry) CompilerError(org.eclipse.ceylon.compiler.java.test.CompilerError) ErrorCollector(org.eclipse.ceylon.compiler.java.test.ErrorCollector) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

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