]> git.vpit.fr Git - perl/modules/rgit.git/blob - t/15-failures.t
Test caching of repositories in App::Rgit::Config::Default
[perl/modules/rgit.git] / t / 15-failures.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 38;
7
8 use App::Rgit;
9
10 local $SIG{__WARN__} = sub { die @_ };
11
12 eval { App::Rgit->new(qw/foo bar baz/) };
13 like($@, qr!Optional\s+arguments\s+must\s+be\s+passed\s+as\s+keys?\s*/\s*values?\s+pairs?!, 'App::Rgit->new(even): croaks');
14
15 my $res = eval { App::Rgit->new() };
16 is($@,   '',    'App::Rgit->new(): no root: does not croak');
17 is($res, undef, 'App::Rgit->new(): no root: returns undef');
18
19 $res = eval { App::Rgit->new(root => $0) };
20 is($@,   '',    'App::Rgit->new(): wrong root: does not croak');
21 is($res, undef, 'App::Rgit->new(): wrong root: returns undef');
22
23 $res = eval { App::Rgit->new(root => 't') };
24 is($@,   '',    'App::Rgit->new(): no git: does not croak');
25 is($res, undef, 'App::Rgit->new(): no git: returns undef');
26
27 $res = eval { App::Rgit->new(root => 't', git => $0) };
28 is($@,   '',    'App::Rgit->new(): wrong git: does not croak');
29 is($res, undef, 'App::Rgit->new(): wrong git: returns undef');
30
31 $res = eval { App::Rgit->new(root => 't', git => 't/bin/git') };
32 is($@,       '',          'App::Rgit->new(): no cmd: does not croak');
33 isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no cmd: returns an object');
34
35 $res = eval { App::Rgit->new(root => 't', git => 't/bin/git', cmd => 'version'); };
36 is($@,       '',          'App::Rgit->new(): no args: does not croak');
37 isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no args: returns an object');
38
39 $res = eval { $res->new(root => 't', git => 't/bin/git', cmd => 'version'); };
40 is($@,       '',          '$ar->new(): no args: does not croak');
41 isa_ok($res, 'App::Rgit', '$ar->new(): no args: returns an object');
42
43 $res = eval { App::Rgit::new(undef, root => 't', git => 't/bin/git', cmd => 'version'); };
44 is($@,       '',         'undef->App::Rgit::new(): no args: does not croak');
45 isa_ok($res, 'App::Rgit','undef->App::Rgit::new(): no args: returns an object');
46
47 use App::Rgit::Command;
48
49 eval { App::Rgit::Command::Once->App::Rgit::Command::new(cmd => 'dongs') };
50 like($@, qr!Command\s+dongs\s+should\s+be\s+executed\s+as\s+a\s+App::Rgit::Command::Each!, 'App::Rgit::Command::Once->App::Rgit::Command::new(cmd => "dongs"): croaks');
51
52 {
53  no strict 'refs';
54  push @{'App::Rgit::Test::Foo::ISA'}, 'App::Rgit::Command::Once';
55 }
56 $res = eval { App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version') };
57 is($@, '', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): does not croak');
58 isa_ok($res, 'App::Rgit::Test::Foo', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): returns valid object');
59
60 $res = eval { App::Rgit::Command->action('version') };
61 is($@,   '', 'App::Rgit::Command->action("version"): does not croak');
62 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action("version"): returns valid answer');
63
64 $res = eval { App::Rgit::Command->new(cmd => 'version')->action() };
65 is($@,   '', 'App::Rgit::Command->action(): does not croak');
66 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action(): returns valid answer');
67
68 $res = eval { App::Rgit::Command->action() };
69 is($@,   '',    'App::Rgit::Command->action(): no cmd: does not croak');
70 is($res, undef, 'App::Rgit::Command->action(); no cmd: returns undef');
71
72 $res = eval { App::Rgit::Command::action() };
73 is($@,   '',    'undef->App::Rgit::Command::action(): no cmd: does not croak');
74 is($res, undef, 'undef->App::Rgit::Command::action(); no cmd: returns undef');
75
76 $res = bless { }, 'App::Rgit::Test::Monkey';
77 $res = eval { $res->App::Rgit::Command::action() };
78 is($@,   '',    'App::Rgit::Test::Monkey->App::Rgit::Command::action(): no cmd: does not croak');
79 is($res, undef, 'App::Rgit::Test::Monkey->App::Rgit::Command::action(); no cmd: returns undef');
80
81 $res = eval { App::Rgit::Command->action('beer' => 'App::Rgit::Test::Pub') };
82 is($@, '', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): does not croak');
83 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): returns valid answer');
84
85 $res = eval { App::Rgit::Command->action('beer') };
86 is($@, '', 'App::Rgit::Command->action("beer"): does not croak');
87 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer"): returns valid answer');
88
89 use App::Rgit::Config;
90
91 my $arc = App::Rgit::Config->new(root => 't', git => 't/bin/git');
92
93 $res = eval { $arc->repos };
94 is($@, '', '$arc->repos: does not croak');
95 is_deeply($res, [ ], '$arc->repos: found nothing');
96
97 $res = eval { $arc->repos };
98 is($@, '', '$arc->repos: does not croak');
99 is_deeply($res, [ ], '$arc->repos: cached ok');