Skip to content

Commit

Permalink
[#2228] update test with prints
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Apr 14, 2024
1 parent a5fdd30 commit a6053da
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/test/java/picocli/Issue2228.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,31 @@ public void run() {
@Test
public void testParseResult() {
final CommandLine commandLine = new CommandLine(new Issue2228.TestCommand());
final ParseResult[] caughtParseResult = new ParseResult[1];
final boolean[] handled = new boolean[] {false};
commandLine.setExecutionExceptionHandler(new CommandLine.IExecutionExceptionHandler() {
public int handleExecutionException(Exception ex, CommandLine exCmdLine, ParseResult parseResult) throws Exception {
handled[0] = true;
assertSame(commandLine, exCmdLine);

ParseResult after = commandLine.getParseResult();
printParseResult(after, "commandLine.getParseResult()");
assertFalse(after.matchedArgs().isEmpty());
assertFalse(after.matchedOptions().isEmpty());

printParseResult(parseResult, "ExecutionExceptionHandler method arg");
assertNotNull(parseResult);
caughtParseResult[0] = parseResult;
assertFalse(parseResult.matchedArgs().isEmpty());
assertFalse(parseResult.matchedOptions().isEmpty());
return 0;
}
});
commandLine.execute("-x");
assertNotNull(caughtParseResult[0]);

ParseResult after = commandLine.getParseResult();
assertFalse(after.matchedArgs().isEmpty());
assertFalse(after.matchedOptions().isEmpty());
assertTrue("ExecutionExceptionHandler tests were executed", handled[0]);
}

assertFalse(caughtParseResult[0].matchedArgs().isEmpty());
assertFalse(caughtParseResult[0].matchedOptions().isEmpty());
private static void printParseResult(ParseResult parseResult, String origin) {
System.out.println("\tParseResult from " + origin + ": " + parseResult);
System.out.println("\t\tmatchedArgs(): " + parseResult.matchedArgs());
System.out.println("\t\tmatchedOptions(): " + parseResult.matchedOptions());
}
}

0 comments on commit a6053da

Please # to comment.