Search in sources :

Example 1 with TestSubtoolTool

use of org.eclipse.ceylon.common.tool.example.TestSubtoolTool in project ceylon by eclipse.

the class ToolFactoryTest method testSubtool.

@Test
public void testSubtool() {
    ToolModel<TestSubtoolTool> model = pluginLoader.loadToolModel("subtool");
    TestSubtoolTool ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool1"));
    Assert.assertEquals(TestSubtoolTool.Subtool1.class, ex.getAction().getClass());
    ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool1", "--foo"));
    Assert.assertEquals(TestSubtoolTool.Subtool1.class, ex.getAction().getClass());
    try {
        ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool1", "--bar"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        Assert.assertEquals("Unrecognised long option '--bar' to command 'subtool1'", e.getMessage());
    }
    ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool2"));
    Assert.assertEquals(TestSubtoolTool.Subtool2.class, ex.getAction().getClass());
    ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool2", "--bar"));
    Assert.assertEquals(TestSubtoolTool.Subtool2.class, ex.getAction().getClass());
    try {
        ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool2", "--foo"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        Assert.assertEquals("Unrecognised long option '--foo' to command 'subtool2'", e.getMessage());
    }
    try {
        ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool3"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        String message = e.getMessage();
        Assert.assertTrue(message, message.startsWith("Invalid value 'subtool3' given for argument 'action'"));
    // Assert.assertTrue(message, message.contains("subtool1"));
    // Assert.assertTrue(message, message.contains("subtool2"));
    }
}
Also used : OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) TestSubtoolTool(org.eclipse.ceylon.common.tool.example.TestSubtoolTool) Test(org.junit.Test)

Aggregations

OptionArgumentException (org.eclipse.ceylon.common.tool.OptionArgumentException)1 TestSubtoolTool (org.eclipse.ceylon.common.tool.example.TestSubtoolTool)1 Test (org.junit.Test)1