Skip to content

Commit

Permalink
Merge pull request #1563 from RexOps/rexfile_path
Browse files Browse the repository at this point in the history
Expect original Rexfile path in messages
  • Loading branch information
ferki committed Jan 29, 2023
2 parents 1b4db2b + 0aef1e7 commit 61b60ef
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Revision history for Rex
- Correct example for file_read command

[ENHANCEMENTS]
- Show Rexfile path in loading messages

[MAJOR]

Expand Down
22 changes: 10 additions & 12 deletions lib/Rex/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,9 @@ sub load_rexfile {
for (@warnings) {
chomp;

# remove /loader/.../ prefix before filename
s{/loader/[^/]+/}{}sxm;
my $message = _tidy_loading_message( $_, $rexfile );

# convert Rexfile to human-friendly name
s{__Rexfile__.pm}{Rexfile}msx;

Rex::Logger::info( "\t$_", 'warn' );
Rex::Logger::info( "\t$message", 'warn' );
}
}

Expand All @@ -780,12 +776,7 @@ sub load_rexfile {
my $e = $@;
chomp $e;

# remove the strange path to the Rexfile which exists because
# we load the Rexfile via our custom code block.
$e =~ s|/loader/[^/]+/||smg;

# convert Rexfile to human-friendly name
$e =~ s{__Rexfile__.pm}{Rexfile}msx;
$e = _tidy_loading_message( $e, $rexfile );

my @lines = split( $/, $e );

Expand All @@ -796,6 +787,13 @@ sub load_rexfile {
}
}

sub _tidy_loading_message {
my ( $message, $rexfile ) = @_;

$message =~ s{/loader/[^/]+/__Rexfile__[.]pm}{$rexfile}gmsx;
return $message;
}

sub exit_rex {
my ( $exit_code_override, $signal ) = @_;

Expand Down
1 change: 1 addition & 0 deletions t/load_rexfile.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ sub _setup_test {

$expected->{$extension} = -r $file ? cat($file) : $default_content;
$expected->{$extension} =~ s{%REX_CLI_PATH%}{$rex_cli_path}msx;
$expected->{$extension} =~ s{%REXFILE_PATH%}{$rexfile}gmsx;
}

# reset log
Expand Down
2 changes: 1 addition & 1 deletion t/rexfiles/Rexfile_fatal.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ERROR - Compile time errors:
ERROR - syntax error at Rexfile line 5, near "abc
ERROR - syntax error at %REXFILE_PATH% line 5, near "abc
ERROR -
ERROR - task "
ERROR - Compilation failed in require at %REX_CLI_PATH% line 756.
2 changes: 1 addition & 1 deletion t/rexfiles/Rexfile_fatal_print.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ERROR - Compile time errors:
ERROR - syntax error at Rexfile line 8, near "abc
ERROR - syntax error at %REXFILE_PATH% line 8, near "abc
ERROR -
ERROR - print"
ERROR - Compilation failed in require at %REX_CLI_PATH% line 756.
4 changes: 2 additions & 2 deletions t/rexfiles/Rexfile_warnings.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
WARN - You have some code warnings:
WARN - This is warning at Rexfile line 5.
WARN - Use of uninitialized value in concatenation (.) or string at Rexfile line 6.
WARN - This is warning at %REXFILE_PATH% line 5.
WARN - Use of uninitialized value in concatenation (.) or string at %REXFILE_PATH% line 6.
4 changes: 2 additions & 2 deletions t/rexfiles/Rexfile_warnings_print.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
WARN - You have some code warnings:
WARN - This is warning at Rexfile line 5.
WARN - Use of uninitialized value in concatenation (.) or string at Rexfile line 6.
WARN - This is warning at %REXFILE_PATH% line 5.
WARN - Use of uninitialized value in concatenation (.) or string at %REXFILE_PATH% line 6.
4 changes: 2 additions & 2 deletions t/rexfiles/Rexfile_warnings_print.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is STDERR message
WARN - You have some code warnings:
WARN - This is warning at Rexfile line 5.
WARN - Use of uninitialized value in concatenation (.) or string at Rexfile line 6.
WARN - This is warning at %REXFILE_PATH% line 5.
WARN - Use of uninitialized value in concatenation (.) or string at %REXFILE_PATH% line 6.

0 comments on commit 61b60ef

Please sign in to comment.