1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!./perl -w
chdir 't' if -d 't';
require './test.pl';
use strict;
{
package End;
sub DESTROY { $_[0]->() }
sub main::end(&) {
my($cleanup) = @_;
return bless(sub { $cleanup->() }, "End");
}
}
my($val, $err);
$@ = "t0\n";
$val = eval {
$@ = "t1\n";
1;
}; $err = $@;
is($val, 1, "true return value from successful eval block");
is($err, "", "no exception after successful eval block");
$@ = "t0\n";
$val = eval {
$@ = "t1\n";
do {
die "t3\n";
};
1;
}; $err = $@;
is($val, undef, "undefined return value from eval block with 'die'");
is($err, "t3\n", "exception after eval block with 'die'");
$@ = "t0\n";
$val = eval {
$@ = "t1\n";
local $@ = "t2\n";
1;
}; $err = $@;
is($val, 1, "true return value from successful eval block with localized \$@");
is($err, "", "no exception after successful eval block with localized \$@");
$@ = "t0\n";
$val = eval {
$@ = "t1\n";
local $@ = "t2\n";
do {
die "t3\n";
};
1;
}; $err = $@;
is($val, undef,
"undefined return value from eval block with 'die' and localized \$@");
is($err, "t3\n",
"exception after eval block with 'die' and localized \$@");
$@ = "t0\n";
$val = eval {
$@ = "t1\n";
my $c = end { $@ = "t2\n"; };
1;
}; $err = $@;
is($val, 1, "true return value from eval block with 'end'");
is($err, "", "no exception after eval block with 'end'");
$@ = "t0\n";
$val = eval {
$@ = "t1\n";
my $c = end { $@ = "t2\n"; };
do {
die "t3\n";
};
1;
}; $err = $@;
is($val, undef, "undefined return value from eval block with 'end' and 'die'");
is($err, "t3\n", "exception after eval block with 'end' and 'die'");
done_testing();
|