5 # Tests bug #22977. Test case from Dave Mitchell.
19 # A bug caused by the fix for #22977/50528
22 # Fill the pad with alphabet soup, to give the closed-over variable a
23 # high padoffset (more likely to trigger the bug and crash).
24 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
25 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
26 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
27 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
28 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
29 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
30 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
31 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
32 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
33 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
34 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
35 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
36 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
37 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
38 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
39 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
40 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
41 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
45 "ok 3".$x # $x is not available, but this should not crash
49 *STDOUT = *STDOUT2{FORMAT};
53 # A regression introduced in 5.10; format cloning would close over the
54 # variables in the currently-running sub (the main CV in this test) if the
55 # outer sub were an inactive closure.
60 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t)}
63 @<<<<<<<<<<<<<<<<<<<<<<<<<
64 defined $x ? "not ok 4 - $x" : "ok 4"
68 *STDOUT = *STDOUT3{FORMAT};
72 local $SIG{__WARN__} = sub { $w = shift };
74 print "not " unless $w =~ /^Variable "\$x" is not available at/;
75 print "ok 5 - closure var not available when outer sub is inactive\n";
78 # Formats inside closures should close over the topmost clone of the outer
79 # sub on the call stack.
80 # Tests will be out of sequence if the wrong sub is used.
84 shift == 0 and &$next(1), return;
90 sub { write }->(); # separate sub, so as not to rely on it being the
91 } # currently-running sub
93 *STDOUT = *STDOUT4{FORMAT};
94 $clo1 = make_closure 6;
95 $clo2 = make_closure 7;
101 # Cloning a format whose outside has been undefined
103 {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t,$u)}
106 @<<<<<<<<<<<<<<<<<<<<<<<<<
107 defined $z ? "not ok 8 - $z" : "ok 8"
111 *STDOUT = *STDOUT6{FORMAT};
115 local $SIG{__WARN__} = sub { $w = shift };
117 print "not " unless $w =~ /^Variable "\$z" is not available at/;
118 print "ok 9 - closure var not available when outer sub is undefined\n";
122 @<<<<<<<<<<<<<<<<<<<<<<<<<<<
123 do { my $x = "ok 10 - closure inside format"; sub { $x }->() }
125 *STDOUT = *STDOUT7{FORMAT};
130 @<<<< - recursive formats
131 do { my $t = "ok " . $testn--; write if $t =~ 12; $t}
133 *STDOUT = *STDOUT8{FORMAT};
139 @* - formats closing over redefined subs (got @*)
140 ref \$x eq 'SCALAR' ? "ok 13" : "not ok 13", ref \$x;
144 eval 'sub _13 { my @x; write }';
145 *STDOUT = *STDOUT13{FORMAT};
148 # This is a variation of bug #22977, which crashes or fails an assertion
150 # Keep this test last if you want test numbers to be sane.
154 *STDOUT = *STDOUT5{FORMAT};