Skip to content

Commit

Permalink
[#1537] add test (cannot reproduce)
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Jan 2, 2022
1 parent 964ff6e commit 02d2ab4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/test/java/picocli/Issue1537Ambiguous.java
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());
}
}
}

0 comments on commit 02d2ab4

Please sign in to comment.