You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return subcommand execution result (instead of null)
When explicitly specifying the `execute` subcommand as advised by:
> WARNING: Delegated to the 'execute' command.
> This behaviour has been deprecated and will be removed in a future release.
> Please use the 'execute' command directly.
... it happens that `ConsoleLauncher.run` returns a `CommandResult`
whose `getValue` method always returns `Optional.empty()` instead of the
expected (non-empty) `Optional<TestExecutionSummary>`.
It turns out that, when `picoli` executes a _subcommand_, it doesn't
propagate the return value to the parent `CommandLine`, whose
`getExecutionResult` method then returns `null`.
There was a question about it last year
(remkop/picocli#1656) answered by the [user
manual](https://picocli.info/#_executing_commands_with_subcommands):
> The `ParseResult` can be used to get the return value from a Callable
> or Method subcommand:
> ```java
> // getting return value from Callable or Method command
> Object topResult = cmd.getExecutionResult();
>
> // getting return value from Callable or Method subcommand
> ParseResult parseResult = cmd.getParseResult();
> if (parseResult.subcommand() != null) {
> CommandLine sub = parseResult.subcommand().commandSpec().commandLine();
> Object subResult = sub.getExecutionResult();
> }
```
The present change therefore consists in implementing it.
Note: prior to the change, presently adapted tests (now parameterized so
as to cover both forms) were all failing on:
```java
java.lang.IllegalStateException: TestExecutionSummary not assigned. Exit code is: 0
at app//org.junit.platform.console.ConsoleLauncherWrapperResult.checkTestExecutionSummaryState(ConsoleLauncherWrapperResult.java:42)
at app//org.junit.platform.console.ConsoleLauncherWrapperResult.getTestsFoundCount(ConsoleLauncherWrapperResult.java:102)
```
0 commit comments