7 use File::Spec::Functions qw/catdir/;
9 use Test::More tests => 44;
13 local $SIG{__WARN__} = sub { die @_ };
15 eval { App::Rgit->new(qw/foo bar baz/) };
16 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');
18 my $res = eval { App::Rgit->new() };
19 is($@, '', 'App::Rgit->new(): no root: does not croak');
20 is($res, undef, 'App::Rgit->new(): no root: returns undef');
22 $res = eval { App::Rgit->new(root => $0) };
23 is($@, '', 'App::Rgit->new(): wrong root: does not croak');
24 is($res, undef, 'App::Rgit->new(): wrong root: returns undef');
26 $res = eval { App::Rgit->new(root => 't') };
27 is($@, '', 'App::Rgit->new(): no git: does not croak');
28 is($res, undef, 'App::Rgit->new(): no git: returns undef');
30 $res = eval { App::Rgit->new(root => 't', git => $0) };
31 is($@, '', 'App::Rgit->new(): wrong git: does not croak');
32 is($res, undef, 'App::Rgit->new(): wrong git: returns undef');
34 $res = eval { App::Rgit->new(root => 't', git => 't/bin/git') };
35 is($@, '', 'App::Rgit->new(): no cmd: does not croak');
36 isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no cmd: returns an object');
38 $res = eval { App::Rgit->new(root => 't', git => 't/bin/git', cmd => 'version'); };
39 is($@, '', 'App::Rgit->new(): no args: does not croak');
40 isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no args: returns an object');
42 $res = eval { $res->new(root => 't', git => 't/bin/git', cmd => 'version'); };
43 is($@, '', '$ar->new(): no args: does not croak');
44 isa_ok($res, 'App::Rgit', '$ar->new(): no args: returns an object');
46 $res = eval { App::Rgit::new(undef, root => 't', git => 't/bin/git', cmd => 'version'); };
47 is($@, '', 'undef->App::Rgit::new(): no args: does not croak');
48 isa_ok($res, 'App::Rgit','undef->App::Rgit::new(): no args: returns an object');
50 use App::Rgit::Command;
52 eval { App::Rgit::Command::Once->App::Rgit::Command::new(cmd => 'dongs') };
53 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');
57 push @{'App::Rgit::Test::Foo::ISA'}, 'App::Rgit::Command::Once';
59 $res = eval { App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version') };
60 is($@, '', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): does not croak');
61 isa_ok($res, 'App::Rgit::Test::Foo', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): returns valid object');
63 $res = eval { App::Rgit::Command->action('version') };
64 is($@, '', 'App::Rgit::Command->action("version"): does not croak');
65 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action("version"): returns valid answer');
67 $res = eval { App::Rgit::Command->new(cmd => 'version')->action() };
68 is($@, '', 'App::Rgit::Command->action(): does not croak');
69 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action(): returns valid answer');
71 $res = eval { App::Rgit::Command->action() };
72 is($@, '', 'App::Rgit::Command->action(): no cmd: does not croak');
73 is($res, undef, 'App::Rgit::Command->action(); no cmd: returns undef');
75 $res = eval { App::Rgit::Command::action() };
76 is($@, '', 'undef->App::Rgit::Command::action(): no cmd: does not croak');
77 is($res, undef, 'undef->App::Rgit::Command::action(); no cmd: returns undef');
79 $res = bless { }, 'App::Rgit::Test::Monkey';
80 $res = eval { $res->App::Rgit::Command::action() };
81 is($@, '', 'App::Rgit::Test::Monkey->App::Rgit::Command::action(): no cmd: does not croak');
82 is($res, undef, 'App::Rgit::Test::Monkey->App::Rgit::Command::action(); no cmd: returns undef');
84 $res = eval { App::Rgit::Command->action('beer' => 'App::Rgit::Test::Pub') };
85 is($@, '', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): does not croak');
86 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): returns valid answer');
88 $res = eval { App::Rgit::Command->action('beer') };
89 is($@, '', 'App::Rgit::Command->action("beer"): does not croak');
90 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer"): returns valid answer');
92 use App::Rgit::Config;
94 my $arc = App::Rgit::Config->new(root => 't', git => 't/bin/git');
96 $res = eval { $arc->repos };
97 is($@, '', '$arc->repos: does not croak');
98 is_deeply($res, [ ], '$arc->repos: found nothing');
100 $res = eval { $arc->repos };
101 is($@, '', '$arc->repos: does not croak');
102 is_deeply($res, [ ], '$arc->repos: cached ok');
104 use App::Rgit::Repository;
107 my $t = catdir($cwd, 't');
108 chdir $t or die "chdir($t): $!";
110 $res = eval { App::Rgit::Repository->new() };
111 is($@, '', 'App::Rgit::Repository->new: no dir: does not croak');
112 is($res, undef, 'App::Rgit::Repository->new: no dir: returns undef');
114 $res = eval { App::Rgit::Repository->new(fake => 1) };
115 is($@, '', 'App::Rgit::Repository->new: no dir, fake: does not croak');
116 isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: no dir, fake: returns a valid object');
118 chdir $cwd or die "chdir($cwd): $!";
120 $res = eval { App::Rgit::Repository->new(dir => 't', fake => 1) };
121 is($@, '', 'App::Rgit::Repository->new: relative dir, fake: does not croak');
122 isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: relative dir, fake: returns a valid object');