-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The needs()
function should propogate run-time task arguments (%params
and @args
) from the calling task down to the "needed" tasks
#1508
Comments
…ds() should behave, with regard to propagating args down to needed tasks, once issue RexOps#1508 will be fixed.
…ds() should behave, with regard to propagating args down to needed tasks, once issue RexOps#1508 will be fixed.
The added tests check that the needs() function propagates run-time task arguments (%params and @Args) from the calling task down to the "needed" tasks. CHANGES: ============= new file: t/issue/1508.t HOW TO TEST : ============= $ prove -v t/issue/1508.t # for this issue $ prove t/**/*.t # for non-regression While the related tests remain marked as "TODO", they will not report failures during normal test runs. To see their true pass/fail status, you have to pass the '-v' option to `prove`.
Notice that how params and args were mixed up (interchanged) when being passed down -- within the needs() function. This appears to be a typo, introduced initially by PR RexOps#1157 (the fix for RexOps#1066 ) with 48c737b. CHANGES: ============= modified: lib/Rex/Command.pm HOW TO TEST : ============= $ prove -v t/issue/1508.t # for this issue $ prove t/**/*.t # for non-regression While the related tests remain marked as "TODO", they will not report failures during normal test runs. To see their true pass/fail status, you have to pass the '-v' option to `prove`.
This is an alternative fix which also does some minimal code clean-up as well fixing the culprit (typo). It is proposed in a separate commit to ease cherry-picking. In any case, all tests pass either way. JUSTIFICATION : =============== There does not appear to be any particular reason for having two identical invocations of the ->run method in two separate arms of an `if... elsif...` statement. So this commit replaces them by a -logically equivalent- snippet. FURTHER DETAILS: ================= BTW, digging in repo history, it seems that the two arm `if ... elsif ...` form existed since the very initial introduction of the needs() function by commit 95d3e91. But even at that time (and probably ever since), those two arms of the if statement always did exactly the same thing... So I can't think of any valid reason to keep them around. CHANGES: ============= modified: lib/Rex/Command.pm HOW TO TEST : ============= $ prove -v t/issue/1508.t # for this issue $ prove t/**/*.t # for non-regression
This is made in a separate commit so to ease cherry-picking between two alternative fixes proposed in distinct commits. In any case, all tests pass either way. CHANGES: ============= modified: t/issue/1508.t modified: ChangeLog HOW TO TEST : ============= $ prove -v t/issue/1508.t # for this issue $ prove t/**/*.t # for non-regression
`dzil test -all` was failing on `xt/author/perltidy.t`, apparently not happy with the indentation/tab-stops. CHANGES: ============= modified: t/issue/1508.t HOW TO TEST : ============= ```shell $ prove --lib -v t/issue/1508.t # for this issue $ prove --lib --recursive t/ # for non-regression ```
Hi @ferki, PR (#1509) which fixes this issue (#1508) is ready, but maintainer approval is required to launch CI workflow (for first time contributors to the project, as is the case here). Otherwise, all tests pass locally with Should I just mark th PR as "Ready for Review" so as to get out of the chicken-and-egg situation ? |
needs()
function does not propogate run-time task arguments (%params
and @args
) from the calling task down to the "needed" tasksneeds()
function should propogate run-time task arguments (%params
and @args
) from the calling task down to the "needed" tasks
Thanks for the report, @tabulon! Kudos for the amazing amount of details 👍
Yeah, unfortunately that commit had somehow caused quite some trouble. Hopefully the affected behavior is nicely covered by tests after this one.
Hmm, I don't think parameter and argument passing is explicitly documented for
Yes, I agree that it seems to be a typo, and this aspect of the behavior is untested. Well spotted!
That's an amazing depth of analysis, thanks for going the extra mile by looking at the history! ❤️ I also don't think there's any reason to keep duplicate code. As an aside, I wonder if there's a good way to detect similar duplications? 🤔 Perhaps that's something for the scope of Perl::Critic::TooMuchCode. I'll also re-read the history again, but I think we should be fine as long as we:
|
I've modified the repo settings to be more relaxed about triggering workflows. |
The
needs()
function should propagate run-time task arguments (%params
and@args
) from the calling task down to the "needed" tasksEdits:
As it turns out: this bug is really easy to fix, as it appears to stem from a typo, introduced initially by PR #1157 (the fix for #1066 ) with 48c737b (ultimately merged into master with 7cf0ca4). Some other sharp edges introduced by PR #1157 seem to have already been handled by #1188, but not this one.
I am preparing a PR with accompanying tests.
Describe the bug
The
needs()
function has a bug which prevents it from implicitely propagating the calling task's params/args down to the "needed" tasks when it runs them.How to reproduce it
Steps to reproduce the behavior:
Rexfile
, define two simple tasks (task_a
&task_b
) that dump their run-time arguments (@_
) onSTDERR
task_b
callsneeds("task_a")
rex task_b
(with appropriate host & auth info) and observe the resultsThe dump from
task_a
is empty, whereastask_b
normally displays itsparams
.rex task_b --greetings=Hello
, and observe that the result is similar to the previous trial.Shortest code example that demonstrates the bug:
Rexfile
Run the example from the shell
Execute
rex
within the directory where the aboveRexfile
resides (with appropriate host and authentication switches).Expected behavior
The
needs()
function should implicitly propagate the calling task's params/args down to the "needed" tasks when it runs them, as documented and seemingly intended by the current code base (see notes below).Circumstances
Debug log
Notes
It turns out: this is really easy to fix, as it appears to stem from a typo.
The culprit
Here's the offending portion of code in
Rex::Commands
.Notice how
params
andargs
are mixed up (interchanged) when being passed torun
!! This certainly looks like a typo.The current test suite does not catch the issue. The tests in
needs.t
do not cover propagation of parameters/args.Quick fix
For a fix with minimal changes, just patch the two occurrences of the
$task_o->run
call, within the body of theneeds()
subroutine (inRex::Commands
), as below:Alternative fix (slightly better, imho)
There does not appear to be any particular reason for having two identical invocations of the
->run
method in the above code snippet.So, the offending code can be replaced by the following -logically equivalent- snippet. I will put that in a separate commit; in case there are other (historical?) reasons to keep the two branches of the if statement around.
In any case, all tests pass either way.
Edit: Digging in repo history, it seems that the
if ... elsif ...
form existed since the very initial introduction ofneeds()
by commit 95d3e91, but even at that time (and probably ever since), those two arms of theif
statement always did exactly the same thing... So I can't think of any valid reason to keep them around.The text was updated successfully, but these errors were encountered: