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