File: 011_process_argv.t

package info (click to toggle)
libmoosex-getopt-perl 0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 356 kB
  • sloc: perl: 1,964; makefile: 8
file content (63 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Fatal 0.003;

if ( !eval { require Test::Deep } )
{
    plan skip_all => 'Test requires Test::Deep';
    exit;
}
else
{
    plan tests => 6;
}

{
    package Testing::Foo;
    use Moose;

    with 'MooseX::Getopt';

    has 'bar' => (
        is       => 'ro',
        isa      => 'Int',
        required => 1,
    );

    has 'baz' => (
        is       => 'ro',
        isa      => 'Int',
        required => 1,
    );
}

@ARGV = qw(--bar 10 file.dat);

my $pa;
is(
    exception {
        $pa = Testing::Foo->process_argv(baz => 100);
    },
    undef,
    '... this should work'
);
isa_ok($pa, 'MooseX::Getopt::ProcessedArgv');

Test::Deep::cmp_deeply($pa->argv_copy, [
    '--bar',
    '10',
    'file.dat'
], 'argv_copy');
Test::Deep::cmp_deeply($pa->cli_params, {
    'bar' => 10
}, 'cli_params');
Test::Deep::cmp_deeply($pa->constructor_params, {
    'baz' => 100
}, 'constructor_params');
Test::Deep::cmp_deeply($pa->extra_argv, [
    'file.dat'
], 'extra_argv');