blib/lib/Module/Setup/Test/Flavor.pm

filter: Statementstmt 100% 99 / 99 Branchbran 100% 14 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 18 / 18 Podpod 0.0% 0 / 7 totaltotal 94.9% 131 / 138 CC 13 SCAR 15.8
CC
13
Cov
100%
run_flavor_test
11.0
import
3.0
BEGIN
1.0
CRAP 4.9
« blib/lib/Module/Setup/Plugin/VC/Git.pm ↑ Summary blib/lib/Module/Setup/Plugin/Helper.pm »
1 package Module::Setup::Test::Flavor;
2 4 ▶use Module::Setup::Test::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
8 4 my $class = shift;
9 4 my $caller = caller;
10 4 my %args = @_;
11  
12 4 ▶ if ($args{for_test}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"for_test"}) 1 3 4
13 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ *ok = sub ($;$) { 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
16 1 ▶ *like = sub ($$;$) { 1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 ▶ *plan = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
18 }
19  
20 4 for my $func (qw/ run_flavor_test name flavor files file dirs options default_dialog dialog /) {
21 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 *{"$caller\::$func"} = \&{ $func };
23 }
24  
25 4 strict->import;
26 4 warnings->import;
27 }
28  
29 4 my $tests = {};
30 6 ▶sub name ($) {
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
31 6 $tests->{module} = shift;
32 }
33 3 ▶sub flavor ($) {
Subroutine flavor: called CC=1 SCAR=0.0
Pod undocumented
34 3 $tests->{flavor_class} = shift;
35 }
36  
37 7 ▶sub files (@) {
Subroutine files: called CC=1 SCAR=0.0
Pod undocumented
38 7 push @{ $tests->{files} }, @_;
39 }
40  
41 19 ▶sub file (@) {
Subroutine file: called CC=1 SCAR=0.0
Pod undocumented
42 19 my $file = shift;
43 19 push @{ $tests->{files} }, {
44 file => $file,
45 likes => [ @_ ],
46 };
47 }
48  
49 7 ▶sub dirs (@) {
Subroutine dirs: called CC=1 SCAR=0.0
Pod undocumented
50 7 push @{ $tests->{dirs} }, @_;
51 }
52  
53 1 ▶sub options ($) {
Subroutine options: called CC=1 SCAR=0.0
Pod undocumented
54 1 $tests->{options} = shift;
55 }
56  
57  
58 8 ▶sub run_flavor_test (&) {
Subroutine run_flavor_test: called CC=11 SCAR=24.0
Pod undocumented
59 8 my $code = shift;
60 8 $tests = {
61 module => 'Default',
62 files => [],
63 dirs => [],
64 options => {},
65 flavor_class => 'Default',
66 };
67 8 $code->();
68 8 my $module = delete $tests->{module};
69 8 my $options = delete $tests->{options};
70 8 $options->{target} = 1;
71 8 $options->{flavor_class} = delete $tests->{flavor_class};
72  
73 # test count
74 8 my $count = 2;
75 8 $count += scalar(@{ $tests->{dirs} });
76 8 for my $test (@{ $tests->{files} }) {
77 67 $count++;
78 67 ▶ if (ref($test) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $test eq "HASH") 19 48 67
79 19 $count += @{ $test->{likes} };
80 }
81 }
82  
83 8 plan tests => $count;
84 8 module_setup $options, $module;
85  
86 8 my $base_path = context->distribute->dist_path;
87 8 ok -d $base_path, 'base_path';
88  
89 8 my %files = map { $_ => 1 } File::Find::Rule->new->relative->in( context->distribute->dist_path );
90  
91 8 for my $path (@{ $tests->{dirs} }) {
92 18 ▶ Carp::croak "$path directory was missing" unless $files{$path};
Branch: 1 branch
BranchTrueFalseTotal
unless $files{$path} 1 17 18
93 17 my $dir = $base_path->subdir( split '/', $path );
94 17 ok -d $dir, "dir: $dir";
95 17 delete $files{$path};
96 }
97  
98 7 for my $data (@{ $tests->{files} }) {
99 67 my $likes = [];
100 67 my $path = $data;
101 67 ▶ if (ref($data) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "HASH") 19 48 67
102 19 $path = $data->{file};
103 19 $likes = $data->{likes};
104 }
105 67 ▶ Carp::croak "$path file was missing" unless $files{$path};
Branch: 1 branch
BranchTrueFalseTotal
unless $files{$path} 1 66 67
106 66 my $file = $base_path->file( split '/', $path );
107 66 ok -f $file, "file: $file";
108  
109 66 ▶ if (@{ $likes }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$likes;}) 19 47 66
110 19 my $slurp = $file->slurp;
111 19 for my $re (@{ $likes }) {
112 23 like $slurp, $re, "like $re";
113 }
114 }
115  
116 66 delete $files{$path};
117 }
118  
119 6 my $is_ok = !scalar(keys %files);
120 6 ok $is_ok, "is all ok";
121 6 ▶ unless ($is_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_ok) 2 4 6
122 2 my $files = join ', ', keys %files;
123 2 Carp::croak "missing tests for $files";
124 }
125  
126 4 return 1;
127 }
128  
129  
130 4 1;
131  
132 =head1 NAME
133  
134 Module::Setup::Test::Flavor - Test for flavor
135  
136 =cut
137  
138  
« blib/lib/Module/Setup/Plugin/VC/Git.pm ↑ Summary blib/lib/Module/Setup/Plugin/Helper.pm »