This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deprecate above \xFF in bitwise string ops
[perl5.git] / t / op / die_keeperr.t
1 #!perl -w
2
3 BEGIN {
4     chdir 't' if -d 't';
5     require './test.pl';
6 }
7
8 plan(24);
9
10 sub End::DESTROY { $_[0]->() }
11
12 sub end(&) {
13     my($c) = @_;
14     return bless(sub { $c->() }, "End");
15 }
16
17 foreach 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] };
35     { my $e = end { no warnings "misc"; die "aa\n"; }; }
36     is $warn, "";
37 }
38
39 {
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 {
48     my $warn = "";
49     local $SIG{__WARN__} = sub { $warn .= $_[0] };
50     { my $e = end { no warnings "misc"; die "aa\n"; }; }
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"; }; }
74     is $warn, "\t(in cleanup) aa\n";
75 }
76
77 1;