blib/lib/Shipwright/Test.pm

filter: Statementstmt 45.4% 40 / 88 Branchbran 6.2% 2 / 32 Conditioncond 16.1% 5 / 31 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 54.1% 13 / 24 Podpod 100% 14 / 14 totaltotal 35.5% 74 / 208 CC 29 SCAR 28.4
CC
29
Cov
31%
has_svk
42.0
has_svn
42.0
test_cmd
42.0
CRAP 17.1
« blib/lib/Shipwright/Script/Maintain.pm ↑ Summary blib/lib/Shipwright/Source/SVK.pm »
1 package Shipwright::Test;
2  
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use IPC::Cmd qw/can_run/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use File::Spec::Functions qw/catfile catdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Cwd 'getcwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 our @EXPORT =
14 qw/has_svk has_svn skip_svk skip_svn create_fs_repo create_svk_repo
15 create_svn_repo devel_cover_enabled test_cmd skip_git create_git_repo/;
16  
17 =head1 NAME
18  
19 Shipwright::Test - Test
20  
21 =head1 SYNOPSIS
22  
23 use Shipwright::Test;
24  
25 =head2 has_svk
26  
27 check to see if we have svk or not, also limit the svk version to be 2+.
28 in fact, it also checks svnadmin since we need that to create repo for svk.
29  
30 =cut
31  
32 0 ▶sub has_svk {
Subroutine has_svk: not called CC=6 SCAR=37.4
Pod documented
33 0 ▶ if ( can_run( $ENV{'SHIPWRIGHT_SVK'} )
Branch: 1 branch
BranchTrueFalseTotal
if (can_run($ENV{"SHIPWRIGHT_SVK"}) and can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')) 0 0 0
Condition0%0/3
can_run($ENV{"SHIPWRIGHT_SVK"}) and can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
!ll&&!rl&&r
000
MC/DC0%0/2
can_run($ENV{"SHIPWRIGHT_SVK"}) and can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
can_run($ENV{"SHIPWRIGHT_SVK"}) can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
Truth table0%0/3
A and B
A= can_run($ENV{"SHIPWRIGHT_SVK"})B= can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
ABresult
0X0
100
111
34 && can_run( $ENV{'SHIPWRIGHT_SVN'} . 'admin' ) )
35 {
36 my $out =
37 0 run_cmd( [ $ENV{'SHIPWRIGHT_SVK'}, '--version' ], 1 );
38 0 ▶ if ( $out && $out =~ /version v(\d)\./i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out and $out =~ /version v(\d)\./i) 0 0 0
Condition0%0/3
$out and $out =~ /version v(\d)\./i
!ll&&!rl&&r
000
MC/DC0%0/2
$out and $out =~ /version v(\d)\./i
$out $out =~ /version v(\d)\./i
Truth table0%0/3
A and B
A= $outB= $out =~ /version v(\d)\./i
ABresult
0X0
100
111
39 0 ▶ return 1 if $1 >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $1 >= 2 0 0 0
40 }
41 }
42 0 return;
43 }
44  
45 =head2 has_svn
46  
47 check to see if we have svn or not, also limit the svn version to be 1.4+.
48 in fact, it also checks svnadmin since we need that to create repo.
49  
50 =cut
51  
52 0 ▶sub has_svn {
Subroutine has_svn: not called CC=6 SCAR=37.4
Pod documented
53 0 ▶ if ( can_run( $ENV{'SHIPWRIGHT_SVN'} )
Branch: 1 branch
BranchTrueFalseTotal
if (can_run($ENV{"SHIPWRIGHT_SVN"}) and can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')) 0 0 0
Condition0%0/3
can_run($ENV{"SHIPWRIGHT_SVN"}) and can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
!ll&&!rl&&r
000
MC/DC0%0/2
can_run($ENV{"SHIPWRIGHT_SVN"}) and can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
can_run($ENV{"SHIPWRIGHT_SVN"}) can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
Truth table0%0/3
A and B
A= can_run($ENV{"SHIPWRIGHT_SVN"})B= can_run($ENV{"SHIPWRIGHT_SVN"} . 'admin')
ABresult
0X0
100
111
54 && can_run( $ENV{'SHIPWRIGHT_SVN'} . 'admin' ) )
55 {
56 my $out =
57 0 run_cmd( [ $ENV{'SHIPWRIGHT_SVN'}, '--version' ], 1 );
58 0 ▶ if ( $out && $out =~ /version 1\.(\d)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out and $out =~ /version 1\.(\d)/i) 0 0 0
Condition0%0/3
$out and $out =~ /version 1\.(\d)/i
!ll&&!rl&&r
000
MC/DC0%0/2
$out and $out =~ /version 1\.(\d)/i
$out $out =~ /version 1\.(\d)/i
Truth table0%0/3
A and B
A= $outB= $out =~ /version 1\.(\d)/i
ABresult
0X0
100
111
59 0 ▶ return 1 if $1 >= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $1 >= 4 0 0 0
60 }
61 }
62 0 return;
63 }
64  
65 =head2 has_git
66  
67 check to see if we have git or not
68  
69 =cut
70  
71 0 ▶sub has_git {
Subroutine has_git: not called CC=2 SCAR=17.9
Pod documented
72 0 ▶ if ( can_run( $ENV{'SHIPWRIGHT_GIT'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (can_run($ENV{"SHIPWRIGHT_GIT"})) 0 0 0
73 0 return 1;
74 }
75 0 return;
76 }
77  
78 =head2 skip_svn
79  
80 if skip svn when test.
81 skip test svn unless env SHIPWRIGHT_TEST_SVN is set to true and
82 the system has svn
83  
84 =cut
85  
86 2 ▶sub skip_svn {
Subroutine skip_svn: called CC=3 SCAR=13.1
Pod documented
87 2 ▶ return if $ENV{'SHIPWRIGHT_TEST_SVN'} && has_svn();
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SHIPWRIGHT_TEST_SVN"} and has_svn() 0 2 2
Condition33%1/3
$ENV{"SHIPWRIGHT_TEST_SVN"} and has_svn()
!ll&&!rl&&r
200
MC/DC0%0/2
$ENV{"SHIPWRIGHT_TEST_SVN"} and has_svn()
$ENV{"SHIPWRIGHT_TEST_SVN"} has_svn()
Truth table33%1/3
A and B
A= $ENV{"SHIPWRIGHT_TEST_SVN"}B= has_svn()
ABresult
0X0
100
111
88 2 return 1;
89 }
90  
91 =head2 skip_svk
92  
93 if skip svk when test.
94 skip test svk unless env SHIPWRIGHT_TEST_SVK is set to true and
95 the system has svk
96  
97 =cut
98  
99 1 ▶sub skip_svk {
Subroutine skip_svk: called CC=3 SCAR=13.1
Pod documented
100 1 ▶ return if $ENV{'SHIPWRIGHT_TEST_SVK'} && has_svk();
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SHIPWRIGHT_TEST_SVK"} and has_svk() 0 1 1
Condition33%1/3
$ENV{"SHIPWRIGHT_TEST_SVK"} and has_svk()
!ll&&!rl&&r
100
MC/DC0%0/2
$ENV{"SHIPWRIGHT_TEST_SVK"} and has_svk()
$ENV{"SHIPWRIGHT_TEST_SVK"} has_svk()
Truth table33%1/3
A and B
A= $ENV{"SHIPWRIGHT_TEST_SVK"}B= has_svk()
ABresult
0X0
100
111
101 1 return 1;
102 }
103  
104 =head2 skip_git
105  
106 if skip git when test.
107 skip test git unless env SHIPWRIGHT_TEST_GIT is set to true and
108 the system has git
109  
110 =cut
111  
112 0 ▶sub skip_git {
Subroutine skip_git: not called CC=3 SCAR=24.8
Pod documented
113 0 ▶ return if $ENV{'SHIPWRIGHT_TEST_GIT'} && has_git();
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SHIPWRIGHT_TEST_GIT"} and has_git() 0 0 0
Condition0%0/3
$ENV{"SHIPWRIGHT_TEST_GIT"} and has_git()
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"SHIPWRIGHT_TEST_GIT"} and has_git()
$ENV{"SHIPWRIGHT_TEST_GIT"} has_git()
Truth table0%0/3
A and B
A= $ENV{"SHIPWRIGHT_TEST_GIT"}B= has_git()
ABresult
0X0
100
111
114 0 return 1;
115 }
116  
117  
118 =head2 create_fs_repo
119  
120 create a repo for fs
121  
122 =cut
123  
124 2 ▶sub create_fs_repo {
Subroutine create_fs_repo: called CC=1 SCAR=0.0
Pod documented
125 2 return tempdir( 'shipwright_test_fs_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
126 }
127  
128 =head2 create_git_repo
129  
130 create a repo for git
131  
132 =cut
133  
134 0 ▶sub create_git_repo {
Subroutine create_git_repo: not called CC=1 SCAR=6.9
Pod documented
135 0 my $dir = tempdir( 'shipwright_test_git_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
136 0 my $cwd = getcwd();
137 0 chdir $dir;
138 0 run_cmd( [$ENV{'SHIPWRIGHT_GIT'}, 'init', '--bare' ] );
139 0 chdir $cwd;
140 0 return "file://$dir";
141 }
142  
143 =head2 create_svk_repo
144  
145 create a repo for svk, will set $ENV{SVKROOT} accordingly.
146 return $ENV{SVKROOT}
147  
148 =cut
149  
150 0 ▶sub create_svk_repo {
Subroutine create_svk_repo: not called CC=1 SCAR=6.9
Pod documented
151 $ENV{SVKROOT} =
152 0 tempdir( 'shipwright_test_svk_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
153 0 my $svk_root_local = catdir( $ENV{SVKROOT}, 'local' );
154 0 system("$ENV{SHIPWRIGHT_SVN}admin create $svk_root_local");
155 0 system("$ENV{SHIPWRIGHT_SVK} depotmap -i");
156 0 return $ENV{SVKROOT};
157 }
158  
159 =head2 create_svn_repo
160  
161 create a svn repo.
162 return the repo's uri, like file:///tmp/foo
163  
164 =cut
165  
166 0 ▶sub create_svn_repo {
Subroutine create_svn_repo: not called CC=2 SCAR=17.9
Pod documented
167 0 my $repo =
168 tempdir( 'shipwright_test_svn_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
169 0 ▶ system("$ENV{SHIPWRIGHT_SVN}admin create $repo")
Branch: 1 branch
BranchTrueFalseTotal
system qq[$ENV{"SHIPWRIGHT_SVN"}admin create $repo] and confess_or_die("create repo failed: $!") 0 0 0
170 && confess_or_die "create repo failed: $!";
171 0 return "file://$repo";
172 }
173  
174 =head2 init
175  
176 init something, like log
177  
178 =cut
179  
180 7 ▶sub init {
Subroutine init: called CC=4 SCAR=14.5
Pod documented
181 7 require Shipwright::Logger;
182 7 Shipwright::Logger->new( log_level => 'FATAL' );
183 7 ▶ $ENV{'SHIPWRIGHT_SVK'} ||= 'svk';
Condition50%1/2
$ENV{"SHIPWRIGHT_SVK"} ||= "svk"
l!l
70
MC/DC0%0/1
$ENV{"SHIPWRIGHT_SVK"} ||= "svk"
$ENV{"SHIPWRIGHT_SVK"}
Truth table50%1/2
A
A= $ENV{"SHIPWRIGHT_SVK"}
Aresult
11
00
184 7 ▶ $ENV{'SHIPWRIGHT_SVN'} ||= 'svn';
Condition50%1/2
$ENV{"SHIPWRIGHT_SVN"} ||= "svn"
l!l
70
MC/DC0%0/1
$ENV{"SHIPWRIGHT_SVN"} ||= "svn"
$ENV{"SHIPWRIGHT_SVN"}
Truth table50%1/2
A
A= $ENV{"SHIPWRIGHT_SVN"}
Aresult
11
00
185 7 ▶ $ENV{'SHIPWRIGHT_GIT'} ||= 'git';
Condition50%1/2
$ENV{"SHIPWRIGHT_GIT"} ||= "git"
l!l
70
MC/DC0%0/1
$ENV{"SHIPWRIGHT_GIT"} ||= "git"
$ENV{"SHIPWRIGHT_GIT"}
Truth table50%1/2
A
A= $ENV{"SHIPWRIGHT_GIT"}
Aresult
11
00
186 7 $ENV{'SHIPWRIGHT_USER_ROOT'} =
187 tempdir( 'shipwright_user_root_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
188 }
189  
190 =head2 shipwright_bin
191  
192 return the path of bin/shipwright
193  
194 =cut
195  
196 0 ▶sub shipwright_bin {
Subroutine shipwright_bin: not called CC=2 SCAR=10.1
Pod documented
197 13 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
198  
199 # so, we'd better add lib to PERL5LIB before run shipwright.
200 # what? you don't want to run shipwright?!!
201 # then what did you call this method for?
202  
203 0 ▶ $ENV{PERL5LIB} = 'lib:' . $ENV{PERL5LIB} unless $ENV{PERL5LIB} =~ /^lib:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"PERL5LIB"} =~ /^lib:/ 0 0 0
204 0 return catfile( 'bin', 'shipwright' );
205 }
206  
207 =head2 devel_cover_enabled
208  
209 return true if -MDevel::Cover
210  
211 =cut
212  
213 0 ▶sub devel_cover_enabled {
Subroutine devel_cover_enabled: not called CC=1 SCAR=6.9
Pod documented
214 0 return $INC{'Devel/Cover.pm'};
215 }
216  
217 =head2 test_cmd
218  
219 a simple wrap for test cmd like create, list ...
220  
221 =cut
222  
223 0 ▶sub test_cmd {
Subroutine test_cmd: not called CC=6 SCAR=37.4
Pod documented
224 0 my $cmd = shift;
225 0 my $exp = shift;
226 0 ▶ my $msg = shift || "@$cmd out";
Condition0%0/2
shift() || "@$cmd out"
l!l
00
MC/DC0%0/1
shift() || "@$cmd out"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
227 0 my $exp_err = shift;
228 0 ▶ my $msg_err = shift || "@$cmd err";
Condition0%0/2
shift() || "@$cmd err"
l!l
00
MC/DC0%0/1
shift() || "@$cmd err"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
229  
230 0 ▶ unshift @$cmd, $^X, '-MDevel::Cover' if devel_cover_enabled;
Branch: 1 branch
BranchTrueFalseTotal
if devel_cover_enabled() 0 0 0
231  
232 0 require Test::More;
233 0 my ( $out, $err ) = run_cmd( $cmd, 1 ); # ingnore failure
234  
235 0 ▶ _test_cmd( $out, $exp, $msg ) if defined $exp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exp 0 0 0
236 0 ▶ _test_cmd( $err, $exp_err, $msg_err ) if defined $exp_err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exp_err 0 0 0
237 }
238  
239 0 ▶sub _test_cmd {
Subroutine _test_cmd: not called CC=2 SCAR=17.9
240 0 my $out = shift;
241 0 my $exp = shift;
242 0 my $msg = shift;
243  
244 0 ▶ if ( ref $exp eq 'Regexp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $exp eq 'Regexp') { } 0 0 0
245 0 Test::More::like( $out, $exp, $msg );
246 }
247 else {
248 0 Test::More::is( $out, $exp, $msg );
249 }
250 }
251  
252 13 1;
253  
254 __END__
« blib/lib/Shipwright/Script/Maintain.pm ↑ Summary blib/lib/Shipwright/Source/SVK.pm »