Skip to content

Commit

Permalink
Catch errors earlier in Devel-Peek/t/Peek.t
Browse files Browse the repository at this point in the history
Relates: Perl#226

When testing Devel-Peek we can run some tests
inside an eval and do not bother to check if it
succeeds or not.

As STDERR is redirected to a file, we do not even
notice the error message when this occurs.

This commit postpone the redirection of STDERR
and die if the eval quoted string from `do_test` fails.
  • Loading branch information
atoomic committed Aug 27, 2020
1 parent 174fd75 commit e525949
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ext/Devel-Peek/t/Peek.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ sub do_test {
my $pattern = $_[2];
my $do_eval = $_[5];
if (open(OUT,'>', "peek$$")) {
open(STDERR, ">&OUT") or die "Can't dup OUT: $!";
my $setup_stderr = sub { open(STDERR, ">&OUT") or die "Can't dup OUT: $!" };
if ($do_eval) {
my $sub = eval "sub { Dump $_[1] }";
die $@ if $@;
$setup_stderr->();
$sub->();
print STDERR "*****\n";
# second dump to compare with the first to make sure nothing
# changed.
$sub->();
}
else {
$setup_stderr->();
Dump($_[1]);
print STDERR "*****\n";
# second dump to compare with the first to make sure nothing
Expand Down Expand Up @@ -344,6 +347,8 @@ do_test('reference to named subroutine without prototype',
\\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$repeat_todo"
\\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$pattern"
\\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$do_eval"
\\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$setup_stderr"
\\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "&"
\\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$sub"
\\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" flags=0x0 index=0
\\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump"
Expand Down

0 comments on commit e525949

Please sign in to comment.