Skip to content

Commit a4b06cc

Browse files
committed
Add TODO tests for issue RexOps#1508 which check and describe how needs() should behave, with regard to propagating args down to needed tasks, once issue RexOps#1508 will be fixed.
1 parent 9663d7f commit a4b06cc

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed
+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
=head1 NAME
2+
3+
issue/1508.needs_arg-propagation.tau.t - Check that the `needs()` function correctly propogates run-time task arguments
4+
5+
=head1 DESCRIPTION
6+
7+
Check that the `needs()` function does indeed correctly propogate
8+
run-time task arguments (%params and @args) from the calling task down to the "needed" tasks.
9+
10+
=head1 DETAILS
11+
12+
* AUTHOR / DATE : [tabulon]@[2021-09-26]
13+
* RELATES-TO : [github issue #1508](https://github.com/RexOps/Rex/issues/1508#issue-1007457392)
14+
* INSPIRED from : t/needs.t
15+
16+
=cut
17+
18+
use Test::More;
19+
use Rex::Commands;
20+
21+
{
22+
package T; # Helper package (for cutting down boilerplate in tests)
23+
use Storable;
24+
25+
sub track_taskrun {
26+
my %opts = ref $_[-1] eq 'HASH' ? %{; pop } : ();
27+
my $argv = $opts{argv};
28+
my @prereqs = (@_);
29+
for (@prereqs) {
30+
my $file = "${_}.txt";
31+
Storable::store($argv, $file);
32+
}
33+
}
34+
sub check_needed {
35+
my %opts = ref $_[-1] eq 'HASH' ? %{; pop } : ();
36+
my $argv = $opts{argv};
37+
my $do_unlink = delete $opts{unlink} // 1;
38+
my @prereqs = (@_);
39+
40+
for (@prereqs) {
41+
my $file = "${_}.txt";
42+
43+
-f "$file" or die;
44+
my $propagated_argv = Storable::retrieve("$file");
45+
Test::More::_deep_check($propagated_argv, $argv) or die;
46+
47+
unlink("$file") if ($do_unlink);
48+
}
49+
}
50+
}
51+
52+
53+
{
54+
55+
package MyTest;
56+
use strict;
57+
use warnings;
58+
use Rex::Commands;
59+
60+
$::QUIET = 1;
61+
62+
task test1 => sub {
63+
T::track_taskrun(test1 => {argv => \@_});
64+
};
65+
66+
task test2 => sub {
67+
T::track_taskrun(test2 => {argv => \@_});
68+
};
69+
70+
1;
71+
}
72+
73+
{
74+
75+
package Nested::Module;
76+
77+
use strict;
78+
use warnings;
79+
80+
use Rex::Commands;
81+
82+
task test => sub {
83+
T::track_taskrun(test => {argv => \@_});
84+
};
85+
}
86+
87+
{
88+
89+
package Rex::Module;
90+
91+
use strict;
92+
use warnings;
93+
94+
use Rex::Commands;
95+
96+
task test => sub {
97+
T::track_taskrun(test => {argv => \@_});
98+
};
99+
}
100+
101+
task test => sub {
102+
needs MyTest;
103+
104+
T::check_needed($_, {argv => \@_}) for (qw/test1 test2/);
105+
};
106+
107+
task test2 => sub {
108+
needs MyTest "test2";
109+
110+
T::check_needed($_, {argv => \@_}) for (qw/test2/);
111+
};
112+
113+
task test3 => sub {
114+
needs "test4";
115+
116+
T::check_needed($_, {argv => \@_}) for (qw/test4/);
117+
};
118+
119+
task test4 => sub {
120+
T::track_taskrun(test4 => {argv => \@_});
121+
};
122+
123+
task test5 => sub {
124+
needs Nested::Module test;
125+
126+
T::check_needed($_, {argv => \@_}) for (qw/test/);
127+
};
128+
129+
130+
task test6 => sub {
131+
needs Rex::Module "test";
132+
133+
T::check_needed($_, {argv => \@_}) for (qw/test /);
134+
};
135+
136+
137+
TODO: {
138+
local $TODO = "Fix #1508: needs() should propogate current task parameters/args";
139+
140+
my $task_list = Rex::TaskList->create;
141+
my $run_list = Rex::RunList->instance;
142+
$run_list->parse_opts(qw/test test2 test3 test5 test6/);
143+
144+
145+
for my $task ( $run_list->tasks ) {
146+
my $name=$task->name;
147+
my %prms=("${name}_greet" => "Hello ${name}");
148+
my @args=("${name}.arg.0", "${name}.arg.1", "${name}.arg.2");
149+
150+
$task_list->run($task);
151+
152+
my @summary = $task_list->get_summary;
153+
is_deeply $summary[-1]->{exit_code}, 0, $task->name;
154+
$run_list->increment_current_index;
155+
}
156+
}
157+
158+
159+
done_testing;

0 commit comments

Comments
 (0)