Return subcommand execution result in ConsoleLauncher#3322
Merged
marcphilipp merged 2 commits intojunit-team:mainfrom May 27, 2023
Merged
Return subcommand execution result in ConsoleLauncher#3322marcphilipp merged 2 commits intojunit-team:mainfrom
ConsoleLauncher#3322marcphilipp merged 2 commits intojunit-team:mainfrom
Conversation
29b6ddd to
7a0a854
Compare
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 `picocli` 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) ```
7a0a854 to
e3b0824
Compare
sormuras
reviewed
May 25, 2023
| @ParameterizedTest | ||
| @ValueSource(strings = { "-e junit-jupiter -p org.junit.platform.console.subpackage", | ||
| "execute -e junit-jupiter -p org.junit.platform.console.subpackage" }) | ||
| void executeWithoutExcludeClassnameOptionDoesNotExcludeClassesAndMustIncludeAllClassesMatchingTheStandardClassnamePattern( |
Member
There was a problem hiding this comment.
Good candidate for longest method name in this project. ;-)
Contributor
Author
There was a problem hiding this comment.
I had to rotate my screen to read it in full ;)
Member
There was a problem hiding this comment.
Good candidate for longest method name in this project. ;-)
Mmmm.... looks like I'm getting some competition! 😈
marcphilipp
approved these changes
May 27, 2023
null)
Contributor
Author
|
Danke, Marc! |
ConsoleLauncher
Member
|
@rdesgroppes Thank you! 🙂 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
When explicitly specifying the
executesubcommand as advised by:... it happens that
ConsoleLauncher.runreturns aCommandResultwhosegetValuemethod always returnsOptional.empty()instead of the expected (non-empty)Optional<TestExecutionSummary>.It turns out that, when
picocliexecutes a subcommand, it doesn't propagate the return value to the parentCommandLine, whosegetExecutionResultmethod then returnsnull.There was a question about it last year (remkop/picocli#1656) answered by the user manual:
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:
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
[ ] Method preconditions are checked and documented in the method's Javadoc[ ] Public API has Javadoc and@APIannotations[ ] Change is documented in the User Guide and Release Notes