~ubuntu-branches/ubuntu/utopic/libcgi-compile-perl/utopic

« back to all changes in this revision

Viewing changes to t/exit-code.t

  • Committer: Package Import Robot
  • Author(s): gregor herrmann
  • Date: 2014-05-25 14:50:14 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140525145014-f7w6i2usopo3vjib
Tags: 0.17-1
* New upstream release.
* Strip trailing slash from metacpan URLs.
* Drop debian/README.source, the upstream .gitignore is gone.
* debian/copyright: remove stanza about removed inc/Module/*.
* Update years of packaging copyright.
* Declare compliance with Debian Policy 3.9.5.
* Build-Depend on Module::Build::Tiny. Adjust required debhelper version
  accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl
 
2
 
 
3
use Test::More tests => 13 * 4;
 
4
use CGI::Compile;
 
5
 
 
6
my $exit_return_val = sub {
 
7
    return CGI::Compile->new(return_exit_val => 1)->compile(shift)->();
 
8
};
 
9
 
 
10
my $exit_return_val_global = sub {
 
11
    no warnings 'once';
 
12
    local $CGI::Compile::RETURN_EXIT_VAL = 1;
 
13
    return CGI::Compile->compile(shift)->();
 
14
};
 
15
 
 
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);
 
20
    return $rv;
 
21
};
 
22
 
 
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');
 
37
}