Skip to content

Commit

Permalink
Use croak in OpenQA::Utils::log_fatal
Browse files Browse the repository at this point in the history
...instead of die.
This way we will get the correct location of the calling method

Issue: https://progress.opensuse.org/issues/57776
  • Loading branch information
perlpunk committed Oct 25, 2019
1 parent 8c3a5ec commit 0e3dad9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/OpenQA/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ sub log_error {
# log_fatal("message"[, param1=>val1, param2=>val2]);
sub log_fatal {
_log_msg('fatal', @_);
die $_[0];
croak $_[0];
}

sub _current_log_level {
Expand Down
4 changes: 3 additions & 1 deletion t/28-logging.t
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,16 @@ subtest 'log fatal to stderr' => sub {
$app->setup_log();
$OpenQA::Utils::app = undef; # To make sure we don't are setting it in other tests
eval { log_fatal('fatal message'); };
my $eval_error = $@;
my $exception_raised = 0;
$exception_raised++ if $@;
$exception_raised++ if $eval_error;
### End of the Testing code ###
# Close the capture (current stdout) and restore STDOUT (by dupping the old STDOUT);
close STDERR;
open(STDERR, '>&', $oldSTDERR) or die "Can't dup \$oldSTDERR: $!";
ok($exception_raised == 1, 'Fatal raised exception');
like($output, qr/\[FATAL\] fatal message/, 'OK fatal');
like($eval_error, qr{fatal message.*t/28-logging.t});

};

Expand Down

0 comments on commit 0e3dad9

Please sign in to comment.