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