TestML1/Setup.pm

filter: Statementstmt 30.9% 22 / 71 Branchbran 3.3% 1 / 30 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 3 totaltotal 20.5% 30 / 146 CC 27 SCAR 58.7
CC
27
Cov
19%
setup
552.0
BEGIN
7.0
relative_path
6.0
CRAP 354.0
↑ Summary TestML1/Compiler.pm »
1 package TestML1::Setup;
2  
3 1 ▶use TestML1::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use TestML1();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=19.4
7 1 for (qw( YAML::XS IO::All Template::Toolkit::Simple )) {
8 3 ▶ if (not $ENV{PERL_ZILD_TEST_000_COMPILE_MODULES}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"PERL_ZILD_TEST_000_COMPILE_MODULES"}) 0 3 3
9 0 ▶ eval "use $_; 1" or die "TestML1::Setup requires $_:\n$@";
Branch: 1 branch
BranchTrueFalseTotal
eval "use $_; 1" or die "TestML1::Setup requires ${_}:\n$@" 0 0 0
10 }
11 }
12 }
13 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our @EXPORT = qw( setup );
18  
19 1 ▶use constant DEFAULT_TESTML_CONF => './t/testml.yaml';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub setup {
Subroutine setup: not called CC=23 SCAR=63.1
Pod undocumented
22 0 my ($testml_conf) = @_;
23 0 ▶ $testml_conf ||=
Condition0%0/5
$testml_conf ||= $ARGV[0] || "./t/testml.yaml"
l!l&&r!l&&!r
000
$ARGV[0] || './t/testml.yaml'
l!l
00
MC/DC0%0/2
$testml_conf ||= $ARGV[0] || "./t/testml.yaml"
$testml_conf $ARGV[0]
Truth table0%0/3
A ||= B
A= $testml_confB= $ARGV[0]
ABresult
1X1
011
000
24 $ARGV[0] ||
25 DEFAULT_TESTML_CONF;
26 0 ▶ die "TestML1 conf file '$testml_conf' not found"
Branch: 1 branch
BranchTrueFalseTotal
unless -f $testml_conf 0 0 0
27 unless -f $testml_conf;
28 0 ▶ die "TestML1 conf file must be .yaml"
Branch: 1 branch
BranchTrueFalseTotal
unless $testml_conf =~ /\.ya?ml$/ 0 0 0
29 unless $testml_conf =~ /\.ya?ml$/;
30 # File paths are relative to the yaml file location
31 0 my $base = File::Basename::dirname($testml_conf);
32 0 my $conf = YAML::XS::LoadFile($testml_conf);
33 my $source = $conf->{source_testml_dir}
34 0 ▶ or die "`testml_setup` requires 'source_testml_dir' key in '$testml_conf'";
Branch: 1 branch
BranchTrueFalseTotal
my $source = $conf->{"source_testml_dir"} or die "`testml_setup` requires 'source_testml_dir' key in '${testml_conf}'" 0 0 0
35 my $target = $conf->{local_testml_dir}
36 0 ▶ or die "`testml_setup` requires 'local_testml_dir' key in '$testml_conf'";
Branch: 1 branch
BranchTrueFalseTotal
my $target = $conf->{"local_testml_dir"} or die "`testml_setup` requires 'local_testml_dir' key in '${testml_conf}'" 0 0 0
37 0 ▶ my $tests = $conf->{test_file_dir} || '.';
Condition0%0/2
$conf->{'test_file_dir'} || '.'
l!l
00
MC/DC0%0/1
$conf->{'test_file_dir'} || '.'
$conf->{'test_file_dir'}
Truth table0%0/2
A
A= $conf->{'test_file_dir'}
Aresult
11
00
38 0 $source = abs_path("$base/$source");
39 0 $target = abs_path("$base/$target");
40 0 $tests = abs_path("$base/$tests");
41 0 ▶ die "'$source' directory does not exist"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $source 0 0 0
42 unless -e $source;
43 0 ▶ mkdir $target unless -d $target;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $target 0 0 0
44 0 ▶ mkdir $tests unless -d $tests;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $tests 0 0 0
45 0 ▶ my $template = $conf->{test_file_template} || '';
Condition0%0/2
$conf->{'test_file_template'} || ''
l!l
00
MC/DC0%0/1
$conf->{'test_file_template'} || ''
$conf->{'test_file_template'}
Truth table0%0/2
A
A= $conf->{'test_file_template'}
Aresult
11
00
46 0 ▶ my $skip = $conf->{exclude_testml_files} || [];
Condition0%0/2
$conf->{'exclude_testml_files'} || []
l!l
00
MC/DC0%0/1
$conf->{'exclude_testml_files'} || []
$conf->{'exclude_testml_files'}
Truth table0%0/2
A
A= $conf->{'exclude_testml_files'}
Aresult
11
00
47 my $files = $conf->{include_testml_files} ||
48 0 ▶ [map $_->filename, grep {"$_" =~ /\.tml$/} io($source)->all_files];
Condition0%0/2
$conf->{'include_testml_files'} || [map($_->filename, grep({"$_" =~ /\.tml$/;} io($source)->all_files))]
l!l
00
MC/DC0%0/1
$conf->{'include_testml_files'} || [map($_->filename, grep({"$_" =~ /\.tml$/;} io($source)->all_files))]
$conf->{'include_testml_files'}
Truth table0%0/2
A
A= $conf->{'include_testml_files'}
Aresult
11
00
49 0 for my $file (sort @$files) {
50 0 ▶ next if grep {$_ eq $file} @$skip;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $file;} @$skip 0 0 0
51 0 my $s = "$source/$file";
52 0 my $t = "$target/$file";
53 0 ▶ if (not -f $t or io($s)->all ne io($t)->all) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -f $t or io($s)->all ne io($t)->all) 0 0 0
Condition0%0/3
not -f $t or io($s)->all ne io($t)->all
l!l&&r!l&&!r
000
MC/DC0%0/2
not -f $t or io($s)->all ne io($t)->all
not -f $t io($s)->all ne io($t)->all
Truth table0%0/3
not(A) or B
A= not -f $tB= io($s)->all ne io($t)->all
ABresult
1X1
011
000
54 0 print "Copying ${\ relative_path($s)} to ${\ relative_path($t)}\n";
55 0 io($t)->print(io($s)->all);
56 }
57 0 ▶ if ($template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($template) 0 0 0
58 0 (my $test = $file) =~ s/\.tml$/.t/;
59 $test = $conf->{test_file_prefix} . $test
60 0 ▶ if $conf->{test_file_prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"test_file_prefix"} 0 0 0
61 0 $test = abs_path "$tests/$test";
62 0 my ($volume, $directories, $file) =
63 File::Spec->splitpath(relative_path($t, $base));
64 0 my $path = [
65 grep $_, File::Spec->splitdir($directories), $file
66 ];
67 0 my $hash = {
68 testml_setup_comment => testml_setup_comment($testml_conf),
69 file => relative_path($t, $base),
70 path => $path,
71 };
72 0 my $code = tt->data($hash)->render(\$template);
73 0 ▶ if (not -f $test or $code ne io($test)->all) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -f $test or $code ne io($test)->all) 0 0 0
Condition0%0/3
not -f $test or $code ne io($test)->all
l!l&&r!l&&!r
000
MC/DC0%0/2
not -f $test or $code ne io($test)->all
not -f $test $code ne io($test)->all
Truth table0%0/3
not(A) or B
A= not -f $testB= $code ne io($test)->all
ABresult
1X1
011
000
74 0 ▶ my $action = -f $test ? 'Updating' : 'Creating';
Branch: 1 branch
BranchTrueFalseTotal
-f $test ? : 0 0 0
75 0 print "$action test file '${\ relative_path($test)}'\n";
76 0 io($test)->print($code);
77 }
78 }
79 }
80 }
81  
82 0 ▶sub relative_path {
Subroutine relative_path: not called CC=2 SCAR=17.9
Pod undocumented
83 0 my ($path, $base) = @_;
84 0 ▶ $base ||= '.';
Condition0%0/2
$base ||= "."
l!l
00
MC/DC0%0/1
$base ||= "."
$base
Truth table0%0/2
A
A= $base
Aresult
11
00
85 0 $base = abs_path($base);
86 0 File::Spec->abs2rel($path, $base);
87 }
88  
89 0 ▶sub testml_setup_comment {
Subroutine testml_setup_comment: not called CC=1 SCAR=6.9
Pod undocumented
90 0 my ($testml_conf) = @_;
91 0 <<"...";
92 # DO NOT EDIT
93 #
94 # This file was generated by TestML1::Setup ($TestML1::VERSION)
95 #
96 # > perl -MTestML1::Setup -e setup $testml_conf
97 ...
98 }
99  
100 1 1;
↑ Summary TestML1/Compiler.pm »