a1dda47569a64c3bbd6c0c37898ff7025b7280f9
[gitmo/MooseX-Runnable.git] / t / basic-mx-getopt.t
1 use strict;
2 use warnings;
3 use Test::Exception;
4 use Test::More tests => 9;
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
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     );
38
39     ok $invocation, 'class is instantiatable';
40
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 }
50
51