-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package picocli; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.contrib.java.lang.system.SystemErrRule; | ||
import picocli.CommandLine.Command; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class Issue1537Ambiguous { | ||
|
||
@Rule | ||
public SystemErrRule systemErrRule = new SystemErrRule().enableLog().muteForSuccessfulTests(); | ||
|
||
@Command | ||
static class MyCommand implements Runnable { | ||
|
||
@Command(name = "chemical-files", aliases = "chem-formats") | ||
void sub() {} | ||
|
||
public void run() {} | ||
} | ||
|
||
@Test | ||
public void testExecute() { | ||
int exitCode = new CommandLine(new MyCommand()).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"); | ||
assertEquals(expected, systemErrRule.getLog()); | ||
} | ||
|
||
@Test | ||
public void testParseArgs() { | ||
try { | ||
new CommandLine(new MyCommand()).parseArgs("chem"); | ||
fail("expected exception"); | ||
} catch (CommandLine.UnmatchedArgumentException ex) { | ||
assertEquals("Unmatched argument at index 0: 'chem'", ex.getMessage()); | ||
} | ||
} | ||
} |