From e7ad26bc85bcdb07dfb33ac433e3e2cda2cbfb82 Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Wed, 17 Jan 2018 08:05:12 +0100 Subject: [PATCH 1/2] Add test for using needs with nested modules (ref #1188) --- t/needs.t | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/t/needs.t b/t/needs.t index c720119a8..0518ba689 100644 --- a/t/needs.t +++ b/t/needs.t @@ -23,6 +23,34 @@ use Rex::Commands; 1; } +{ + package Nested::Module; + + use strict; + use warnings; + + use Rex::Commands; + + task "test", sub { + open( my $fh, ">", "test.txt" ); + close($fh); + }; +} + +{ + package Rex::Module; + + use strict; + use warnings; + + use Rex::Commands; + + task "test", sub { + open( my $fh, ">", "test.txt" ); + close($fh); + }; +} + task "test", sub { needs MyTest; @@ -62,9 +90,31 @@ task "test4", sub { close($fh); }; +task "test5", sub { + needs Nested::Module "test"; + + if ( -f "test.txt" ) { + unlink("test.txt"); + return 1; + } + + die; +}; + +task "test6", sub { + needs Rex::Module "test"; + + if ( -f "test.txt" ) { + unlink("test.txt"); + return 1; + } + + die; +}; + my $task_list = Rex::TaskList->create; my $run_list = Rex::RunList->instance; -$run_list->parse_opts(qw/test test2 test3/); +$run_list->parse_opts(qw/test test2 test3 test5 test6/); for my $task ( $run_list->tasks ) { $task_list->run($task); From 88949fd30903bbd4454bc0c9e747016acc0ff6db Mon Sep 17 00:00:00 2001 From: Ferenc Erki Date: Mon, 15 Jan 2018 06:48:17 +0100 Subject: [PATCH 2/2] Convert namespace separators from module to task (fix #1188) --- lib/Rex/Commands.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Rex/Commands.pm b/lib/Rex/Commands.pm index 256b32f0c..e9192139d 100644 --- a/lib/Rex/Commands.pm +++ b/lib/Rex/Commands.pm @@ -1035,6 +1035,9 @@ sub needs { Rex::Logger::debug("need to call tasks from $self"); + $self =~ s/^Rex:://g; + $self =~ s/::/:/g; + my @tasks_to_run; if($self) { @tasks_to_run = $tl->get_all_tasks(qr{^\Q$self\E:[A-Za-z0-9_\-]+$});