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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
use strict;
use warnings;
use lib 't';
use Test::More;
use Test::Requires::Git;
use Test::Git;
use File::Temp qw( tempdir );
use File::Spec;
use Cwd qw( cwd abs_path );
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};
plan tests => my $tests;
# first create a new empty repository
my @init;
push @init, init => [ '-q' ] if Git::Repository->version_ge('1.5.2.3');
my $r = test_repository( @init );
my $dir = $r->work_tree;
my $gitdir = $r->git_dir;
# FAIL - no hello method
BEGIN { $tests += 1 }
ok( !eval { $r->hello }, 'No hello() method' );
# PASS - load Hello
BEGIN { $tests += 1 }
use_ok( 'Git::Repository', 'Hello' );
# PASS - new methods
BEGIN { $tests += 4 }
ok( my $got = eval { $r->hello }, 'hello() method is there' );
diag $@ if $@;
is( $got, "Hello, git world!\n", '... with expected value' );
ok( $got = eval { $r->hello_gitdir }, 'hello_gitdir() method is there' );
diag $@ if $@;
is( $got, "Hello, $gitdir!\n", '... with expected value' );
# FAIL - can't load this plugin
BEGIN { $tests += 2 }
ok( !eval q{use Git::Repository 'DoesNotExist'; 2;},
'Failed to load inexistent plugin' );
like(
$@,
qr{^Can't locate Git/Repository/Plugin/DoesNotExist\.pm },
'... expected error message'
);
# PASS - load Hello2 and throw various warnings
my @warnings;
{
BEGIN { $tests += 5 }
local $SIG{__WARN__} = sub { push @warnings, shift };
use_ok( 'Git::Repository', [ Hello2 => 'hello', 'zlonk' ] );
is( scalar @warnings, 3, 'Got 3 warnings' );
like(
$warnings[0],
qr/^Use of \@KEYWORDS by Git::Repository::Plugin::Hello2 is deprecated /,
'... deprecation warning'
);
like(
$warnings[1],
qr/^Unknown keyword 'zlonk' in Git::Repository::Plugin::Hello2 /,
'... unknown keyword'
);
like(
$warnings[2],
qr/^Subroutine (Git::Repository::)?hello redefined /,
'... redefined method warning'
);
@warnings = ();
BEGIN { $tests += 5 }
use_ok( 'Git::Repository', [ Hello2 => 'bam' ] );
is( scalar @warnings, 3, 'Got 3 warnings' );
like(
$warnings[0],
qr/^Use of \@KEYWORDS by Git::Repository::Plugin::Hello2 is deprecated /,
'... deprecation warning'
);
like(
$warnings[1],
qr/^Unknown keyword 'bam' in Git::Repository::Plugin::Hello2 /,
'... unknown keyword'
);
like(
$warnings[2],
qr/^No keywords installed from Git::Repository::Plugin::Hello2 /,
'... no valid keyword left'
);
@warnings = ();
}
# PASS - new methods
BEGIN { $tests += 4 }
ok( $got = eval { $r->hello }, 'hello() method is there' );
diag $@ if $@;
is( $got, "Hello, world!\n", '... with new value' );
ok( !eval { $r->hello_worktree }, 'hello_worktree() method is not there' );
like(
$@,
qr/^Can't locate object method "hello_worktree" via package "Git::Repository" /,
'... expected error message'
);
# PASS - load a fully qualified plgin class
BEGIN { $tests += 3 }
use_ok( 'Git::Repository', '+MyGit::Hello' );
ok( $got = eval { $r->myhello }, 'myhello() method is there' );
diag $@ if $@;
is( $got, "Hello, my git world!\n", '... with expected value' );
|