fix tests; make default value for plugins {}
[gitmo/MooseX-Runnable.git] / t / basic.t
CommitLineData
c527660e 1use strict;
2use warnings;
3use Test::Exception;
4use Test::More tests => 8;
5
6use ok 'MooseX::Runnable';
7use ok 'MooseX::Runnable::Invocation';
8
9{ package Class;
10 use Moose;
11 with 'MooseX::Runnable';
12
13 sub run {
14 my ($self, @args) = @_;
15 my $result;
16 $result += $_ for @args;
17 return $result;
18 }
19}
20
21my $invocation = MooseX::Runnable::Invocation->new(
22 class => 'Class',
23);
24
25ok $invocation;
26
27my $code;
28lives_ok {
29 $code = $invocation->run(1,2,3);
30} 'run lived';
31
32is $code, 6, 'run worked';
33
34{ package MooseX::Runnable::Invocation::Plugin::ExitFixer;
35 use Moose::Role;
36
37 around run => sub {
38 my ($next, $self, @args) = @_;
39 my $code = $self->$next(@args);
40 if($code){ return 0 }
41 else { confess "Exited with error." }
42 };
43}
44
45$invocation = MooseX::Runnable::Invocation->new(
46 class => 'Class',
528dfa34 47 plugins => {'+MooseX::Runnable::Invocation::Plugin::ExitFixer' => []},
c527660e 48);
49
50ok $invocation;
51
52lives_ok {
53 $code = $invocation->run(1,2,3);
54} 'run lived';
55
56is $code, 0, 'run worked, and plugin changed the return code';