Skip to content

Commit 97f9e9a

Browse files
committed
Add "TODO" tests related to issue RexOps#1508
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`.
1 parent 9663d7f commit 97f9e9a

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

t/issue/1508.t

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

0 commit comments

Comments
 (0)