use of org.eclipse.ceylon.common.tool.OptionArgumentException in project ceylon by eclipse.
the class CeylonTool method handleException.
public static int handleException(CeylonTool mainTool, Exception ex) throws Exception {
int result;
if (ex instanceof NoSuchToolException) {
result = SC_NO_SUCH_TOOL;
} else if (ex instanceof ModelException) {
result = SC_TOOL_CREATION;
} else if (ex instanceof OptionArgumentException) {
result = SC_ARGS;
} else if (ex instanceof FatalToolError) {
result = SC_TOOL_BUG;
} else if (ex instanceof ToolError) {
ToolError err = (ToolError) ex;
result = err.isExitCodeProvided() ? err.getExitCode() : SC_TOOL_ERROR;
} else {
result = SC_TOOL_EXCEPTION;
}
Usage.handleException(mainTool, mainTool.getToolName(), ex);
return result;
}
use of org.eclipse.ceylon.common.tool.OptionArgumentException 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"));
}
}
use of org.eclipse.ceylon.common.tool.OptionArgumentException in project ceylon by eclipse.
the class ImportJarToolTests method testJarOnly.
@Test
public void testJarOnly() {
ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
Assert.assertNotNull(model);
try {
CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("my.jar"));
Assert.fail();
} catch (OptionArgumentException e) {
Assert.assertEquals("Invalid value 'my.jar' given for argument 'module' to command 'import-jar'", e.getMessage());
}
}
use of org.eclipse.ceylon.common.tool.OptionArgumentException in project ceylon by eclipse.
the class ImportJarToolTests method testNoArgs.
@Test
public void testNoArgs() {
ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
Assert.assertNotNull(model);
try {
CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions());
Assert.fail();
} catch (OptionArgumentException e) {
Assert.assertEquals("Argument 'module' to command 'import-jar' should appear at least 1 time(s)", e.getMessage());
}
}
use of org.eclipse.ceylon.common.tool.OptionArgumentException in project ceylon by eclipse.
the class SrcToolTests method testNoArgs.
@Test
public void testNoArgs() throws Exception {
ToolModel<CeylonSrcTool> model = pluginLoader.loadToolModel("src");
Assert.assertNotNull(model);
try {
CeylonSrcTool tool = pluginFactory.bindArguments(model, getMainTool(), Collections.<String>emptyList());
Assert.fail();
} catch (OptionArgumentException e) {
// asserting this is thrown
}
}
Aggregations