Commit | Line | Data |
780724cb |
1 | use strict; |
2 | use warnings; |
3 | use Test::Exception; |
19241782 |
4 | use Test::More tests => 9; |
780724cb |
5 | |
6 | use MooseX::Runnable::Invocation; |
7 | use ok 'MooseX::Runnable::Invocation::Scheme::MooseX::Getopt'; |
8 | |
9 | my $foo; |
10 | |
11 | { package Class; |
12 | use Moose; |
13 | with 'MooseX::Runnable', 'MooseX::Getopt'; |
14 | |
15 | has 'foo' => ( |
16 | is => 'ro', |
17 | isa => 'Str', |
18 | required => 1, |
19 | ); |
20 | |
21 | sub run { |
22 | my ($self, $code) = @_; |
23 | $foo = $self->foo; |
24 | return $code; |
25 | } |
26 | } |
27 | |
19241782 |
28 | { package Class2; |
29 | use Moose; |
30 | extends 'Class'; |
31 | } |
32 | |
33 | foreach my $class (qw(Class Class2)) |
34 | { |
35 | my $invocation = MooseX::Runnable::Invocation->new( |
36 | class => $class, |
37 | ); |
780724cb |
38 | |
19241782 |
39 | ok $invocation, 'class is instantiatable'; |
780724cb |
40 | |
19241782 |
41 | my $code; |
42 | lives_ok { |
43 | $code = $invocation->run('--foo', '42', 0); |
44 | } 'run lived'; |
45 | |
46 | is $foo, '42', 'got foo from cmdline'; |
47 | |
48 | is $code, 0, 'exit status ok'; |
49 | } |
780724cb |
50 | |
780724cb |
51 | |