3 # Test scoping issues with embedded code in regexps.
9 skip_all_if_miniperl("no dynamic loading on miniperl, no re");
14 # Functions for turning to-do-ness on and off (as there are so many
16 sub on { $::TODO = "(?{}) implementation is screwy" }
17 sub off { undef $::TODO }
20 fresh_perl_is <<'CODE', '781745', {}, '(?{}) has its own lexical scope';
21 my $x = 7; my $a = 4; my $b = 5;
22 print "a" =~ /(?{ print $x; my $x = 8; print $x; my $y })a/;
28 fresh_perl_is <<'CODE',
35 a (?{ print $y; local $y = $y+1; print $x; my $x = 8; print $x })
36 b (?{ print $y; local $y = $y+1; print $x; my $x = 9; print $x })
37 c (?{ print $y; local $y = $y+1; print $x; my $x = 10; print $x })
43 '1a82a93a104a85a96a101a 1b82b93b104b85b96b101b 1c82c93c104c85c96c101c ',
45 'multiple (?{})s in loop with lexicals';
49 fresh_perl_is <<'CODE', '781745', {}, 'run-time re-eval has its own scope';
51 my $x = 7; my $a = 4; my $b = 5;
53 print "a" =~ /(?{ print $x; my $x = 8; print $x; my $y })$rest/;
57 fresh_perl_is <<'CODE', '178279371047857967101745', {},
65 a (?{ print $y; local $y = $y+1; print $x; my $x = 8; print $x })
66 b (?{ print $y; local $y = $y+1; print $x; my $x = 9; print $x })
67 c (?{ print $y; local $y = $y+1; print $x; my $x = 10; print $x })
72 'multiple (?{})s in "foo" =~ $string';
74 fresh_perl_is <<'CODE', '178279371047857967101745', {},
82 a (?{ print $y; local $y = $y+1; print $x; my $x = 8; print $x })
83 b (?{ print $y; local $y = $y+1; print $x; my $x = 9; print $x })
84 c (?{ print $y; local $y = $y+1; print $x; my $x = 10; print $x })
89 'multiple (?{})s in "foo" =~ /$string/x';
93 fresh_perl_is <<'CODE', '123123', {},
95 push @regexps = qr/(?{ print $x })a/;
97 "a" =~ $_ for @regexps;
98 "ba" =~ /b$_/ for @regexps;
100 'qr/(?{})/ is a closure';
104 "a" =~ do { package foo; qr/(?{ $::pack = __PACKAGE__ })a/ };
105 is $pack, 'foo', 'qr// inherits package';
106 "a" =~ do { use re "/x"; qr/(?{ $::re = qr-- })a/ };
107 is $re, '(?^x:)', 'qr// inherits pragmata';
111 "ba" =~ /b${\do { package baz; qr|(?{ $::pack = __PACKAGE__ })a| }}/;
112 is $pack, 'baz', '/text$qr/ inherits package';
113 "ba" =~ m+b${\do { use re "/i"; qr|(?{ $::re = qr-- })a| }}+;
114 is $re, '(?^i:)', '/text$qr/ inherits pragmata';
120 "ba" =~ /${\'(?{ $::pack = __PACKAGE__ })a'}/;
122 is $pack, 'bar', '/$text/ containing (?{}) inherits package';
125 "ba" =~ /${\'(?{ $::re = qr -- })a'}/;
127 is $re, '(?^m:)', '/$text/ containing (?{}) inherits pragmata';
131 fresh_perl_is <<'CODE', '45', { stderr => 1 }, '(?{die})';
132 eval { my $a=4; my $b=5; "a" =~ /(?{die})a/ }; print $a,$b"
136 # The remaining TODO tests crash, which will display an error dialog
137 # on Windows that has to be manually dismissed. We don't want this
138 # to happen for release builds: 5.14.x, 5.16.x etc.
139 # On UNIX, they produce ugly 'Aborted' shell output mixed in with the
140 # test harness output, so skip on all platforms.
141 skip "Don't run crashing TODO test on release build", 3
142 if $::TODO && (int($]*1000) & 1) == 0;
144 fresh_perl_is <<'CODE', '45', { stderr => 1 }, '(?{last})';
145 { my $a=4; my $b=5; "a" =~ /(?{last})a/ }; print $a,$b
147 fresh_perl_is <<'CODE', '45', { stderr => 1 }, '(?{next})';
148 { my $a=4; my $b=5; "a" =~ /(?{last})a/ }; print $a,$b
150 fresh_perl_is <<'CODE', '45', { stderr => 1 }, '(?{return})';
151 print sub { my $a=4; my $b=5; "a" =~ /(?{return $a.$b})a/ }->();
155 fresh_perl_is <<'CODE', '45', { stderr => 1 }, '(?{goto})';
156 my $a=4; my $b=5; "a" =~ /(?{goto _})a/; die; _: print $a,$b