Search in sources :

Example 26 with CompilerError

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

the class CMRTests method testMdlBug1062IncompatibleNonSharedImport.

@Test
public void testMdlBug1062IncompatibleNonSharedImport() throws IOException {
    // compile our java class
    File classesOutputFolder = new File(destDir + "-jar-classes");
    cleanCars(classesOutputFolder.getPath());
    classesOutputFolder.mkdirs();
    File jarOutputFolder = new File(destDir + "-jar");
    cleanCars(jarOutputFolder.getPath());
    jarOutputFolder.mkdirs();
    compileJavaModule(jarOutputFolder, classesOutputFolder, "bug1062.javaA", "1", new File(getPackagePath() + "/modules/bug1062/javaA1-src"), new File[0], "bug1062/javaA/JavaA.java");
    compileJavaModule(jarOutputFolder, classesOutputFolder, "bug1062.javaA", "2", new File(getPackagePath() + "/modules/bug1062/javaA2-src"), new File[0], "bug1062/javaA/JavaA.java");
    compileJavaModule(jarOutputFolder, classesOutputFolder, "bug1062.javaB", "1", new File(getPackagePath() + "/modules/bug1062/javaB-module-src"), new File[] { new File(jarOutputFolder, "bug1062/javaA/1/bug1062.javaA-1.jar") }, "bug1062/javaB/JavaB.java");
    // ceylon module imports JavaA/2 and JavaB/1
    // JavaB/1 imports JavaA/1
    assertErrors("modules/bug1062/ceylon/test", Arrays.asList("-rep", jarOutputFolder.getPath(), "-cp", getClassPathAsPath()), null, new CompilerError(5, "could not determine type of method or attribute reference: 'method' of 'JavaB': Error while loading the bug1062.javaB/1 module:\n" + "   Declaration 'bug1062.javaA.JavaA' could not be found in module 'bug1062.javaB' or its imported modules but was found in the non-imported module 'bug1062.javaA'"), new CompilerError(5, "parameter type could not be determined: 'arg0' of 'method' in 'JavaB': Error while loading the bug1062.javaB/1 module:\n" + "   Declaration 'bug1062.javaA.JavaA' could not be found in module 'bug1062.javaB' or its imported modules but was found in the non-imported module 'bug1062.javaA'"));
}
Also used : CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 27 with CompilerError

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

the class CMRTests method testMdlMultipleVersionsDuringImport.

@Test
public void testMdlMultipleVersionsDuringImport() {
    // Compile module A/1
    Boolean result = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules/multiversion/a1"), "modules/multiversion/a1/a/module.ceylon", "modules/multiversion/a1/a/package.ceylon", "modules/multiversion/a1/a/A.ceylon").call();
    Assert.assertEquals(Boolean.TRUE, result);
    // Compile module A/2
    result = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules/multiversion/a2"), "modules/multiversion/a2/a/module.ceylon", "modules/multiversion/a2/a/package.ceylon", "modules/multiversion/a2/a/A.ceylon").call();
    Assert.assertEquals(Boolean.TRUE, result);
    ErrorCollector collector = new ErrorCollector();
    // Compile module cImportsATwice which imports both A/1 and A/2
    result = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules/multiversion/c"), collector, "modules/multiversion/c/cImportsATwice/module.ceylon", "modules/multiversion/c/cImportsATwice/C.ceylon").call();
    Assert.assertEquals(Boolean.FALSE, result);
    compareErrors(collector.get(Diagnostic.Kind.ERROR), new CompilerError(20, "module (transitively) imports conflicting versions of dependency 'a': version '1' and version '2'"), new CompilerError(20, "source code imports two different versions of module 'a': version '1' and version '2'"), new CompilerError(22, "duplicate module import: 'a'"));
}
Also used : ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) Test(org.junit.Test)

Example 28 with CompilerError

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

the class CMRTests method testMdlDefaultUsesJavaWithoutImportingIt.

@Test
public void testMdlDefaultUsesJavaWithoutImportingIt() throws IOException {
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "/modules/jdk/defaultUsesJavaWithoutImportingIt");
    options.addAll(defaultOptions);
    assertErrors("modules/jdk/defaultUsesJavaWithoutImportingIt/Foo", new CompilerError(20, "package not found in imported modules: 'java.lang' (define a module and add module import to its module descriptor)"), new CompilerError(23, "function or value does not exist: 'nanoTime'"));
}
Also used : CompilerError(com.redhat.ceylon.compiler.java.test.CompilerError) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 29 with CompilerError

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

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

the class CMRTests method testOverridesCeylonModuleVersionAlterdPackageSharing.

@Test
public void testOverridesCeylonModuleVersionAlterdPackageSharing() {
    setupBinaryModulesForOverridesCeylonModuleTests();
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl compilerTask = getCompilerTask(Arrays.asList("-src", getPackagePath() + "/modules", "-overrides", getPackagePath() + "modules/overridesCeylonModule/overrides-b-version.xml"), collector, "modules/overridesCeylonModule/module.ceylon", "modules/overridesCeylonModule/testImportHiddenPackage.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, "imported package is not shared: 'b.hidden'"));
}
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) 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