blib/lib/Test/Git.pm

filter: Statementstmt 88.5% 54 / 61 Branchbran 45.0% 9 / 20 Conditioncond 50.0% 9 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 91.6% 11 / 12 Podpod 100% 2 / 2 totaltotal 70.7% 87 / 123 CC 18 SCAR 26.3
CC
18
Cov
73%
has_git
30.0
test_repository
17.4
BEGIN
1.0
CRAP 13.9
↑ Summary blib/lib/Git/Repository/Command.pm »
1 package Test::Git;
2 15 $Test::Git::VERSION = '1.326';
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Git::Repository; # 1.15
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use File::Temp qw( tempdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use File::Spec::Functions qw( catdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Git::Version::Compare qw( cmp_git );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Cwd qw( cwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 15 our @ISA = qw( Exporter );
16 15 our @EXPORT = qw( has_git test_repository );
17  
18 15 my $Test = Test::Builder->new();
19  
20 0 ▶sub has_git {
Subroutine has_git: not called CC=5 SCAR=34.0
Pod documented
21 0 my ( $version, @options ) = ( ( grep !ref, @_ )[0], grep ref, @_ );
22 0 ▶ carp sprintf 'has_git() is obsolete, write `use Test::Requires::Git; test_requires_git%s;` instead',
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
23 $version ? " '$version'" : '';
24  
25 # check some git is present
26 0 ▶ $Test->skip_all('Default git binary not found in PATH')
Branch: 1 branch
BranchTrueFalseTotal
unless Git::Repository::Command::_is_git("git") 0 0 0
27 if !Git::Repository::Command::_is_git('git');
28  
29 # check it's at least some minimum version
30 0 my $git_version = Git::Repository->version(@options);
31 0 ▶ $Test->skip_all(
Branch: 1 branch
BranchTrueFalseTotal
if $version and "Git::Repository"->version_lt($version, @options) 0 0 0
Condition0%0/3
$version and "Git::Repository"->version_lt($version, @options)
!ll&&!rl&&r
000
MC/DC0%0/2
$version and "Git::Repository"->version_lt($version, @options)
$version "Git::Repository"->version_lt($version, @options)
Truth table0%0/3
A and B
A= $versionB= "Git::Repository"->version_lt($version, @options)
ABresult
0X0
100
111
32 "Test script requires git >= $version (this is only $git_version)")
33 if $version && Git::Repository->version_lt( $version, @options );
34 }
35  
36 13 ▶sub test_repository {
Subroutine test_repository: called CC=14 SCAR=28.6
Pod documented
37 13 my %args = @_;
38  
39 croak "Can't use both 'init' and 'clone' parameters"
40 13 ▶ if exists $args{init} && exists $args{clone};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"init"} and exists $args{"clone"} 0 13 13
Condition66%2/3
exists $args{"init"} and exists $args{"clone"}
!ll&&!rl&&r
2110
MC/DC0%0/2
exists $args{"init"} and exists $args{"clone"}
exists $args{"init"} exists $args{"clone"}
Truth table66%2/3
A and B
A= exists $args{"init"}B= exists $args{"clone"}
ABresult
0X0
100
111
41  
42 # setup some default values
43 13 ▶ my $temp = $args{temp} || [ CLEANUP => 1 ]; # File::Temp options
Condition50%1/2
$args{'temp'} || ['CLEANUP', 1]
l!l
013
MC/DC0%0/1
$args{'temp'} || ['CLEANUP', 1]
$args{'temp'}
Truth table50%1/2
A
A= $args{'temp'}
Aresult
11
00
44 13 ▶ my $init = $args{init} || []; # git init options
Condition100%2/2
$args{'init'} || []
l!l
112
MC/DC100%1/1
$args{'init'} || []
$args{'init'}
Truth table100%2/2
A
A= $args{'init'}
Aresult
11
00
45 13 ▶ my $opts = $args{git} || {}; # Git::Repository options
Condition100%2/2
$args{'git'} || {}
l!l
310
MC/DC100%1/1
$args{'git'} || {}
$args{'git'}
Truth table100%2/2
A
A= $args{'git'}
Aresult
11
00
46 13 my $safe = { %$opts, fatal => [] }; # ignore 'fatal' settings
47 13 my $clone = $args{clone}; # git clone options
48  
49 # version check
50 13 my $bad_version;
51 13 my $git_version = Git::Repository->version($safe);
52 13 ▶ if ($clone) {
Branch: 2 branches
BranchTrueFalseTotal
if ($clone) { } 2 11 13
elsif (&cmp_git($git_version, '1.4.0') <= 0) { } 0 11 11
53 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&cmp_git($git_version, "1.6.2.rc0") < 0 or &cmp_git("1.7.0.rc1", $git_version) <= 0 and &cmp_git($git_version, "1.7.0.2") <= 0) 0 2 2
Condition33%2/6
&cmp_git($git_version, "1.6.2.rc0") < 0 or &cmp_git("1.7.0.rc1", $git_version) <= 0 and &cmp_git($git_version, "1.7.0.2") <= 0
l!l&&r!l&&!r
002
&cmp_git("1.7.0.rc1", $git_version) <= 0 and &cmp_git($git_version, "1.7.0.2") <= 0
!ll&&!rl&&r
020
MC/DC0%0/3
&cmp_git($git_version, "1.6.2.rc0") < 0 or &cmp_git("1.7.0.rc1", $git_version) <= 0 and &cmp_git($git_version, "1.7.0.2") <= 0
&cmp_git($git_version, "1.6.2.rc0") < 0 &cmp_git("1.7.0.rc1", $git_version) <= 0 &cmp_git($git_version, "1.7.0.2") <= 0
Truth table25%1/4
A or B and C
A= &cmp_git($git_version, "1.6.2.rc0") < 0B= &cmp_git("1.7.0.rc1", $git_version) <= 0C= &cmp_git($git_version, "1.7.0.2") <= 0
ABCresult
1XX1
0111
00X0
0100
54 cmp_git( $git_version, '1.6.2.rc0' ) < 0
55 || ( cmp_git( '1.7.0.rc1', $git_version ) <= 0
56 && cmp_git( $git_version, '1.7.0.2' ) <= 0 )
57 )
58 {
59 0 $bad_version = "test_repository( clone => ... ) requires git >= 1.6.2.rc0 and 1.7.0.rc1 < git < 1.7.0.2 (this is $git_version)";
60 }
61 }
62 elsif ( cmp_git( $git_version, '1.4.0' ) <= 0 ) {
63 0 $bad_version = "test_repository( init => ... ) requires git >= 1.4.0 (this is only $git_version)";
64 }
65 13 ▶ croak $bad_version if $bad_version;
Branch: 1 branch
BranchTrueFalseTotal
if $bad_version 0 13 13
66  
67 # create a temporary directory to host our repository
68 13 my $dir = tempdir(@$temp);
69 13 my $cwd = { cwd => $dir }; # option to chdir there
70  
71 # create the git repository there
72 13 ▶ my $init_cmd = Git::Repository->version_lt('1.5.0.rc1') ? 'init-db' : 'init';
Branch: 1 branch
BranchTrueFalseTotal
'Git::Repository'->version_lt('1.5.0.rc1') ? : 0 13 13
73 13 ▶ my @cmd = $clone ? ( clone => @$clone, $dir ) : ( $init_cmd => @$init, $cwd );
Branch: 1 branch
BranchTrueFalseTotal
$clone ? : 2 11 13
74 13 Git::Repository->run( @cmd, $safe );
75  
76 # create the Git::Repository object
77 13 my $gitdir = Git::Repository->run( qw( rev-parse --git-dir ), $cwd );
78 13 return Git::Repository->new( git_dir => catdir( $dir, $gitdir ), $opts );
79 }
80  
81 15 1;
82  
83 __END__
↑ Summary blib/lib/Git/Repository/Command.pm »