7 use File::Spec (); # catdir
9 use Test::More tests => 44;
13 local $SIG{__WARN__} = sub { die @_ };
21 is $@, '', "App::Rgit->new(): no root, no GIT_DIR: doesn't croak";
22 isa_ok $res,'App::Rgit','App::Rgit->new(): no root, no GIT_DIR: returns object';
25 local $ENV{GIT_DIR} = Cwd::cwd;
30 is $@, '', "App::Rgit->new(): no root: doesn't croak";
31 isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no root: returns object';
39 like $@, qr/Invalid root directory/, 'App::Rgit->new(): wrong root: croaks';
42 local $ENV{GIT_EXEC_PATH};
43 local $ENV{PATH} = 't/bin';
48 is $@, '', "App::Rgit->new(): no git, no GIT_EXEC_PATH: doesn't croak";
49 isa_ok $res, 'App::Rgit',
50 'App::Rgit->new(): no git, no GIT_EXEC_PATH: returns object';
53 local $ENV{GIT_EXEC_PATH} = 't/bin/git';
58 is $@, '', "App::Rgit->new(): no git: doesn't croak";
59 isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no git: returns object';
67 like $@, qr/Couldn't find a proper git executable/,
68 'App::Rgit->new(): wrong git: croaks';
76 is $@, '', "App::Rgit->new(): no cmd: doesn't croak";
77 isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no cmd: returns object';
86 is $@, '', "App::Rgit->new(): no args: doesn't croak";
87 isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no args: returns object';
96 is $@, '', '$ar->new(): no args: doesn\'t croak';
97 isa_ok $res, 'App::Rgit', '$ar->new(): no args: returns object';
99 use App::Rgit::Command;
102 App::Rgit::Command::Once->App::Rgit::Command::new(
106 like $@, qr!Command dongs should be executed as a App::Rgit::Command::Each!,
107 'App::Rgit::Command::Once->App::Rgit::Command::new(cmd => "dongs"): croaks';
111 push @{'App::Rgit::Test::Foo::ISA'}, 'App::Rgit::Command::Once';
114 App::Rgit::Test::Foo->App::Rgit::Command::new(
118 is $@, '', "App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version'): doesn't croak";
119 isa_ok $res, 'App::Rgit::Test::Foo', "App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version'): returns object";
122 App::Rgit::Command->action('version')
125 "App::Rgit::Command->action('version'): doesn't croak";
126 is $res, 'App::Rgit::Command::Once',
127 "App::Rgit::Command->action('version'): returns class";
130 App::Rgit::Command->new(
135 "App::Rgit::Command->action(): doesn't croak";
136 is $res, 'App::Rgit::Command::Once',
137 'App::Rgit::Command->action(): returns class';
140 App::Rgit::Command->action()
142 is $@, '', "App::Rgit::Command->action(): no cmd: doesn't croak";
143 is $res, undef, 'App::Rgit::Command->action(); no cmd: returns undef';
146 App::Rgit::Command::action()
148 is $@, '', "undef->App::Rgit::Command::action(): no cmd: doesn't croak";
149 is $res, undef, 'undef->App::Rgit::Command::action(); no cmd: returns undef';
152 my $obj = bless { }, 'App::Rgit::Test::Monkey';
153 $obj->App::Rgit::Command::action()
156 "App::Rgit::Test::Monkey->App::Rgit::Command::action(): no cmd: doesn't croak";
158 'App::Rgit::Test::Monkey->App::Rgit::Command::action(); no cmd: returns undef';
161 App::Rgit::Command->action(
162 beer => 'App::Rgit::Test::Pub'
166 "App::Rgit::Command->action(beer => 'App::Rgit::Test::Pub'): doesn't croak";
167 is $res, 'App::Rgit::Test::Pub',
168 "App::Rgit::Command->action(beer => 'App::Rgit::Test::Pub'): returns class";
171 App::Rgit::Command->action('beer')
174 "App::Rgit::Command->action('beer'): doesn't croak";
175 is $res, 'App::Rgit::Test::Pub',
176 "App::Rgit::Command->action('beer'): returns class";
179 App::Rgit::Command->new(
183 like $@, qr!Couldn't load App::Rgit::Test::Pub:!,
184 'App::Rgit::Command->new(cmd => "pub"): croaks';
186 use App::Rgit::Config;
188 my $arc = App::Rgit::Config->new(root => 't', git => 't/bin/git');
190 $res = eval { $arc->repos };
191 is $@, '', '$arc->repos: doesn\'t croak';
192 is_deeply $res, [ ], '$arc->repos: found nothing';
194 $res = eval { $arc->repos };
195 is $@, '', '$arc->repos: doesn\'t croak';
196 is_deeply $res, [ ], '$arc->repos: cached ok';
198 use App::Rgit::Repository;
201 my $t = File::Spec->catdir($cwd, 't');
202 chdir $t or die "chdir($t): $!";
205 App::Rgit::Repository->new();
207 is $@, '', "App::Rgit::Repository->new: no dir: doesn't croak";
208 is $res, undef, 'App::Rgit::Repository->new: no dir: returns undef';
211 App::Rgit::Repository->new(
216 "App::Rgit::Repository->new: no dir, fake: doesn't croak";
217 isa_ok $res, 'App::Rgit::Repository',
218 'App::Rgit::Repository->new: no dir, fake: returns object';
220 chdir $cwd or die "chdir($cwd): $!";
223 App::Rgit::Repository->new(dir => 't', fake => 1)
226 "App::Rgit::Repository->new: relative dir, fake: doesn't croak";
227 isa_ok $res, 'App::Rgit::Repository',
228 'App::Rgit::Repository->new: relative dir, fake: returns object';