]> git.vpit.fr Git - perl/modules/rgit.git/blob - t/15-failures.t
Make App::Rgit::Config->new discover the git executable itself
[perl/modules/rgit.git] / t / 15-failures.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Cwd        (); # cwd
7 use File::Spec (); # catdir
8
9 use Test::More tests => 43;
10
11 use App::Rgit;
12
13 local $SIG{__WARN__} = sub { die @_ };
14
15 my $res = eval {
16  App::Rgit->new()
17 };
18 is $@,   '',    "App::Rgit->new(): no root: doesn't croak";
19 is $res, undef, 'App::Rgit->new(): no root: returns undef';
20
21 $res = eval {
22  App::Rgit->new(
23   root => $0,
24  );
25 };
26 is $@,   '',    "App::Rgit->new(): wrong root: doesn't croak";
27 is $res, undef, 'App::Rgit->new(): wrong root: returns undef';
28
29 $res = eval {
30  local $ENV{GIT_EXEC_PATH};
31  local $ENV{PATH} = 't/bin';
32  App::Rgit->new(
33   root => 't',
34  );
35 };
36 is     $@,   '',   "App::Rgit->new(): no git, no GIT_EXEC_PATH: doesn't croak";
37 isa_ok $res, 'App::Rgit',
38                    'App::Rgit->new(): no git, no GIT_EXEC_PATH: returns object';
39
40 $res = eval {
41  local $ENV{GIT_EXEC_PATH} = 't/bin/git';
42  App::Rgit->new(
43   root => 't',
44  );
45 };
46 is     $@,   '',          "App::Rgit->new(): no git: doesn't croak";
47 isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no git: returns object';
48
49 $res = eval {
50  App::Rgit->new(
51   root => 't',
52   git  => $0,
53  );
54 };
55 like $@, qr/Couldn't find a proper git executable/,
56                                           'App::Rgit->new(): wrong git: croaks';
57
58 $res = eval {
59  App::Rgit->new(
60   root => 't',
61   git  => 't/bin/git',
62  );
63 };
64 is     $@,   '',          "App::Rgit->new(): no cmd: doesn't croak";
65 isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no cmd: returns object';
66
67 $res = eval {
68  App::Rgit->new(
69   root => 't',
70   git  => 't/bin/git',
71   cmd  => 'version',
72  );
73 };
74 is     $@,   '',          "App::Rgit->new(): no args: doesn't croak";
75 isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no args: returns object';
76
77 $res = eval {
78  $res->new(
79   root => 't',
80   git  => 't/bin/git',
81   cmd  => 'version',
82  );
83 };
84 is     $@,   '',          '$ar->new(): no args: doesn\'t croak';
85 isa_ok $res, 'App::Rgit', '$ar->new(): no args: returns object';
86
87 use App::Rgit::Command;
88
89 eval {
90  App::Rgit::Command::Once->App::Rgit::Command::new(
91   cmd => 'dongs',
92  );
93 };
94 like $@, qr!Command dongs should be executed as a App::Rgit::Command::Each!,
95     'App::Rgit::Command::Once->App::Rgit::Command::new(cmd => "dongs"): croaks';
96
97 {
98  no strict 'refs';
99  push @{'App::Rgit::Test::Foo::ISA'}, 'App::Rgit::Command::Once';
100 }
101 $res = eval {
102  App::Rgit::Test::Foo->App::Rgit::Command::new(
103   cmd => 'version',
104  );
105 };
106 is     $@,   '',                     "App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version'): doesn't croak";
107 isa_ok $res, 'App::Rgit::Test::Foo', "App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version'): returns object";
108
109 $res = eval {
110  App::Rgit::Command->action('version')
111 };
112 is $@,   '',
113                          "App::Rgit::Command->action('version'): doesn't croak";
114 is $res, 'App::Rgit::Command::Once',
115                          "App::Rgit::Command->action('version'): returns class";
116
117 $res = eval {
118  App::Rgit::Command->new(
119   cmd => 'version',
120  )->action();
121 };
122 is $@,   '',
123                                   "App::Rgit::Command->action(): doesn't croak";
124 is $res, 'App::Rgit::Command::Once',
125                                   'App::Rgit::Command->action(): returns class';
126
127 $res = eval {
128  App::Rgit::Command->action()
129 };
130 is $@,   '',    "App::Rgit::Command->action(): no cmd: doesn't croak";
131 is $res, undef, 'App::Rgit::Command->action(); no cmd: returns undef';
132
133 $res = eval {
134  App::Rgit::Command::action()
135 };
136 is $@,   '',    "undef->App::Rgit::Command::action(): no cmd: doesn't croak";
137 is $res, undef, 'undef->App::Rgit::Command::action(); no cmd: returns undef';
138
139 $res = eval {
140  my $obj = bless { }, 'App::Rgit::Test::Monkey';
141  $obj->App::Rgit::Command::action()
142 };
143 is $@,   '',
144  "App::Rgit::Test::Monkey->App::Rgit::Command::action(): no cmd: doesn't croak";
145 is $res, undef,
146  'App::Rgit::Test::Monkey->App::Rgit::Command::action(); no cmd: returns undef';
147
148 $res = eval {
149  App::Rgit::Command->action(
150   beer => 'App::Rgit::Test::Pub'
151  );
152 };
153 is $@,   '',
154     "App::Rgit::Command->action(beer => 'App::Rgit::Test::Pub'): doesn't croak";
155 is $res, 'App::Rgit::Test::Pub',
156     "App::Rgit::Command->action(beer => 'App::Rgit::Test::Pub'): returns class";
157
158 $res = eval {
159  App::Rgit::Command->action('beer')
160 };
161 is $@,   '',
162                             "App::Rgit::Command->action('beer'): doesn't croak";
163 is $res, 'App::Rgit::Test::Pub',
164                             "App::Rgit::Command->action('beer'): returns class";
165
166 $res = eval {
167  App::Rgit::Command->new(
168   cmd => 'beer',
169  );
170 };
171 like $@, qr!Couldn't load App::Rgit::Test::Pub:!,
172                                 'App::Rgit::Command->new(cmd => "pub"): croaks';
173
174 use App::Rgit::Config;
175
176 my $arc = App::Rgit::Config->new(root => 't', git => 't/bin/git');
177
178 $res = eval { $arc->repos };
179 is        $@,   '',  '$arc->repos: doesn\'t croak';
180 is_deeply $res, [ ], '$arc->repos: found nothing';
181
182 $res = eval { $arc->repos };
183 is        $@,   '',  '$arc->repos: doesn\'t croak';
184 is_deeply $res, [ ], '$arc->repos: cached ok';
185
186 use App::Rgit::Repository;
187
188 my $cwd = Cwd::cwd;
189 my $t   = File::Spec->catdir($cwd, 't');
190 chdir $t or die "chdir($t): $!";
191
192 $res = eval {
193  App::Rgit::Repository->new();
194 };
195 is $@,   '',    "App::Rgit::Repository->new: no dir: doesn't croak";
196 is $res, undef, 'App::Rgit::Repository->new: no dir: returns undef';
197
198 $res = eval {
199  App::Rgit::Repository->new(
200   fake => 1,
201  );
202 };
203 is     $@,   '',
204                       "App::Rgit::Repository->new: no dir, fake: doesn't croak";
205 isa_ok $res, 'App::Rgit::Repository',
206                      'App::Rgit::Repository->new: no dir, fake: returns object';
207
208 chdir $cwd or die "chdir($cwd): $!";
209
210 $res = eval {
211  App::Rgit::Repository->new(dir => 't', fake => 1)
212 };
213 is     $@,   '',
214                 "App::Rgit::Repository->new: relative dir, fake: doesn't croak";
215 isa_ok $res, 'App::Rgit::Repository',
216                'App::Rgit::Repository->new: relative dir, fake: returns object';
217