File: 113_moosex_strictconstructor.t

package info (click to toggle)
libmoosex-getopt-perl 0.78-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 508 kB
  • sloc: perl: 607; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;

use Test::Needs 'MooseX::StrictConstructor';
use Test::More 0.88;
use Test::Fatal;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';

{
    package Test1;
    use Moose;
    with 'MooseX::Getopt';
    use MooseX::StrictConstructor;

    has att1 => (is => 'ro', isa => 'Str');
};

{
    my $o1;
    is(
        exception { $o1 = Test1->new_with_options(argv => [ '--att1', 'value1' ]); },
        undef,
        'new_with_options + argv on a MooseX::StrictConstructor enabled class',
    );
    cmp_ok($o1->att1, 'eq', 'value1', 'att1 gets initialized correctly');
}


{
    package Test2;
    use Moose;
    with 'MooseX::Getopt';
    use MooseX::StrictConstructor;

    has argv => (is => 'ro');
    has att1 => (is => 'ro', isa => 'Str');
};

{
    my $o2;
    is(
        exception { $o2 = Test2->new_with_options(argv => [ '--att1', 'value1' ]); },
        undef,
        'new_with_options + argv on a MooseX::StrictConstructor enabled class',
    );

    cmp_ok($o2->att1, 'eq', 'value1', 'att1 gets initialized correctly');
    is_deeply($o2->argv, ['--att1', 'value1'], 'attribute argv is correct too');
}

done_testing;