Search in sources :

Example 11 with CeylonCompileTool

use of com.redhat.ceylon.compiler.CeylonCompileTool in project ceylon-compiler by ceylon.

the class CompilerToolTests method testCompileKeywordsInModuleName.

@Test
public void testCompileKeywordsInModuleName() throws Exception {
    ToolModel<CeylonCompileTool> model = pluginLoader.loadToolModel("compile");
    Assert.assertNotNull(model);
    CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--src=test/src", "com.redhat.ceylon.tools.test.keywords.long.module"));
    tool.run();
}
Also used : CeylonCompileTool(com.redhat.ceylon.compiler.CeylonCompileTool) Test(org.junit.Test)

Example 12 with CeylonCompileTool

use of com.redhat.ceylon.compiler.CeylonCompileTool in project ceylon-compiler by ceylon.

the class NewProjectToolTests method testHelloWorldNoAntNoEclipseCompiles.

@Test
public void testHelloWorldNoAntNoEclipseCompiles() throws Exception {
    ToolModel<CeylonNewTool> newModel = pluginLoader.loadToolModel("new");
    Assert.assertNotNull(newModel);
    Assert.assertTrue(newModel.isPorcelain());
    Path tmpPath = Files.createTempDirectory("ceylon-new-");
    File tmpDir = tmpPath.toFile();
    try {
        CeylonNewTool newTool = pluginFactory.bindArguments(newModel, getMainTool(), args("--from=../ceylon-dist/templates", "hello-world", "--module-name=org.example.hello", "--module-version=1", "--ant=false", "--eclipse=false", tmpDir.getAbsolutePath()));
        runTool(newTool);
        ToolModel<CeylonCompileTool> compileModel = pluginLoader.loadToolModel("compile");
        Assert.assertNotNull(compileModel);
        CeylonCompileTool compileTool = pluginFactory.bindArguments(compileModel, getMainTool(), args("--src=" + tmpDir.getAbsolutePath() + "/source", "--out=" + tmpDir.getAbsolutePath(), "org.example.hello"));
        runTool(compileTool);
    } finally {
        delete(tmpDir);
    }
}
Also used : Path(java.nio.file.Path) CeylonCompileTool(com.redhat.ceylon.compiler.CeylonCompileTool) File(java.io.File) Test(org.junit.Test)

Example 13 with CeylonCompileTool

use of com.redhat.ceylon.compiler.CeylonCompileTool in project ceylon-compiler by ceylon.

the class CompilerToolTests method testCompileWithRuntimeException.

@Test
public void testCompileWithRuntimeException() throws Exception {
    ToolModel<CeylonCompileTool> model = pluginLoader.loadToolModel("compile");
    Assert.assertNotNull(model);
    CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--src=test/src", "com.redhat.ceylon.tools.test.runtimeex"));
    try {
        tool.run();
        Assert.fail("Tool should have thrown an exception");
    } catch (CompilerErrorException x) {
        Assert.assertEquals("There was 1 error", x.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
        Assert.fail("Unexpected exception");
    }
}
Also used : CeylonCompileTool(com.redhat.ceylon.compiler.CeylonCompileTool) CompilerErrorException(com.redhat.ceylon.compiler.CompilerErrorException) Test(org.junit.Test)

Example 14 with CeylonCompileTool

use of com.redhat.ceylon.compiler.CeylonCompileTool in project ceylon-compiler by ceylon.

the class CompilerToolTests method testValidatingJavaOptions.

@Test
public void testValidatingJavaOptions() throws Exception {
    ToolModel<CeylonCompileTool> model = pluginLoader.loadToolModel("compile");
    Assert.assertNotNull(model);
    try {
        CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--javac=-target=foo", "com.example"));
        Assert.fail("Tool should have thrown an exception");
    } catch (OptionArgumentException x) {
        Assert.assertEquals("Invalid --javac option: -target: invalid target release: foo", x.getMessage());
    }
    try {
        CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--javac=-source=foo", "com.example"));
        Assert.fail("Tool should have thrown an exception");
    } catch (OptionArgumentException x) {
        Assert.assertEquals("Invalid --javac option: -source: invalid source release: foo", x.getMessage());
    }
    try {
        CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--javac=-monkey", "com.example"));
        Assert.fail("Tool should have thrown an exception");
    } catch (OptionArgumentException x) {
        Assert.assertEquals("Unknown --javac option: -monkey", x.getMessage());
    }
    {
        CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--javac=-Xlint:cast", "--src=test/src", "com.redhat.ceylon.tools.test.ceylon"));
    }
    try {
        CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--javac=-Xlint:monkey", "--src=test/src", "com.redhat.ceylon.tools.test.ceylon"));
        Assert.fail("Tool should have thrown an exception");
    } catch (OptionArgumentException x) {
        Assert.assertEquals("Unknown --javac option: -Xlint:monkey", x.getMessage());
    }
}
Also used : CeylonCompileTool(com.redhat.ceylon.compiler.CeylonCompileTool) OptionArgumentException(com.redhat.ceylon.common.tool.OptionArgumentException) Test(org.junit.Test)

Example 15 with CeylonCompileTool

use of com.redhat.ceylon.compiler.CeylonCompileTool in project ceylon-compiler by ceylon.

the class CompilerToolTests method testCompileModuleAndVersion.

@Test
public void testCompileModuleAndVersion() throws Exception {
    ToolModel<CeylonCompileTool> model = pluginLoader.loadToolModel("compile");
    Assert.assertNotNull(model);
    try {
        CeylonCompileTool tool = pluginFactory.bindArguments(model, getMainTool(), options("--src=test/src", "com.redhat.ceylon.tools.test.ceylon/1.0"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        Assert.assertEquals("Invalid module name or source file: com.redhat.ceylon.tools.test.ceylon/1.0\n" + "Module names should not contain any version part.\n" + "Source file names should be given relative to the current directory.", e.getMessage());
    }
}
Also used : CeylonCompileTool(com.redhat.ceylon.compiler.CeylonCompileTool) OptionArgumentException(com.redhat.ceylon.common.tool.OptionArgumentException) Test(org.junit.Test)

Aggregations

CeylonCompileTool (com.redhat.ceylon.compiler.CeylonCompileTool)27 Test (org.junit.Test)27 OptionArgumentException (com.redhat.ceylon.common.tool.OptionArgumentException)8 CompilerErrorException (com.redhat.ceylon.compiler.CompilerErrorException)6 File (java.io.File)4 JarFile (java.util.jar.JarFile)3 ToolUsageError (com.redhat.ceylon.common.tool.ToolUsageError)2 SystemErrorException (com.redhat.ceylon.compiler.SystemErrorException)2 Path (java.nio.file.Path)1 ZipEntry (java.util.zip.ZipEntry)1