diff --git a/lib/Rex/CLI.pm b/lib/Rex/CLI.pm index f80cfb348..d2e8824af 100644 --- a/lib/Rex/CLI.pm +++ b/lib/Rex/CLI.pm @@ -761,6 +761,7 @@ sub load_rexfile { if (@warnings) { Rex::Logger::info( "You have some code warnings:", 'warn' ); for (@warnings) { + # remove /loader/.../ prefix before filename s|/loader/[^/]+/||; Rex::Logger::info( "\t$_", 'warn' ); diff --git a/t/load_rexfile.t b/t/load_rexfile.t index daf3d9b52..37e52d20d 100644 --- a/t/load_rexfile.t +++ b/t/load_rexfile.t @@ -9,14 +9,15 @@ use File::Spec; use Rex::CLI; #diag 'create some rexfiles to test...'; -my $fh = undef; -my $testdir = File::Temp->newdir('rextest.XXXX', TMPDIR => 1, CLEANUP => 1); +my $fh = undef; +my $testdir = File::Temp->newdir( 'rextest.XXXX', TMPDIR => 1, CLEANUP => 1 ); while () { last if /^__END__$/; if (/^@@ *(\S+)$/) { + #diag "prepare file $1"; close($fh) if $fh; - open($fh, '>', File::Spec->catfile($testdir, $1)) or die $!; + open( $fh, '>', File::Spec->catfile( $testdir, $1 ) ) or die $!; next; } print $fh $_ if $fh; @@ -36,78 +37,113 @@ use warnings 'redefine'; $::QUIET = 1; #$Rex::Logger::no_color = 1; -my $logfile = File::Spec->catfile($testdir, 'log'); +my $logfile = File::Spec->catfile( $testdir, 'log' ); Rex::Config->set_log_filename($logfile); - # NOW TEST # No Rexfile warning (via Rex::Logger) -Rex::CLI::load_rexfile(File::Spec->catfile($testdir, 'no_Rexfile')); +Rex::CLI::load_rexfile( File::Spec->catfile( $testdir, 'no_Rexfile' ) ); my $content = _get_log(); -like($content, qr/WARN - No Rexfile found/, 'No Rexfile warning (via logger)'); +like( $content, qr/WARN - No Rexfile found/, + 'No Rexfile warning (via logger)' ); # Valid Rexfile _reset_test(); output_like { - Rex::CLI::load_rexfile(File::Spec->catfile($testdir, 'Rexfile_noerror')); -} qr/^$/, qr/^$/, 'No stdout/stderr messages on valid Rexfile'; + Rex::CLI::load_rexfile( File::Spec->catfile( $testdir, 'Rexfile_noerror' ) ); +} +qr/^$/, qr/^$/, 'No stdout/stderr messages on valid Rexfile'; $content = _get_log(); -is($content, '', 'No warnings on valid Rexfile (via logger)'); +is( $content, '', 'No warnings on valid Rexfile (via logger)' ); # Rexfile with warnings _reset_test(); output_like { - Rex::CLI::load_rexfile(File::Spec->catfile($testdir, 'Rexfile_warnings')); -} qr/^$/, qr/^$/, 'No stdout/stderr messages on Rexfile with warnings'; + Rex::CLI::load_rexfile( File::Spec->catfile( $testdir, 'Rexfile_warnings' ) ); +} +qr/^$/, qr/^$/, 'No stdout/stderr messages on Rexfile with warnings'; $content = _get_log(); -ok(!$exit_was_called, 'sub load_rexfile() not exit'); -like($content, qr/WARN - You have some code warnings/, 'Code warnings via logger'); -like($content, qr/This is warning/, 'warn() warning via logger'); -like($content, qr/Use of uninitialized value \$undef/, 'perl warning via logger'); -unlike($content, qr#at /loader/0x#, 'loader prefix is filtered in warnings report'); +ok( !$exit_was_called, 'sub load_rexfile() not exit' ); +like( + $content, + qr/WARN - You have some code warnings/, + 'Code warnings via logger' +); +like( $content, qr/This is warning/, 'warn() warning via logger' ); +like( + $content, + qr/Use of uninitialized value \$undef/, + 'perl warning via logger' +); +unlike( + $content, + qr#at /loader/0x#, + 'loader prefix is filtered in warnings report' +); # Rexfile with fatal errors _reset_test(); output_like { - Rex::CLI::load_rexfile(File::Spec->catfile($testdir, 'Rexfile_fatal')); -} qr/^$/, qr/^$/, 'No stdout/stderr messages on Rexfile with errors'; + Rex::CLI::load_rexfile( File::Spec->catfile( $testdir, 'Rexfile_fatal' ) ); +} +qr/^$/, qr/^$/, 'No stdout/stderr messages on Rexfile with errors'; $content = _get_log(); -ok($exit_was_called, 'sub load_rexfile() aborts'); -like($content, qr/ERROR - Compile time errors/, 'Fatal errors via logger'); -like($content, qr/syntax error at/, 'syntax error is fatal error via logger'); -unlike($content, qr#at /loader/0x#, 'loader prefix is filtered in errors report'); +ok( $exit_was_called, 'sub load_rexfile() aborts' ); +like( $content, qr/ERROR - Compile time errors/, 'Fatal errors via logger' ); +like( $content, qr/syntax error at/, 'syntax error is fatal error via logger' ); +unlike( + $content, + qr#at /loader/0x#, + 'loader prefix is filtered in errors report' +); # Now print messages to STDERR/STDOUT # Valid Rexfile _reset_test(); output_like { - Rex::CLI::load_rexfile(File::Spec->catfile($testdir, 'Rexfile_noerror_print')); -} qr/^This is STDOUT message$/, qr/^This is STDERR message$/, 'Correct stdout/stderr messages printed from valid Rexfile'; + Rex::CLI::load_rexfile( + File::Spec->catfile( $testdir, 'Rexfile_noerror_print' ) ); +} +qr/^This is STDOUT message$/, qr/^This is STDERR message$/, + 'Correct stdout/stderr messages printed from valid Rexfile'; $content = _get_log(); -is($content, '', 'No warnings via logger on valid Rexfile that print messages'); +is( $content, '', + 'No warnings via logger on valid Rexfile that print messages' ); # Rexfile with warnings _reset_test(); output_like { - Rex::CLI::load_rexfile(File::Spec->catfile($testdir, 'Rexfile_warnings_print')); -} qr/^This is STDOUT message$/, qr/^This is STDERR message$/, 'Correct stdout/stderr messages printed from Rexfile with warnings'; + Rex::CLI::load_rexfile( + File::Spec->catfile( $testdir, 'Rexfile_warnings_print' ) ); +} +qr/^This is STDOUT message$/, qr/^This is STDERR message$/, + 'Correct stdout/stderr messages printed from Rexfile with warnings'; $content = _get_log(); -like($content, qr/WARN - You have some code warnings/, 'Code warnings exist via logger'); +like( + $content, + qr/WARN - You have some code warnings/, + 'Code warnings exist via logger' +); # Rexfile with fatal errors _reset_test(); output_like { - Rex::CLI::load_rexfile(File::Spec->catfile($testdir, 'Rexfile_fatal_print')); -} qr/^$/, qr/^$/, 'No stdout/stderr messages printed from Rexfile that has errors'; + Rex::CLI::load_rexfile( + File::Spec->catfile( $testdir, 'Rexfile_fatal_print' ) ); +} +qr/^$/, qr/^$/, + 'No stdout/stderr messages printed from Rexfile that has errors'; $content = _get_log(); -ok($exit_was_called, 'sub load_rexfile() aborts'); -like($content, qr/ERROR - Compile time errors/, 'Fatal errors exist via logger'); - +ok( $exit_was_called, 'sub load_rexfile() aborts' ); +like( + $content, + qr/ERROR - Compile time errors/, + 'Fatal errors exist via logger' +); done_testing; - # from logger.t sub _get_log { local $/; @@ -121,9 +157,11 @@ sub _get_log { sub _reset_test { $exit_was_called = undef; + # reset log open my $fh, '>', $logfile or die $!; close $fh; + # reset require delete $INC{'__Rexfile__.pm'}; }