add friendly error message when giving argless plugins args
[gitmo/MooseX-Runnable.git] / t / invocation-plugin-initargs.t
1 use strict;
2 use warnings;
3 use Test::Exception;
4 use Test::More tests => 6;
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
29 { package Argless;
30   use Moose::Role;
31 }
32
33 my $i;
34 lives_ok {
35     $i = MooseX::Runnable::Invocation->new(
36         class => 'Class',
37         plugins => {
38             '+Plugin' => [qw/foo bar baz/],
39         },
40     );
41 } 'created invocation without dying';
42
43 ok $i, 'created invocation ok';
44 ok $i->run, 'ran ok';
45 is $initargs, 'foo,bar,baz', 'got initargs';
46
47 throws_ok {
48     MooseX::Runnable::Invocation->new(
49         class => 'Class',
50         plugins => {
51             '+Argless' => ['args go here'],
52         },
53     );
54 } qr/Perhaps/, 'argless + args = error';
55
56 lives_ok {
57     MooseX::Runnable::Invocation->new(
58         class => 'Class',
59         plugins => {
60             '+Argless' => [],
61         },
62     );
63 } 'argless + no args = ok';