Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid closing over values in string eval when comparing values #1018

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/Test/Builder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -963,13 +963,23 @@ sub cmp_ok {
# over it, which can lead to issues with Devel::Cover
my $bits_code = defined $warning_bits ? qq["\Q$warning_bits\E"] : 'undef';

# This is so that warnings come out at the caller's level
# Make sure warnings and location matches the caller. Can't do the
# comparison directly in the eval, as closing over variables can
# capture them forever when running with Devel::Cover.
my $check;
$succ = eval qq[
BEGIN {\${^WARNING_BITS} = $bits_code};
#line $line "(eval in cmp_ok) $file"
\$test = (\$got $type \$expect);
\$check = sub { \$_[0] $type \$_[1] };
1;
];

if ($succ) {
$succ = eval {
$test = $check->($got, $expect);
1;
};
}
$error = $@;
}
local $Level = $Level + 1;
Expand Down
Loading