]> git.vpit.fr Git - perl/modules/rgit.git/blobdiff - t/15-failures.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/rgit.git] / t / 15-failures.t
index d0711889b3bcf68cbc6260120b66dc46d6c016a9..ea9881babb73b6fdd3eefe6c1c658e5c33462cdf 100644 (file)
@@ -3,36 +3,60 @@
 use strict;
 use warnings;
 
-use Cwd qw/cwd/;
-use File::Spec::Functions qw/catdir/;
+use Cwd        (); # cwd
+use File::Spec (); # catdir
 
-use Test::More tests => 42;
+use Test::More tests => 44;
 
 use App::Rgit;
 
 local $SIG{__WARN__} = sub { die @_ };
 
 my $res = eval {
- App::Rgit->new()
+ local $ENV{GIT_DIR};
+ App::Rgit->new(
+  git => 't/bin/git',
+ );
+};
+is     $@,  '',         "App::Rgit->new(): no root, no GIT_DIR: doesn't croak";
+isa_ok $res,'App::Rgit','App::Rgit->new(): no root, no GIT_DIR: returns object';
+
+$res = eval {
+ local $ENV{GIT_DIR} = Cwd::cwd;
+ App::Rgit->new(
+  git => 't/bin/git',
+ );
 };
-is $@,   '',    "App::Rgit->new(): no root: doesn't croak";
-is $res, undef, 'App::Rgit->new(): no root: returns undef';
+is     $@,   '',          "App::Rgit->new(): no root: doesn't croak";
+isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no root: returns object';
 
 $res = eval {
  App::Rgit->new(
   root => $0,
+  git  => 't/bin/git',
+ );
+};
+like $@, qr/Invalid root directory/, 'App::Rgit->new(): wrong root: croaks';
+
+$res = eval {
+ local $ENV{GIT_EXEC_PATH};
+ local $ENV{PATH} = 't/bin';
+ App::Rgit->new(
+  root => 't',
  );
 };
-is $@,   '',    "App::Rgit->new(): wrong root: doesn't croak";
-is $res, undef, 'App::Rgit->new(): wrong root: returns undef';
+is     $@,   '',   "App::Rgit->new(): no git, no GIT_EXEC_PATH: doesn't croak";
+isa_ok $res, 'App::Rgit',
+                   'App::Rgit->new(): no git, no GIT_EXEC_PATH: returns object';
 
 $res = eval {
+ local $ENV{GIT_EXEC_PATH} = 't/bin/git';
  App::Rgit->new(
   root => 't',
  );
 };
-is $@,   '',    "App::Rgit->new(): no git: doesn't croak";
-is $res, undef, 'App::Rgit->new(): no git: returns undef';
+is     $@,   '',          "App::Rgit->new(): no git: doesn't croak";
+isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no git: returns object';
 
 $res = eval {
  App::Rgit->new(
@@ -40,8 +64,8 @@ $res = eval {
   git  => $0,
  );
 };
-is $@,   '',    "App::Rgit->new(): wrong git: doesn't croak";
-is $res, undef, 'App::Rgit->new(): wrong git: returns undef';
+like $@, qr/Couldn't find a proper git executable/,
+                                          'App::Rgit->new(): wrong git: croaks';
 
 $res = eval {
  App::Rgit->new(
@@ -173,8 +197,8 @@ is_deeply $res, [ ], '$arc->repos: cached ok';
 
 use App::Rgit::Repository;
 
-my $cwd = cwd;
-my $t   = catdir($cwd, 't');
+my $cwd = Cwd::cwd;
+my $t   = File::Spec->catdir($cwd, 't');
 chdir $t or die "chdir($t): $!";
 
 $res = eval {