File: 06-options.t

package info (click to toggle)
libparams-validate-perl 0.76-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 316 kB
  • ctags: 214
  • sloc: perl: 2,230; makefile: 36
file content (50 lines) | stat: -rw-r--r-- 815 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

use strict;

BEGIN
{
    $ENV{PERL_NO_VALIDATION} = 0;
    require Params::Validate;
    Params::Validate->import(':all');
}

use Test;
plan test => $] == 5.006 ? 3 : 7;

Params::Validate::validation_options( stack_skip => 2 );

sub foo
{
    my %p = validate(@_, { bar => 1 });
}

sub bar { foo(@_) }

sub baz { bar(@_) }

eval { baz() };

ok( $@ );
ok( $@ =~ /mandatory.*missing.*call to main::bar/i );

Params::Validate::validation_options( stack_skip => 3 );

eval { baz() };

ok( $@ );

unless ( $] == 5.006 )
{
    ok( $@ =~ /mandatory.*missing.*call to main::baz/i );

    Params::Validate::validation_options
        ( on_fail => sub { die bless { hash => 'ref' }, 'Dead' } );

    eval { baz() };

    ok( $@ );
    ok( $@->{hash} eq 'ref' );
    ok( UNIVERSAL::isa( $@, 'Dead' ) );
}