Test::Git - Helper functions for test scripts using Git
use Test::More; use Test::Git; # check there is a git binary available, or skip all has_git(); # check there is a minimum version of git available, or skip all has_git( '1.6.5' ); # check the git we want to test has a minimum version, or skip all has_git( '1.6.5', { git => '/path/to/alternative/git' } ); # normal plan plan tests => 2; # create a new, empty repository in a temporary location # and return a Git::Repository object my $r = test_repository(); # run some tests on the repository ...
Test::Git provides a number of helpful functions when running test scripts that require the creation and management of a Git repository.
Checks if there is a git binary available, or skips all tests.
If the optional $version argument is provided, also checks if the available git binary has a version greater or equal to $version.
$version
This function also accepts an option hash of the same kind as those accepted by Git::Repository and Git::Repository::Command.
This function must be called before plan(), as it performs a skip_all if requirements are not met.
plan()
Creates a new empty git repository in a temporary location, and returns a Git::Repository object pointing to it.
This function takes options as a hash. Each key will influence a different part of the creation process.
This call is the equivalent of the default call with no options:
test_repository( temp => [ CLEANUP => 1 ], # File::Temp::tempdir options init => [], # git init options git => {}, # Git::Repository options );
To create a bare repository:
test_repository( init => [ '--bare' ] );
To leave the repository in its location after the end of the test:
test_repository( temp => [ CLEANUP => 0 ] );
Note that since test_repository() uses git init to create the test repository, it requires at least Git version 1.5.0.
test_repository()
git init
1.5.0
Philippe Bruhat (BooK), <book at cpan.org>
<book at cpan.org>
Copyright 2010-2012 Philippe Bruhat (BooK), all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Git::Repository, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Git::Repository
CPAN shell
perl -MCPAN -e shell install Git::Repository
For more information on module installation, please visit the detailed CPAN module installation guide.