]> git.vpit.fr Git - perl/modules/rgit.git/blob - t/15-failures.t
Test loading all modules
[perl/modules/rgit.git] / t / 15-failures.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Cwd qw/cwd/;
7 use File::Spec::Functions qw/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 { 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 use App::Rgit::Command;
44
45 eval { App::Rgit::Command::Once->App::Rgit::Command::new(cmd => 'dongs') };
46 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');
47
48 {
49  no strict 'refs';
50  push @{'App::Rgit::Test::Foo::ISA'}, 'App::Rgit::Command::Once';
51 }
52 $res = eval { App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version') };
53 is($@, '', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): does not croak');
54 isa_ok($res, 'App::Rgit::Test::Foo', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): returns valid object');
55
56 $res = eval { App::Rgit::Command->action('version') };
57 is($@,   '', 'App::Rgit::Command->action("version"): does not croak');
58 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action("version"): returns valid answer');
59
60 $res = eval { App::Rgit::Command->new(cmd => 'version')->action() };
61 is($@,   '', 'App::Rgit::Command->action(): does not croak');
62 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action(): returns valid answer');
63
64 $res = eval { App::Rgit::Command->action() };
65 is($@,   '',    'App::Rgit::Command->action(): no cmd: does not croak');
66 is($res, undef, 'App::Rgit::Command->action(); no cmd: returns undef');
67
68 $res = eval { App::Rgit::Command::action() };
69 is($@,   '',    'undef->App::Rgit::Command::action(): no cmd: does not croak');
70 is($res, undef, 'undef->App::Rgit::Command::action(); no cmd: returns undef');
71
72 $res = bless { }, 'App::Rgit::Test::Monkey';
73 $res = eval { $res->App::Rgit::Command::action() };
74 is($@,   '',    'App::Rgit::Test::Monkey->App::Rgit::Command::action(): no cmd: does not croak');
75 is($res, undef, 'App::Rgit::Test::Monkey->App::Rgit::Command::action(); no cmd: returns undef');
76
77 $res = eval { App::Rgit::Command->action('beer' => 'App::Rgit::Test::Pub') };
78 is($@, '', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): does not croak');
79 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): returns valid answer');
80
81 $res = eval { App::Rgit::Command->action('beer') };
82 is($@, '', 'App::Rgit::Command->action("beer"): does not croak');
83 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer"): returns valid answer');
84
85 $res = eval { App::Rgit::Command->new(cmd => 'beer') };
86 like($@, qr!Couldn't\s+load\s+App::Rgit::Test::Pub\s*:!, 'App::Rgit::Command->new(cmd => "pub"): croaks');
87
88 use App::Rgit::Config;
89
90 my $arc = App::Rgit::Config->new(root => 't', git => 't/bin/git');
91
92 $res = eval { $arc->repos };
93 is($@, '', '$arc->repos: does not croak');
94 is_deeply($res, [ ], '$arc->repos: found nothing');
95
96 $res = eval { $arc->repos };
97 is($@, '', '$arc->repos: does not croak');
98 is_deeply($res, [ ], '$arc->repos: cached ok');
99
100 use App::Rgit::Repository;
101
102 my $cwd = cwd;
103 my $t = catdir($cwd, 't');
104 chdir $t or die "chdir($t): $!";
105
106 $res = eval { App::Rgit::Repository->new() };
107 is($@, '', 'App::Rgit::Repository->new: no dir: does not croak');
108 is($res, undef, 'App::Rgit::Repository->new: no dir: returns undef');
109
110 $res = eval { App::Rgit::Repository->new(fake => 1) };
111 is($@, '', 'App::Rgit::Repository->new: no dir, fake: does not croak');
112 isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: no dir, fake: returns a valid object');
113
114 chdir $cwd or die "chdir($cwd): $!";
115
116 $res = eval { App::Rgit::Repository->new(dir => 't', fake => 1) };
117 is($@, '', 'App::Rgit::Repository->new: relative dir, fake: does not croak');
118 isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: relative dir, fake: returns a valid object');
119