Skip to content

Commit

Permalink
#121 added autocompletion tests when cannot instantiate command class
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Aug 23, 2017
1 parent e704e78 commit 731f1ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
* Generates a bash auto-complete script.
*/
public class AutoComplete {
private AutoComplete() {
}
private AutoComplete() { }

public static void main(String... args) { CommandLine.run(new App(), System.err, args); }

Expand Down
19 changes: 19 additions & 0 deletions src/test/java/picocli/AutoCompleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ public void testAutoCompleteAppHelp() throws Exception {
assertEquals(AUTO_COMPLETE_APP_USAGE, actual);
}

@Test
public void testAutoCompleteAppCannotInstantiate() throws Exception {
@Command(name = "test")
class TestApp {
public TestApp() { throw new RuntimeException();}
}

PrintStream originalErr = System.err;
ByteArrayOutputStream baos = new ByteArrayOutputStream(2500);
System.setErr(new PrintStream(baos));

AutoComplete.main(TestApp.class.getName());

System.setErr(originalErr);
String actual = new String(baos.toByteArray(), "UTF8");
assertTrue(actual.startsWith("java.lang.InstantiationException: picocli.AutoCompleteTest$1TestApp"));
assertTrue(actual.endsWith(AUTO_COMPLETE_APP_USAGE));
}

@Test
public void testAutoCompleteAppCompletionScriptFileWillNotOverwrite() throws Exception {
PrintStream originalErr = System.err;
Expand Down

0 comments on commit 731f1ac

Please sign in to comment.