This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
re-fix leak in Devel-PPPort
[perl5.git] / t / op / die_keeperr.t
CommitLineData
7ce09284
Z
1#!perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
1ae3d757 5 require './test.pl';
7ce09284
Z
6}
7
624c42e2
N
8plan(24);
9
7ce09284
Z
10sub End::DESTROY { $_[0]->() }
11
12sub end(&) {
13 my($c) = @_;
14 return bless(sub { $c->() }, "End");
15}
16
17foreach my $inx ("", "aabbcc\n", [qw(aa bb cc)]) {
18 foreach my $outx ("", "xxyyzz\n", [qw(xx yy zz)]) {
19 my $warn = "";
20 local $SIG{__WARN__} = sub { $warn .= $_[0] };
21 {
22 $@ = $outx;
23 my $e = end { die $inx if $inx };
24 }
25 ok ref($@) eq ref($outx) && $@ eq $outx;
26 $warn =~ s/ at [^\n]*\n\z//;
27 is $warn, $inx ? "\t(in cleanup) $inx" : "";
28 }
29}
30
31{
32 no warnings "misc";
33 my $warn = "";
34 local $SIG{__WARN__} = sub { $warn .= $_[0] };
fc941f37 35 { my $e = end { no warnings "misc"; die "aa\n"; }; }
7ce09284
Z
36 is $warn, "";
37}
38
39{
fc941f37
Z
40 no warnings "misc";
41 my $warn = "";
42 local $SIG{__WARN__} = sub { $warn .= $_[0] };
43 { my $e = end { use warnings "misc"; die "aa\n"; }; }
44 is $warn, "\t(in cleanup) aa\n";
45}
46
47{
7ce09284
Z
48 my $warn = "";
49 local $SIG{__WARN__} = sub { $warn .= $_[0] };
50 { my $e = end { no warnings "misc"; die "aa\n"; }; }
fc941f37
Z
51 is $warn, "";
52}
53
54{
55 my $warn = "";
56 local $SIG{__WARN__} = sub { $warn .= $_[0] };
57 { my $e = end { use warnings "misc"; die "aa\n"; }; }
58 is $warn, "\t(in cleanup) aa\n";
59}
60
61{
62 use warnings "misc";
63 my $warn = "";
64 local $SIG{__WARN__} = sub { $warn .= $_[0] };
65 { my $e = end { no warnings "misc"; die "aa\n"; }; }
66 is $warn, "";
67}
68
69{
70 use warnings "misc";
71 my $warn = "";
72 local $SIG{__WARN__} = sub { $warn .= $_[0] };
73 { my $e = end { use warnings "misc"; die "aa\n"; }; }
7ce09284
Z
74 is $warn, "\t(in cleanup) aa\n";
75}
76
771;