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