Skip to content

Commit 54199bc

Browse files
toddr-botclaude
andcommitted
test: add regression tests for undefined subroutine reporting (issue #1)
Verify that calling an undefined subroutine reports an error even when arguments involve Safe::Hole wrapped calls returning wrapped objects. The original bug (rt#122934) was that $@ was not set in this scenario. Cannot reproduce on current Perl/Safe, but these tests guard against regression. Closes #1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d82da3e commit 54199bc

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

t/01-hole.t

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use strict;
22
use warnings;
3-
use Test::More tests => 33;
3+
use Test::More tests => 37;
44

55
use_ok('Safe::Hole');
66
use Safe;
@@ -145,3 +145,34 @@ is( $safe->reval('%INC = ( FOO => "./FOO.pm" ); &get_inc'), 'FOO ./FOO.pm', '%IN
145145

146146
# To do
147147

148+
###################################
149+
# Regression: undefined subroutines must be reported when parameter
150+
# involves a Safe::Hole wrapped call (GitHub issue #1, rt#122934)
151+
##################################
152+
{
153+
my $safe_i1 = Safe->new;
154+
my $hole_i1 = Safe::Hole->new({});
155+
156+
package SafeHoleTestObj;
157+
sub new { bless {}, shift }
158+
package main;
159+
160+
my $sub_w = sub { return $hole_i1->wrap(SafeHoleTestObj->new) };
161+
$hole_i1->wrap($sub_w, $safe_i1, '&w_test');
162+
163+
$safe_i1->reval(q{sub x_test { return &w_test; } undefined_func(x_test());});
164+
like( $@, qr/Undefined subroutine/, 'undefined sub with wrapped-object arg is reported (issue #1)' );
165+
166+
$@ = '';
167+
$safe_i1->reval(q{undefined_func(&w_test);});
168+
like( $@, qr/Undefined subroutine/, 'undefined sub with direct wrapped call arg is reported' );
169+
170+
$@ = '';
171+
$safe_i1->reval(q{undefined_func(42);});
172+
like( $@, qr/Undefined subroutine/, 'undefined sub with plain arg is reported (baseline)' );
173+
174+
$@ = '';
175+
$safe_i1->reval(q{undefined_func();});
176+
like( $@, qr/Undefined subroutine/, 'undefined sub with no args is reported (baseline)' );
177+
}
178+

0 commit comments

Comments
 (0)