This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #93320] localising @DB::args leads to coredump
[perl5.git] / t / op / die_unwind.t
CommitLineData
d7c80187
NC
1#!./perl -w
2
3require './test.pl';
4use strict;
22a30693
Z
5
6#
7# This test checks for $@ being set early during an exceptional
8# unwinding, and that this early setting doesn't affect the late
9# setting used to emit the exception from eval{}. The early setting is
10# a backward-compatibility hack to satisfy modules that were relying on
11# the historical early setting in order to detect exceptional unwinding.
12# This hack should be removed when a proper way to detect exceptional
13# unwinding has been developed.
14#
15
22a30693
Z
16{
17 package End;
18 sub DESTROY { $_[0]->() }
19 sub main::end(&) {
20 my($cleanup) = @_;
21 return bless(sub { $cleanup->() }, "End");
22 }
23}
24
25my($uerr, $val, $err);
26
27$@ = "";
28$val = eval {
29 my $c = end { $uerr = $@; $@ = "t2\n"; };
30 1;
31}; $err = $@;
d7c80187
NC
32is($uerr, "");
33is($val, 1);
34is($err, "");
22a30693
Z
35
36$@ = "t0\n";
37$val = eval {
38 $@ = "t1\n";
39 my $c = end { $uerr = $@; $@ = "t2\n"; };
40 1;
41}; $err = $@;
d7c80187
NC
42is($uerr, "t1\n");
43is($val, 1);
44is($err, "");
22a30693
Z
45
46$@ = "";
47$val = eval {
48 my $c = end { $uerr = $@; $@ = "t2\n"; };
49 do {
50 die "t3\n";
51 };
52 1;
53}; $err = $@;
d7c80187
NC
54is($uerr, "t3\n");
55is($val, undef);
56is($err, "t3\n");
22a30693
Z
57
58$@ = "t0\n";
59$val = eval {
60 $@ = "t1\n";
61 my $c = end { $uerr = $@; $@ = "t2\n"; };
62 do {
63 die "t3\n";
64 };
65 1;
66}; $err = $@;
d7c80187
NC
67is($uerr, "t3\n");
68is($val, undef);
69is($err, "t3\n");
22a30693 70
d7c80187 71done_testing();