Search in sources :

Example 21 with CompilerError

use of com.redhat.ceylon.compiler.java.test.CompilerError 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 22 with CompilerError

use of com.redhat.ceylon.compiler.java.test.CompilerError 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 23 with CompilerError

use of com.redhat.ceylon.compiler.java.test.CompilerError 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 24 with CompilerError

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

the class RecoveryTests method testTako.

@Ignore("This test largely depends on modules that are now binary-incompatible")
@Test
public void testTako() throws IOException {
    String subPath = "modules/bug1411";
    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 + "/dupdecl.ceylon", subPath + "/moduletest1/module.ceylon", subPath + "/moduletest1/package.ceylon", subPath + "/moduletest1/helloworld.ceylon", subPath + "/hello/hello.ceylon", subPath + "/hello/module.ceylon", subPath + "/hello/package.ceylon", subPath + "/testtest/module.ceylon", subPath + "/testtest/test.ceylon", subPath + "/sub/mod/module.ceylon", subPath + "/sub/mod/run.ceylon", subPath + "/sub/mod/package.ceylon", subPath + "/unknownmodule/module.ceylon", subPath + "/unknownmodule/run.ceylon", subPath + "/unknownmodule/package.ceylon", subPath + "/interop/module.ceylon", subPath + "/interop/interop.ceylon", subPath + "/jsonly/jsonly.ceylon", subPath + "/jsonly/module.ceylon", subPath + "/jsonly/package.ceylon", subPath + "/modulep/module.ceylon", subPath + "/modulep/main.ceylon", subPath + "/browser/dom/main.ceylon", subPath + "/browser/dom/package.ceylon", subPath + "/browser/module.ceylon", subPath + "/browser/main.ceylon", subPath + "/browser/package.ceylon", subPath + "/test/InheritanceAndBoxingTest.ceylon", subPath + "/test/ExceptionTest.ceylon", subPath + "/test/Foo.ceylon", subPath + "/test/GameOfLife.ceylon", subPath + "/test/Bar.ceylon", subPath + "/test/encoding.ceylon", subPath + "/test/helloworld.ceylon", subPath + "/swing/module.ceylon", subPath + "/swing/run.ceylon", subPath + "/swing/package.ceylon", subPath + "/interoprev/module.ceylon", subPath + "/interoprev/run.ceylon", subPath + "/interoprev/package.ceylon", subPath + "/java/hello.ceylon", subPath + "/java/module.ceylon", subPath + "/java/package.ceylon", subPath + "/helloworld.ceylon", subPath + "/wrongversion/module.ceylon", subPath + "/wrongversion/run.ceylon", subPath + "/wrongversion/package.ceylon", subPath + "/importhello/module.ceylon", subPath + "/importhello/helloworld.ceylon", subPath + "/usingimport.ceylon", // subPath + "/javaa/run.ceylon"
    subPath + "/gavinprob/module.ceylon", subPath + "/gavinprob/main.ceylon", subPath + "/web_ide_script/module.ceylon", subPath + "/web_ide_script/hello_world.ceylon", subPath + "/timetest/module.ceylon", subPath + "/timetest/test.ceylon");
    Boolean ret = task.call();
    assertFalse(ret);
    TreeSet<CompilerError> actualErrors = c.get(Diagnostic.Kind.ERROR);
    compareErrors(actualErrors, new CompilerError(1, "package not found in imported modules: 'java.lang' (define a module and add module import to its module descriptor)"), new CompilerError(2, "source code imports two different versions of module 'ceylon.file': version '0.5' and version '1.1.0'"), new CompilerError(2, "cannot find module artifact fooxhilio.bastardo-77.9(.car|.jar)\n" + "  \t- dependency tree: unknownmodule/1.0.0 -> fooxhilio.bastardo/77.9"), new CompilerError(4, "function or value does not exist: 'nanoTime'"), new CompilerError(4, "type does not exist: 'Test'"), new CompilerError(4, "unsupported module name: this namespace is used by Java platform modules"), new CompilerError(5, "duplicate declaration name: 'run'"), new CompilerError(7, "duplicate declaration name: 'run'"), new CompilerError(10, "case must be a toplevel anonymous class: 'alive' is not toplevel"), new CompilerError(10, "case must be a toplevel anonymous class: 'dead' is not toplevel"), new CompilerError(10, "case must be a toplevel anonymous class: 'moribund' is not toplevel"), new CompilerError(10, "case must be a toplevel anonymous class: 'resurrected' is not toplevel"), new CompilerError(12, "imported declaration not found: 'newServer_bogus'"), new CompilerError(30, "function or value does not exist: 'newServer_bogus'"), new CompilerError(135, "function or value does not exist: 'array'"), new CompilerError(138, "could not determine type of function or value reference: 'cells'"), new CompilerError(139, "could not determine type of function or value reference: 'c'"), new CompilerError(140, "could not determine type of function or value reference: 'c'"));
    File carFile = getModuleArchive("default", null);
    assertTrue(carFile.exists());
    String[] modules = new String[] { "swing/1.0.0", "web_ide_script/1.0.0", "browser/1.0.0", "timetest/1.0.0", "interop/1.0.0", "importhello/0.1", "interoprev/1.0.0", "modulep/0.1", "hello/1.0.0", "moduletest1/0.1", "jsonly/1.0.0", "testtest/1.1", "sub.mod/1.0.0" };
    for (String module : modules) {
        int sep = module.indexOf('/');
        String name = module.substring(0, sep);
        String version = module.substring(sep + 1);
        carFile = getModuleArchive(name, version);
        assertTrue("Module created car: " + module, carFile.exists());
    }
}
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) JarFile(java.util.jar.JarFile) File(java.io.File) LinkedList(java.util.LinkedList) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with CompilerError

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

the class BcTests method testBinaryVersionIncompatibleModule1.

// tests before we renamed module_.class to $module_.class
@Test
public void testBinaryVersionIncompatibleModule1() throws IOException {
    CompilationTask compiler = compileJava("binaryVersionOld/module_.java");
    Assert.assertTrue(compiler.call());
    // so now make a jar containing the java module
    File jarFolder = new File(destDir, "com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld/1/");
    jarFolder.mkdirs();
    File jarFile = new File(jarFolder, "com.redhat.ceylon.compiler.java.test.bc.binaryVersionOld-1.jar");
    // now jar it up
    JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(jarFile));
    ZipEntry entry = new ZipEntry("com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld/module_.class");
    outputStream.putNextEntry(entry);
    File javaClass = new File(destDir, "com/redhat/ceylon/compiler/java/test/bc/binaryVersionOld/module_.class");
    FileInputStream inputStream = new FileInputStream(javaClass);
    Util.copy(inputStream, outputStream);
    inputStream.close();
    outputStream.close();
    assertErrors("binaryVersion/module", new CompilerError(21, "version '1' of module 'com.redhat.ceylon.compiler.java.test.bc.binaryVersionOld' was compiled by" + " an incompatible version of the compiler" + " (binary version 0.0 of module is not compatible with binary version " + Versions.JVM_BINARY_MAJOR_VERSION + "." + Versions.JVM_BINARY_MINOR_VERSION + " of this compiler)"));
}
Also used : FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) File(java.io.File) CompilationTask(javax.tools.JavaCompiler.CompilationTask) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)47 Test (org.junit.Test)47 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)15 File (java.io.File)13 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)11 JarFile (java.util.jar.JarFile)11 ZipEntry (java.util.zip.ZipEntry)7 LinkedList (java.util.LinkedList)6 ZipFile (java.util.zip.ZipFile)4 HttpServer (com.sun.net.httpserver.HttpServer)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 JarOutputStream (java.util.jar.JarOutputStream)2 CompilationTask (javax.tools.JavaCompiler.CompilationTask)2 ExitState (com.redhat.ceylon.compiler.java.launcher.Main.ExitState)1 Module (com.redhat.ceylon.model.typechecker.model.Module)1 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 Ignore (org.junit.Ignore)1