Commit | Line | Data |
2828ce0c |
1 | use strict; |
2 | use warnings; |
3 | use Test::Exception; |
4fc441ce |
4 | use Test::More tests => 7; |
2828ce0c |
5 | |
6 | use MooseX::Runnable::Invocation; |
7 | |
8 | my $initargs; |
9 | |
10 | { package Class; |
11 | use Moose; |
12 | with 'MooseX::Runnable'; |
13 | sub run { 42 } |
14 | } |
15 | |
16 | { package Plugin; |
17 | use Moose::Role; |
18 | with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs'; |
19 | |
20 | has 'init' => ( is => 'ro', required => 1 ); |
21 | |
22 | sub _build_initargs_from_cmdline { |
23 | my $class = shift; |
24 | $initargs = join ',', @_; |
25 | return { init => 'args' }; |
26 | } |
27 | } |
28 | |
86c248d8 |
29 | { package Argless; |
30 | use Moose::Role; |
31 | } |
32 | |
4fc441ce |
33 | { package Plugin2; |
34 | use Moose::Role; |
35 | with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs'; |
36 | |
37 | sub _build_initargs_from_cmdline { |
38 | return { init => 'fails' }; |
39 | } |
40 | } |
41 | |
2828ce0c |
42 | my $i; |
43 | lives_ok { |
44 | $i = MooseX::Runnable::Invocation->new( |
45 | class => 'Class', |
46 | plugins => { |
47 | '+Plugin' => [qw/foo bar baz/], |
48 | }, |
49 | ); |
50 | } 'created invocation without dying'; |
51 | |
52 | ok $i, 'created invocation ok'; |
53 | ok $i->run, 'ran ok'; |
54 | is $initargs, 'foo,bar,baz', 'got initargs'; |
55 | |
86c248d8 |
56 | throws_ok { |
57 | MooseX::Runnable::Invocation->new( |
58 | class => 'Class', |
59 | plugins => { |
60 | '+Argless' => ['args go here'], |
61 | }, |
62 | ); |
63 | } qr/Perhaps/, 'argless + args = error'; |
2828ce0c |
64 | |
86c248d8 |
65 | lives_ok { |
66 | MooseX::Runnable::Invocation->new( |
67 | class => 'Class', |
68 | plugins => { |
69 | '+Argless' => [], |
70 | }, |
71 | ); |
72 | } 'argless + no args = ok'; |
4fc441ce |
73 | |
74 | lives_ok { |
75 | MooseX::Runnable::Invocation->new( |
76 | class => 'Class', |
77 | plugins => { |
78 | '+Plugin' => [], |
79 | '+Plugin2' => [], |
80 | }, |
81 | ); |
82 | } 'two plugins with args compose OK'; |