From: Vincent Pit Date: Sun, 5 Oct 2008 22:08:26 +0000 (+0200) Subject: Throughly test App::Rgit::Command::action X-Git-Tag: v0.02~7 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=3a19229d25523e535c5a79343d4a4d80e153e389;p=perl%2Fmodules%2Frgit.git Throughly test App::Rgit::Command::action --- diff --git a/lib/App/Rgit/Command.pm b/lib/App/Rgit/Command.pm index 3754d83..2030414 100644 --- a/lib/App/Rgit/Command.pm +++ b/lib/App/Rgit/Command.pm @@ -70,9 +70,10 @@ Otherwise, returns the current class for C<$cmd>. sub action { my ($self, $cmd, $pkg) = @_; - $cmd = $self->cmd if !defined $cmd - and defined $self and $self->isa(__PACKAGE__); - return unless defined $cmd; + if (not defined $cmd) { + return unless defined $self and ref $self and $self->isa(__PACKAGE__); + $cmd = $self->cmd; + } unless (defined $pkg) { return __PACKAGE__ . '::Each' unless defined $commands{$cmd}; return $commands{$cmd} diff --git a/t/15-failures.t b/t/15-failures.t index 5233267..46d2d32 100644 --- a/t/15-failures.t +++ b/t/15-failures.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 20; +use Test::More tests => 30; use App::Rgit; @@ -56,3 +56,24 @@ like($@, qr!Command\s+dongs\s+should\s+be\s+executed\s+as\s+a\s+App::Rgit::Comma $res = eval { App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version') }; is($@, '', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): does not croak'); isa_ok($res, 'App::Rgit::Test::Foo', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): returns valid object'); + +$res = eval { App::Rgit::Command->action('version') }; +is($@, '', 'App::Rgit::Command->action("version"): does not croak'); +is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action("version"): returns valid object'); + +$res = eval { App::Rgit::Command->new(cmd => 'version')->action() }; +is($@, '', 'App::Rgit::Command->action(): does not croak'); +is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action(): returns valid object'); + +$res = eval { App::Rgit::Command->action() }; +is($@, '', 'App::Rgit::Command->action(): no cmd: does not croak'); +is($res, undef, 'App::Rgit::Command->action(); no cmd: returns undef'); + +$res = eval { App::Rgit::Command::action() }; +is($@, '', 'undef->App::Rgit::Command::action(): no cmd: does not croak'); +is($res, undef, 'undef->App::Rgit::Command::action(); no cmd: returns undef'); + +$res = bless { }, 'App::Rgit::Test::Monkey'; +$res = eval { $res->App::Rgit::Command::action() }; +is($@, '', 'App::Rgit::Test::Monkey->App::Rgit::Command::action(): no cmd: does not croak'); +is($res, undef, 'App::Rgit::Test::Monkey->App::Rgit::Command::action(); no cmd: returns undef');