1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
use strict;
use warnings;
use Test::More;
use Test::Requires::Git;
use Test::Git;
use File::Temp qw( tempdir );
use File::Spec;
use Cwd qw( cwd realpath );
use Git::Repository;
test_requires_git '1.5.0.rc1';
# clean up the environment
delete @ENV{qw( GIT_DIR GIT_WORK_TREE )};
$ENV{LC_ALL} = 'C';
$ENV{GIT_CONFIG_NOSYSTEM} = 1;
delete $ENV{XDG_CONFIG_HOME};
delete $ENV{HOME};
my $home = cwd();
# a place to put a git repository
my @init;
push @init, init => [ '-q' ] if Git::Repository->version_ge('1.5.2.3');
my $fake = realpath( tempdir( CLEANUP => 1 ) );
my $r = test_repository(@init);
my $dir = $r->work_tree;
my $gitdir = $r->git_dir;
# capture warnings
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, shift };
# use new with various options
my $re_wc = qr/^working_copy is obsolete, please use work_tree instead /;
my $re_re = qr/^repository is obsolete, please use git_dir instead /;
my @tests = (
[ $home => [ working_copy => $dir ], $re_wc ],
[ $home => [ work_tree => $dir, working_copy => $fake ], $re_wc ],
[ $home => [ repository => $gitdir ], $re_re ],
[ $home => [ git_dir => $gitdir, repository => $fake ], $re_re ],
[ $home => [
git_dir => $gitdir,
repository => $fake,
work_tree => $dir,
working_copy => $fake,
],
$re_re
],
# order doesn't matter
[ $home => [
repository => $fake,
working_copy => $fake,
work_tree => $dir,
git_dir => $gitdir,
],
$re_re
],
);
# test backward compatibility
plan tests => 2 * @tests;
# now test most possible cases for backward compatibility
for my $t (@tests) {
my ( $cwd, $args, $re ) = @$t;
chdir $cwd;
my $i;
my @args = grep { ++$i % 2 } @$args;
$r = eval { Git::Repository->new(@$args) };
ok( !$r, "Git::Repository->new( @args ) fails" );
like( $@, $re, '... with expected error message' );
}
|