File: return-val.t

package info (click to toggle)
libcgi-compile-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 248 kB
  • sloc: perl: 372; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 869 bytes parent folder | download | duplicates (4)
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
#!perl

use strict;
use warnings;
use Test::More 'no_plan';
use Test::NoWarnings;
use CGI::Compile;

my $SHEBANG  = "#!perl -w\n";
my %VALS     = ('undef' => 0, '"bla"' => 0);
my %NUM_VALS = (0.5 => 0, 1.2 => 1, 2.7 => 3, 0 => 0, 1240 => 216);
my %TESTS;

my $gen_keys = sub {
    my @r;
    foreach my $cmd ('', 'return ', 'exit ') {
        push @r, $SHEBANG . "${cmd}$_[0];\n";
    }
    @r;
};

while (my ($k, $v) = each %VALS) {
    $TESTS{$_} = $v foreach $gen_keys->($k);
}
while (my ($k, $v) = each %NUM_VALS) {
    $TESTS{$_} = $v foreach $gen_keys->($k);
    $TESTS{$_} = $v foreach $gen_keys->(qq|"${k}bla"|);
}

while (my ($k, $v) = each %TESTS) {
    local $@;
    eval {
        is(CGI::Compile->compile(\$k)->(), $v, 'return val from CGI');
    };
    if ($@ && $@ =~ /^exited nonzero: (\d+) /) {
        is($1, $v, 'nonzero exit val from CGI');
    }
}