]> git.vpit.fr Git - perl/modules/rgit.git/blob - t/15-failures.t
Use @ as the escape character. ^ is actually an escape char of cmd.exe
[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 => 45;
10
11 use App::Rgit;
12
13 local $SIG{__WARN__} = sub { die @_ };
14
15 eval { App::Rgit->new(qw/foo bar baz/) };
16 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');
17
18 my $res = eval { App::Rgit->new() };
19 is($@,   '',    'App::Rgit->new(): no root: does not croak');
20 is($res, undef, 'App::Rgit->new(): no root: returns undef');
21
22 $res = eval { App::Rgit->new(root => $0) };
23 is($@,   '',    'App::Rgit->new(): wrong root: does not croak');
24 is($res, undef, 'App::Rgit->new(): wrong root: returns undef');
25
26 $res = eval { App::Rgit->new(root => 't') };
27 is($@,   '',    'App::Rgit->new(): no git: does not croak');
28 is($res, undef, 'App::Rgit->new(): no git: returns undef');
29
30 $res = eval { App::Rgit->new(root => 't', git => $0) };
31 is($@,   '',    'App::Rgit->new(): wrong git: does not croak');
32 is($res, undef, 'App::Rgit->new(): wrong git: returns undef');
33
34 $res = eval { App::Rgit->new(root => 't', git => 't/bin/git') };
35 is($@,       '',          'App::Rgit->new(): no cmd: does not croak');
36 isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no cmd: returns an object');
37
38 $res = eval { App::Rgit->new(root => 't', git => 't/bin/git', cmd => 'version'); };
39 is($@,       '',          'App::Rgit->new(): no args: does not croak');
40 isa_ok($res, 'App::Rgit', 'App::Rgit->new(): no args: returns an object');
41
42 $res = eval { $res->new(root => 't', git => 't/bin/git', cmd => 'version'); };
43 is($@,       '',          '$ar->new(): no args: does not croak');
44 isa_ok($res, 'App::Rgit', '$ar->new(): no args: returns an object');
45
46 $res = eval { App::Rgit::new(undef, root => 't', git => 't/bin/git', cmd => 'version'); };
47 is($@,       '',         'undef->App::Rgit::new(): no args: does not croak');
48 isa_ok($res, 'App::Rgit','undef->App::Rgit::new(): no args: returns an object');
49
50 use App::Rgit::Command;
51
52 eval { App::Rgit::Command::Once->App::Rgit::Command::new(cmd => 'dongs') };
53 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');
54
55 {
56  no strict 'refs';
57  push @{'App::Rgit::Test::Foo::ISA'}, 'App::Rgit::Command::Once';
58 }
59 $res = eval { App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => 'version') };
60 is($@, '', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): does not croak');
61 isa_ok($res, 'App::Rgit::Test::Foo', 'App::Rgit::Test::Foo->App::Rgit::Command::new(cmd => "version"): returns valid object');
62
63 $res = eval { App::Rgit::Command->action('version') };
64 is($@,   '', 'App::Rgit::Command->action("version"): does not croak');
65 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action("version"): returns valid answer');
66
67 $res = eval { App::Rgit::Command->new(cmd => 'version')->action() };
68 is($@,   '', 'App::Rgit::Command->action(): does not croak');
69 is($res, 'App::Rgit::Command::Once', 'App::Rgit::Command->action(): returns valid answer');
70
71 $res = eval { App::Rgit::Command->action() };
72 is($@,   '',    'App::Rgit::Command->action(): no cmd: does not croak');
73 is($res, undef, 'App::Rgit::Command->action(); no cmd: returns undef');
74
75 $res = eval { App::Rgit::Command::action() };
76 is($@,   '',    'undef->App::Rgit::Command::action(): no cmd: does not croak');
77 is($res, undef, 'undef->App::Rgit::Command::action(); no cmd: returns undef');
78
79 $res = bless { }, 'App::Rgit::Test::Monkey';
80 $res = eval { $res->App::Rgit::Command::action() };
81 is($@,   '',    'App::Rgit::Test::Monkey->App::Rgit::Command::action(): no cmd: does not croak');
82 is($res, undef, 'App::Rgit::Test::Monkey->App::Rgit::Command::action(); no cmd: returns undef');
83
84 $res = eval { App::Rgit::Command->action('beer' => 'App::Rgit::Test::Pub') };
85 is($@, '', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): does not croak');
86 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer" => "App::Rgit::Test::Pub"): returns valid answer');
87
88 $res = eval { App::Rgit::Command->action('beer') };
89 is($@, '', 'App::Rgit::Command->action("beer"): does not croak');
90 is($res, 'App::Rgit::Test::Pub', 'App::Rgit::Command->action("beer"): returns valid answer');
91
92 $res = eval { App::Rgit::Command->new(cmd => 'beer') };
93 like($@, qr!Couldn't\s+load\s+App::Rgit::Test::Pub\s*:!, 'App::Rgit::Command->new(cmd => "pub"): croaks');
94
95 use App::Rgit::Config;
96
97 my $arc = App::Rgit::Config->new(root => 't', git => 't/bin/git');
98
99 $res = eval { $arc->repos };
100 is($@, '', '$arc->repos: does not croak');
101 is_deeply($res, [ ], '$arc->repos: found nothing');
102
103 $res = eval { $arc->repos };
104 is($@, '', '$arc->repos: does not croak');
105 is_deeply($res, [ ], '$arc->repos: cached ok');
106
107 use App::Rgit::Repository;
108
109 my $cwd = cwd;
110 my $t = catdir($cwd, 't');
111 chdir $t or die "chdir($t): $!";
112
113 $res = eval { App::Rgit::Repository->new() };
114 is($@, '', 'App::Rgit::Repository->new: no dir: does not croak');
115 is($res, undef, 'App::Rgit::Repository->new: no dir: returns undef');
116
117 $res = eval { App::Rgit::Repository->new(fake => 1) };
118 is($@, '', 'App::Rgit::Repository->new: no dir, fake: does not croak');
119 isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: no dir, fake: returns a valid object');
120
121 chdir $cwd or die "chdir($cwd): $!";
122
123 $res = eval { App::Rgit::Repository->new(dir => 't', fake => 1) };
124 is($@, '', 'App::Rgit::Repository->new: relative dir, fake: does not croak');
125 isa_ok($res, 'App::Rgit::Repository', 'App::Rgit::Repository->new: relative dir, fake: returns a valid object');
126