@Test public void testExampleFileOption() throws Exception { try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_OK, tool.bootstrap(args("example", "--file=."))); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); Assert.assertTrue(out.getErr(), out.getErr().isEmpty()); } }
@Test public void testHelpOption() throws Exception { try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_OK, tool.bootstrap(args("--help"))); Assert.assertEquals(getHelpOutput(""), out.getOut()); } Assert.assertEquals("help", tool.getToolName()); }
@Test public void testVersionOption() throws Exception { try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_OK, tool.bootstrap(args("--version"))); Assert.assertTrue(out.getOut(), out.getOut().startsWith("ceylon version ")); Assert.assertTrue(out.getErr().isEmpty()); } Assert.assertEquals(null, tool.getToolName()); }
@Test public void testStacktracesOptionExample() throws Exception { try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_OK, tool.bootstrap(args("--stacktraces", "example"))); Assert.assertTrue(out.getErr(), out.getErr().isEmpty()); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); } Assert.assertEquals("example", tool.getToolName()); Assert.assertTrue(tool.getStacktraces()); }
@Test public void testHelpVersionOption() throws Exception { // We expect NO_SUCH_TOOL in this case because the HelpTool // isn't loadable by the toolLoader we're using try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_ARGS, tool.bootstrap(args("help", "--version"))); Assert.assertTrue(out.getOut().isEmpty()); Assert.assertTrue( out.getErr(), out.getErr().contains("ceylon help: Unrecognised long option '--version'")); } Assert.assertEquals("help", tool.getToolName()); }
@Test public void testBug820() throws Exception { // the top level tool doesn't take a --file option try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals( CeylonTool.SC_ARGS, tool.bootstrap(args("-rep", "http://something", "compile"))); Assert.assertEquals( "ceylon: 'http://something' is not a ceylon command\n" + "Run 'ceylon help' for more help", out.getErr().trim().replace("\r", "")); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); } }
@Test public void testSubtoolMissingArg() throws Exception { try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_ARGS, tool.bootstrap(args("config", "set"))); Assert.assertEquals( "ceylon config: Argument 'key' to command 'set' should appear at least 1 time(s)\n" + "\n" + "Usage:\n" + "ceylon set <key> <values...>\n" + "\n" + "Run 'ceylon help config' for more help", out.getErr().trim().replace("\r", "")); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); } }
@Test public void testTopLevelUnknownTool() throws Exception { try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_NO_SUCH_TOOL, tool.bootstrap(args("comple", "foo/bar"))); Assert.assertEquals( "ceylon: 'comple' is not a ceylon command\n" + "Did you mean?\n" + " compile\n" + " copy\n" + " example\n" + "\n" + "Run 'ceylon help' for more help", out.getErr().trim().replace("\r", "")); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); } }
@Test public void testFileOptionExample() throws Exception { // the top level tool doesn't take a --file option try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_ARGS, tool.bootstrap(args("--file=.", "example"))); Assert.assertEquals( "ceylon example: Unrecognised long option '--file=.' to command 'ceylon'\n" + "\n" + "Usage:\n" + "ceylon [--config=<file>] [--cwd=<dir>] [--define=<key>=<value>...] [--\n" + " distribution=<version-or-url>] [--java=<options>] [--no-config] [--no-\n" + " pager] [--paginate] [--show-home] [--stacktraces] [--version] [--] [\n" + " <tool-arguments...>]\n" + "\n" + "Run 'ceylon help example' for more help", out.getErr().trim().replace("\r", "")); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); } }
@Test public void testOptionExampleFil() throws Exception { // the top level tool doesn't take a --file option try (CapturingStdOut out = new CapturingStdOut()) { Assert.assertEquals(CeylonTool.SC_ARGS, tool.bootstrap(args("example", "--fil=."))); Assert.assertEquals( "ceylon example: Unrecognised long option '--fil=.' to command 'example'\n" + "\n" + "Usage:\n" + "ceylon example [--file=<value>] [--list-option=<bars>...] [--long-name] [--pure-\n" + " option] [--short-name=<value>] [--thread-state=<value>] [--] [\n" + " <args...>]\n" + "\n" + "Did you mean?\n" + " --file\n" + "\n" + "Run 'ceylon help example' for more help", out.getErr().trim().replace("\r", "")); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); } }
@Test public void testOptionException() throws Exception { try (CapturingStdOut out = new CapturingStdOut()) { System.setProperty("ceylon.home", "../dist/dist"); Assert.assertEquals( CeylonTool.SC_ARGS, tool.bootstrap(args("doc", "--link=ceylon.math=foobar://baz", "ceylon.math"))); Assert.assertEquals( "ceylon doc: Invalid value '[ceylon.math=foobar://baz]' given for option 'link'\n" + "to command 'doc': Unexpected link protocol: ceylon.math=foobar://baz (allowed\n" + "are: http://, https://, file://)\n" + "\n" + "Usage:\n" + "ceylon doc [--link=<url>...] [--non-shared] [--out=<dir-or-url>] [--pass=\n" + " <secret>] [--rep=<dir-or-url>...] [--source-code] [--src=<dir>...] [\n" + " --sysrep=<dir-or-url>] [--user=<name>] [--] <modules...>\n" + "\n" + "--link=<url>\n" + " The URL of a module repository containing documentation for\n" + " external dependencies.\n" + "\n" + " Parameter url must be one of supported protocols (http://, https://\n" + " or file://). Parameter url can be prefixed with module name\n" + " pattern, separated by a '=' character, determine for which external\n" + " modules will be use.\n" + "\n" + " Examples:\n" + "\n" + " --link " + Constants.REPO_URL_CEYLON + "\n" + " --link ceylon.math=" + Constants.REPO_URL_CEYLON + "\n" + "\n" + "Run 'ceylon help doc' for more help", out.getErr().trim().replace("\r", "")); Assert.assertTrue(out.getOut(), out.getOut().isEmpty()); } }
@Test public void testBashCompletion() throws Exception { Assert.assertEquals( CeylonTool.SC_OK, tool.bootstrap(args("bash-completion", "--cword=1", "--", "./cey"))); }