3
use Test::More tests => 13 * 4;
6
my $exit_return_val = sub {
7
return CGI::Compile->new(return_exit_val => 1)->compile(shift)->();
10
my $exit_return_val_global = sub {
12
local $CGI::Compile::RETURN_EXIT_VAL = 1;
13
return CGI::Compile->compile(shift)->();
16
my $throw_exit_val = sub {
17
my $rv = eval { CGI::Compile->compile(shift)->() };
18
ok( (defined($rv) && $rv =~ /^\d+\Z/ && $@ eq '') || (!defined($rv) && $@ =~ /^exited nonzero: (\d+) /) );
19
$rv = $1 if !defined($rv);
23
foreach my $method ($exit_return_val, $exit_return_val_global, $throw_exit_val) {
24
is ($method->(\'0;'), 0, 'fall-through exit 0');
25
is ($method->(\'exit 0;'), 0, 'function exit 0');
26
is ($method->(\'1;'), 1, 'fall-through exit 1');
27
is ($method->(\'2.6;'), 3, 'fall-through float rounded up to int');
28
is ($method->(\'4.4;'), 4, 'fall-through float rounded down to int');
29
is ($method->(\'exit 1;'), 1, 'function exit 1');
30
is ($method->(\'"blah";'), 0, 'fall-through exit string');
31
is ($method->(\'exit "blah";'), 0, 'function exit string');
32
is ($method->(\'"";'), 0, 'fall-through exit empty string');
33
is ($method->(\'exit "";'), 0, 'function exit empty string');
34
is ($method->(\';'), 0, 'fall-through exit undef');
35
is ($method->(\'exit;'), 0, 'function exit implicit undef');
36
is ($method->(\'exit undef;'), 0, 'function exit explicit undef');