Skip to content

Commit 466975a

Browse files
committed
[#1159] added test
1 parent fe01f27 commit 466975a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/test/java/picocli/InheritedOptionTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import picocli.CommandLine.Option;
1515
import picocli.CommandLine.ParameterException;
1616
import picocli.CommandLine.Parameters;
17+
import picocli.CommandLine.ParseResult;
1718

1819
import java.util.*;
1920

@@ -504,4 +505,24 @@ public void testIssue1159WithEquals() {
504505
assertEquals(345, bean.x);
505506
}
506507

508+
@Test
509+
public void testIssue1159ParseResult() {
510+
Issue1159 bean = new Issue1159();
511+
CommandLine cmd = new CommandLine(bean).setAbbreviatedOptionsAllowed(true);
512+
ParseResult parseResult = cmd.parseArgs("sub", "--x", "345");
513+
assertEquals(345, bean.x);
514+
515+
assertTrue(parseResult.hasSubcommand());
516+
ParseResult subResult = parseResult.subcommand();
517+
518+
assertTrue("Matched on the subcommand", subResult.hasMatchedOption("--xxx-yyy"));
519+
Object subValue = subResult.matchedOption("--xxx-yyy").getValue();
520+
assertEquals(345, subValue);
521+
522+
assertFalse("Abbreviated options not supported in ParseResult...",
523+
subResult.hasMatchedOption("--x")); // this does not work
524+
525+
assertFalse("Not matched on the parent command",
526+
parseResult.hasMatchedOption("--xxx-yyy"));
527+
}
507528
}

0 commit comments

Comments
 (0)