Skip to content

Commit

Permalink
[#1537] update test setAbbreviatedSubcommandsAllowed: reproduced the …
Browse files Browse the repository at this point in the history
…issue
  • Loading branch information
remkop committed Jan 2, 2022
1 parent a1bd031 commit 9427525
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/test/java/picocli/Issue1537Ambiguous.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ public void run() {}

@Test
public void testExecute() {
int exitCode = new CommandLine(new MyCommand()).setAbbreviatedOptionsAllowed(true).execute("chem");
int exitCode = new CommandLine(new MyCommand()).setAbbreviatedSubcommandsAllowed(true).execute("chem");
assertEquals(2, exitCode);

String expected = String.format(
"Unmatched argument at index 0: 'chem'%n" +
"Did you mean: chem-formats or chemical-files?%n");
"Error: 'chem' is not unique: it matches 'chemical-files', 'chem-formats'%n" +
"Usage: <main class> [COMMAND]%n" +
"Commands:%n" +
" chemical-files, chem-formats%n");
assertEquals(expected, systemErrRule.getLog());
}

@Test
public void testParseArgs() {
try {
new CommandLine(new MyCommand()).setAbbreviatedOptionsAllowed(true).parseArgs("chem");
new CommandLine(new MyCommand()).setAbbreviatedSubcommandsAllowed(true).parseArgs("chem");
fail("expected exception");
} catch (CommandLine.UnmatchedArgumentException ex) {
assertEquals("Unmatched argument at index 0: 'chem'", ex.getMessage());
} catch (CommandLine.ParameterException ex) {
assertEquals("Error: 'chem' is not unique: it matches 'chemical-files', 'chem-formats'", ex.getMessage());
}
}
}

0 comments on commit 9427525

Please sign in to comment.