X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F15-failures.t;h=19b3995f3169a48a71b272bd4226454e70129e0f;hb=04036d6d8571dbd27c04fa83248577a065b9b761;hp=6b823fe9dc5ae425f816b77d1c19c21b59d43a39;hpb=19bee8f647bfe6c94c5cb3cf6a60d7a43cbca222;p=perl%2Fmodules%2Frgit.git diff --git a/t/15-failures.t b/t/15-failures.t index 6b823fe..19b3995 100644 --- a/t/15-failures.t +++ b/t/15-failures.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 38; use App::Rgit; @@ -20,26 +20,80 @@ $res = eval { App::Rgit->new(root => $0) }; is($@, '', 'App::Rgit->new(): wrong root: does not croak'); is($res, undef, 'App::Rgit->new(): wrong root: returns undef'); -$res = eval { App::Rgit->new(root => 't/repos') }; +$res = eval { App::Rgit->new(root => 't') }; is($@, '', 'App::Rgit->new(): no git: does not croak'); is($res, undef, 'App::Rgit->new(): no git: returns undef'); -$res = eval { App::Rgit->new(root => 't/repos', git => $0) }; +$res = eval { App::Rgit->new(root => 't', git => $0) }; is($@, '', 'App::Rgit->new(): wrong git: does not croak'); is($res, undef, 'App::Rgit->new(): wrong git: returns undef'); -$res = eval { App::Rgit->new(root => 't/repos', git => 't/bin/git') }; +$res = eval { App::Rgit->new(root => 't', git => 't/bin/git') }; is($@, '', 'App::Rgit->new(): no cmd: does not croak'); isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no cmd: returns an object'); -$res = eval { App::Rgit->new(root => 't/repos', git => 't/bin/git', cmd => 'version'); }; +$res = eval { App::Rgit->new(root => 't', git => 't/bin/git', cmd => 'version'); }; is($@, '', 'App::Rgit->new(): no args: does not croak'); isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no args: returns an object'); -$res = eval { $res->new(root => 't/repos', git => 't/bin/git', cmd => 'version'); }; +$res = eval { $res->new(root => 't', git => 't/bin/git', cmd => 'version'); }; is($@, '', '$ar->new(): no args: does not croak'); isa_ok($res, 'App::Rgit', '$ar->new(): no args: returns an object'); -$res = eval { App::Rgit::new(undef, root => 't/repos', git => 't/bin/git', cmd => 'version'); }; +$res = eval { App::Rgit::new(undef, root => 't', git => 't/bin/git', cmd => 'version'); }; is($@, '', 'undef->App::Rgit::new(): no args: does not croak'); isa_ok($res, 'App::Rgit','undef->App::Rgit::new(): no args: returns an object'); + +use App::Rgit::Command; + +eval { App::Rgit::Command::Once->App::Rgit::Command::new(cmd => 'dongs') }; +like($@, qr!Command\s+dongs\s+should\s+be\s+executed\s+as\s+a\s+App::Rgit::Command::Each!, 'App::Rgit::Command::Once->App::Rgit::Command::new(cmd => "dongs"): croaks'); + +{ + no strict 'refs'; + push @{'App::Rgit::Test::Foo::ISA'}, 'App::Rgit::Command::Once'; +} +$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 answer'); + +$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 answer'); + +$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'); + +$res = eval { App::Rgit::Command->action('beer' => 'App::Rgit::Test::Pub') }; +is($@, '', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): does not croak'); +is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): returns valid answer'); + +$res = eval { App::Rgit::Command->action('beer') }; +is($@, '', 'App::Rgit::Command->action("beer"): does not croak'); +is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer"): returns valid answer'); + +use App::Rgit::Config; + +my $arc = App::Rgit::Config->new(root => 't', git => 't/bin/git'); + +$res = eval { $arc->repos }; +is($@, '', '$arc->repos: does not croak'); +is_deeply($res, [ ], '$arc->repos: found nothing'); + +$res = eval { $arc->repos }; +is($@, '', '$arc->repos: does not croak'); +is_deeply($res, [ ], '$arc->repos: cached ok');