X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F15-failures.t;h=3217e23d990080058329012c1fd08fb4932e7754;hb=e24fcce942bbff836770d333a4a919a26872db6d;hp=a25d334d25e7d875fbd2d400f83a0df98a0d4ddf;hpb=059db7acc549028de142c82c375a46a5ad03a026;p=perl%2Fmodules%2Frgit.git diff --git a/t/15-failures.t b/t/15-failures.t index a25d334..3217e23 100644 --- a/t/15-failures.t +++ b/t/15-failures.t @@ -3,15 +3,15 @@ use strict; use warnings; -use Test::More tests => 34; +use Cwd qw/cwd/; +use File::Spec::Functions qw/catdir/; + +use Test::More tests => 42; use App::Rgit; local $SIG{__WARN__} = sub { die @_ }; -eval { App::Rgit->new(qw/foo bar baz/) }; -like($@, qr!Optional\s+arguments\s+must\s+be\s+passed\s+as\s+keys?\s*/\s*values?\s+pairs?!, 'App::Rgit->new(even): croaks'); - my $res = eval { App::Rgit->new() }; is($@, '', 'App::Rgit->new(): no root: does not croak'); is($res, undef, 'App::Rgit->new(): no root: returns undef'); @@ -20,30 +20,26 @@ $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'); }; -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') }; @@ -85,3 +81,39 @@ is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer" => "App::Rgi $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'); + +$res = eval { App::Rgit::Command->new(cmd => 'beer') }; +like($@, qr!Couldn't\s+load\s+App::Rgit::Test::Pub\s*:!, 'App::Rgit::Command->new(cmd => "pub"): croaks'); + +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'); + +use App::Rgit::Repository; + +my $cwd = cwd; +my $t = catdir($cwd, 't'); +chdir $t or die "chdir($t): $!"; + +$res = eval { App::Rgit::Repository->new() }; +is($@, '', 'App::Rgit::Repository->new: no dir: does not croak'); +is($res, undef, 'App::Rgit::Repository->new: no dir: returns undef'); + +$res = eval { App::Rgit::Repository->new(fake => 1) }; +is($@, '', 'App::Rgit::Repository->new: no dir, fake: does not croak'); +isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: no dir, fake: returns a valid object'); + +chdir $cwd or die "chdir($cwd): $!"; + +$res = eval { App::Rgit::Repository->new(dir => 't', fake => 1) }; +is($@, '', 'App::Rgit::Repository->new: relative dir, fake: does not croak'); +isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: relative dir, fake: returns a valid object'); +