blib/lib/Test/Rinci.pm

filter: Statementstmt 12.4% 30 / 241 Branchbran 0.0% 0 / 126 Conditioncond 0.0% 0 / 64 MC/DCmcdc 0.0% 0 / 38 Subroutinesub 34.7% 8 / 23 Podpod 66.6% 2 / 3 totaltotal 8.0% 40 / 495 CC 97 SCAR 53.3
CC
97
Cov
7%
__ANON__
420.0
_test_function_metadata
306.0
all_modules
272.0
CRAP 206.5
↑ Summary
1 ## no critic: ValuesAndExpressions::ProhibitCommaSeparatedStatements BuiltinFunctions::RequireBlockMap
2  
3 package Test::Rinci;
4  
5 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Test::More ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Perinci::Access::Perl 0.895;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
15 1 our $DATE = '2023-07-09'; # DATE
16 1 our $DIST = 'Test-Rinci'; # DIST
17 1 our $VERSION = '0.156'; # VERSION
18  
19 1 my $Test = Test::Builder->new;
20 # XXX is cache_size=0 really necessary?
21 1 my $Pa = Perinci::Access::Perl->new(load=>0, cache_size=>0);
22  
23 0 ▶sub import {
Subroutine import: not called CC=1 SCAR=3.3
24 0 my $self = shift;
25 0 my $caller = caller;
26 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 0 *{$caller.'::metadata_in_module_ok'} = \&metadata_in_module_ok;
28 0 *{$caller.'::metadata_in_all_modules_ok'} = \&metadata_in_all_modules_ok;
29  
30 0 $Test->exported_to($caller);
31 0 $Test->plan(@_);
32 }
33  
34 0 ▶sub _test_package_metadata {
Subroutine _test_package_metadata: not called CC=1 SCAR=6.9
35 0 my ($uri, $opts) = @_;
36 # XXX validate metadata
37 0 $Test->ok(1, "currently no test for package metadata");
38 }
39  
40 0 ▶sub _test_function_metadata {
Subroutine _test_function_metadata: not called CC=17 SCAR=57.2
41 0 my ($uri, $opts) = @_;
42 0 my $ok = 1;
43  
44 # XXX validate metadata
45  
46 0 my $res = $Pa->request(meta => $uri);
47 0 ▶ $Test->is_num($res->[0], 200, "wrap (load meta)") or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->is_num($res->[0], 200, "wrap (load meta)") or $ok = 0 0 0 0
48 0 ▶ if ($res->[0] != 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0] != 200) 0 0 0
49 0 $Test->diag("Can't meta $uri: $res->[0] - $res->[1]");
50 0 return 0;
51 }
52  
53 0 my $meta = $res->[2];
54  
55 TEST_ARGS:
56 {
57 0 require Data::Sah;
58 0 require Data::Dmp;
59 0 ▶ last unless $meta->{args};
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->{"args"} 0 0 0
60 0 for my $argname (sort keys %{ $meta->{args} }) {
61 0 my $argspec = $meta->{args}{$argname};
62  
63 # test that default values passes schema
64 0 ▶ if ($argspec->{schema} && exists($argspec->{default})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($argspec->{"schema"} and exists $argspec->{"default"}) 0 0 0
Condition0%0/3
$argspec->{"schema"} and exists $argspec->{"default"}
!ll&&!rl&&r
000
MC/DC0%0/2
$argspec->{"schema"} and exists $argspec->{"default"}
$argspec->{"schema"} exists $argspec->{"default"}
Truth table0%0/3
A and B
A= $argspec->{"schema"}B= exists $argspec->{"default"}
ABresult
0X0
100
111
65 my $v = Data::Sah::gen_validator(
66 0 $argspec->{schema}, {return_type=>'str+val'});
67 0 my $v_res = $v->($argspec->{default});
68 0 my ($err, $val) = @{$v_res};
69 0 ▶ $err //= '';
Condition0%0/2
$err //= ""
l!l
00
MC/DC0%0/1
$err //= ""
$err
Truth table0%0/2
A
A= $err
Aresult
11
00
70 #$Test->explain($v_res);
71 #use DD; dd $v_res;
72 $Test->is_eq(
73 $err, '',
74 "default value for arg '$argname' (".Data::Dmp::dmp($argspec->{default}).", coerced as ".Data::Dmp::dmp($val).
75 0 ▶ ") validates against schema (".Data::Dmp::dmp($argspec->{schema}).")") or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->is_eq($err, "", "default value for arg '${argname}' (" . Data::Dmp::dmp($argspec->{"default"}) . ', coerced as ' . Data::Dmp::dmp($val) . ') validates against schema (' . Data::Dmp::dmp($argspec->{"schema"}) . ')') or $ok = 0 0 0 0
76 }
77 }
78 }
79  
80 0 ▶ if ($opts->{test_function_examples} && $meta->{examples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"test_function_examples"} and $meta->{"examples"}) 0 0 0
Condition0%0/3
$opts->{"test_function_examples"} and $meta->{"examples"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"test_function_examples"} and $meta->{"examples"}
$opts->{"test_function_examples"} $meta->{"examples"}
Truth table0%0/3
A and B
A= $opts->{"test_function_examples"}B= $meta->{"examples"}
ABresult
0X0
100
111
81 0 my $i = 0;
82 0 for my $eg (@{ $meta->{examples} }) {
83 0 $i++;
84 0 ▶ next unless $eg->{test} // 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $eg->{"test"} // 1 0 0 0
Condition0%0/2
$eg->{"test"} // 1
l!l
00
MC/DC0%0/1
$eg->{"test"} // 1
$eg->{"test"}
Truth table0%0/2
A
A= $eg->{"test"}
Aresult
11
00
85 $Test->subtest(
86 "example #$i" .
87 ($eg->{name} ? " ($eg->{name})" :
88 ($eg->{summary} ? " ($eg->{summary})" : "")),
89 0 ▶ sub {
Subroutine __ANON__: not called CC=14 SCAR=53.5
90 0 my $args;
91 0 ▶ if ($eg->{args}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($eg->{'args'}) { } 0 0 0
elsif ($eg->{'argv'}) { } 0 0 0
elsif (defined $eg->{'src'}) { } 0 0 0
92 0 $args = $eg->{args};
93 } elsif ($eg->{argv}) {
94 0 require Perinci::Sub::GetArgs::Argv;
95 my $r = Perinci::Sub::GetArgs::Argv::get_args_from_argv(
96 0 argv => $eg->{argv}, meta => $meta,
97 );
98 0 ▶ unless ($r->[0] == 200) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->[0] == 200) 0 0 0
99 0 $Test->diag("Can't parse argv into args");
100 0 $ok = 0;
101 0 return;
102 }
103 0 $args = $r->[2];
104 } elsif (defined $eg->{src}) {
105 0 $Test->diag("Skipping example #$i for now (src)");
106 0 Test::More::ok(1);
107 0 return;
108 } else {
109 0 $Test->diag("Bad example #$i: No args/argv/src");
110 0 $ok = 0;
111 0 return;
112 }
113 0 my $r = $Pa->request(call => $uri, {args=>$args});
114 $Test->is_num($r->[0], $eg->{status} // 200, "status")
115 0 ▶ or do { $Test->diag($Test->explain($r)); $ok = 0 };
Branch: 1 branch
BranchTrueFalseTotal
$Test->is_num($r->[0], $eg->{"status"} // 200, "status") or do { $Test->diag($Test->explain($r)); $ok = 0 } 0 0 0
Condition0%0/2
$eg->{"status"} // 200
l!l
00
MC/DC0%0/1
$eg->{"status"} // 200
$eg->{"status"}
Truth table0%0/2
A
A= $eg->{"status"}
Aresult
11
00
116 0 ▶ my $actual_r = $meta->{_orig_result_naked} ? $r->[2] : $r;
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'_orig_result_naked'} ? : 0 0 0
117 0 ▶ if (exists $eg->{result}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $eg->{"result"}) 0 0 0
118 Test::More::is_deeply(
119 $actual_r, $eg->{result}, "result")
120 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
Test::More::is_deeply($actual_r, $eg->{"result"}, "result") or do { Test::More::diag(Test::More::explain($actual_r)); $ok = 0 } 0 0 0
121 0 Test::More::diag(
122 Test::More::explain($actual_r));
123 0 $ok = 0;
124 };
125 }
126 0 ▶ if (exists $eg->{env_result}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $eg->{"env_result"}) 0 0 0
127 Test::More::is_deeply(
128 $r, $eg->{env_result}, "env_result")
129 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
Test::More::is_deeply($r, $eg->{"env_result"}, "env_result") or do { Test::More::diag(Test::More::explain($r)); $ok = 0 } 0 0 0
130 0 Test::More::diag(
131 Test::More::explain($r));
132 0 $ok = 0;
133 };
134 }
135 0 ▶ if (exists $eg->{naked_result}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $eg->{"naked_result"}) 0 0 0
136 Test::More::is_deeply(
137 $r->[2], $eg->{naked_result}, "naked_result")
138 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
Test::More::is_deeply($r->[2], $eg->{"naked_result"}, "naked_result") or do { Test::More::diag(Test::More::explain($r->[2])); $ok = 0 } 0 0 0
139 0 Test::More::diag(
140 Test::More::explain($r->[2]));
141 0 $ok = 0;
142 };
143 }
144 0 ▶ }) or $ok = 0;
Branch: 3 branches
BranchTrueFalseTotal
$Test->subtest("example #$i" . ($eg->{"name"} ? qq[ ($eg->{"name"})] : ($eg->{"summary"} ? qq[ ($eg->{"summary"})] : "")), sub { my $args; if ($eg->{"args"}) { $args = $eg->{"args"}; } elsif ($eg->{"argv"}) { require Perinci::Sub::GetArgs::Argv; my $r = Perinci::Sub::GetArgs::Argv::get_args_from_argv("argv", $eg->{"argv"}, "meta", $meta); unless ($r->[0] == 200) { $Test->diag("Can't parse argv into args"); $ok = 0; return; } ; $args = $r->[2]; } elsif (defined $eg->{"src"}) { $Test->diag("Skipping example #$i for now (src)"); &Test::More::ok(1); return; } else { $Test->diag("Bad example #${i}: No args/argv/src"); $ok = 0; return; } ; my $r = $Pa->request("call", $uri, {"args", $args}); $Test->is_num($r->[0], $eg->{"status"} // 200, "status") or do { $Test->diag($Test->explain($r)); $ok = 0 }; my $actual_r = $meta->{"_orig_result_naked"} ? $r->[2] : $r; if (exists $eg->{"result"}) { Test::More::is_deeply($actual_r, $eg->{"result"}, "result") or do { Test::More::diag(Test::More::explain($actual_r)); $ok = 0 }; } ; if (exists $eg->{"env_result"}) { Test::More::is_deeply($r, $eg->{"env_result"}, "env_result") or do { Test::More::diag(Test::More::explain($r)); $ok = 0 }; } ; if (exists $eg->{"naked_result"}) { Test::More::is_deeply($r->[2], $eg->{"naked_result"}, "naked_result") or do { Test::More::diag(Test::More::explain($r->[2])); $ok = 0 }; } ; } ) or $ok = 0 0 0 0
$eg->{'name'} ? : 0 0 0
$eg->{'summary'} ? : 0 0 0
145 }
146 }
147 0 $ok;
148 }
149  
150 0 ▶sub _test_variable_metadata {
Subroutine _test_variable_metadata: not called CC=1 SCAR=6.9
151 0 my ($uri, $opts) = @_;
152 # XXX validate metadata
153 0 $Test->ok(1, "currently no test for variable metadata");
154 }
155  
156 0 ▶sub _set_option_defaults {
Subroutine _set_option_defaults: not called CC=12 SCAR=50.5
157 0 my $opts = shift;
158  
159 0 ▶ $opts->{load} //= 1;
Condition0%0/2
$opts->{"load"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"load"} //= 1
$opts->{"load"}
Truth table0%0/2
A
A= $opts->{"load"}
Aresult
11
00
160 0 ▶ $opts->{test_package_metadata} //= 1;
Condition0%0/2
$opts->{"test_package_metadata"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"test_package_metadata"} //= 1
$opts->{"test_package_metadata"}
Truth table0%0/2
A
A= $opts->{"test_package_metadata"}
Aresult
11
00
161 0 ▶ $opts->{include_packages} //= [];
Condition0%0/2
$opts->{"include_packages"} //= []
l!l
00
MC/DC0%0/1
$opts->{"include_packages"} //= []
$opts->{"include_packages"}
Truth table0%0/2
A
A= $opts->{"include_packages"}
Aresult
11
00
162 0 ▶ $opts->{exclude_packages} //= [];
Condition0%0/2
$opts->{"exclude_packages"} //= []
l!l
00
MC/DC0%0/1
$opts->{"exclude_packages"} //= []
$opts->{"exclude_packages"}
Truth table0%0/2
A
A= $opts->{"exclude_packages"}
Aresult
11
00
163 0 ▶ $opts->{test_function_metadata} //= 1;
Condition0%0/2
$opts->{"test_function_metadata"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"test_function_metadata"} //= 1
$opts->{"test_function_metadata"}
Truth table0%0/2
A
A= $opts->{"test_function_metadata"}
Aresult
11
00
164 0 ▶ $opts->{wrap_function} //= 1;
Condition0%0/2
$opts->{"wrap_function"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"wrap_function"} //= 1
$opts->{"wrap_function"}
Truth table0%0/2
A
A= $opts->{"wrap_function"}
Aresult
11
00
165 0 ▶ $opts->{test_function_examples} //= 1;
Condition0%0/2
$opts->{"test_function_examples"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"test_function_examples"} //= 1
$opts->{"test_function_examples"}
Truth table0%0/2
A
A= $opts->{"test_function_examples"}
Aresult
11
00
166 0 ▶ $opts->{include_functions} //= [];
Condition0%0/2
$opts->{"include_functions"} //= []
l!l
00
MC/DC0%0/1
$opts->{"include_functions"} //= []
$opts->{"include_functions"}
Truth table0%0/2
A
A= $opts->{"include_functions"}
Aresult
11
00
167 0 ▶ $opts->{exclude_functions} //= [];
Condition0%0/2
$opts->{"exclude_functions"} //= []
l!l
00
MC/DC0%0/1
$opts->{"exclude_functions"} //= []
$opts->{"exclude_functions"}
Truth table0%0/2
A
A= $opts->{"exclude_functions"}
Aresult
11
00
168 0 ▶ $opts->{test_variable_metadata} //= 1;
Condition0%0/2
$opts->{"test_variable_metadata"} //= 1
l!l
00
MC/DC0%0/1
$opts->{"test_variable_metadata"} //= 1
$opts->{"test_variable_metadata"}
Truth table0%0/2
A
A= $opts->{"test_variable_metadata"}
Aresult
11
00
169 0 ▶ $opts->{exclude_variables} //= [];
Condition0%0/2
$opts->{"exclude_variables"} //= []
l!l
00
MC/DC0%0/1
$opts->{"exclude_variables"} //= []
$opts->{"exclude_variables"}
Truth table0%0/2
A
A= $opts->{"exclude_variables"}
Aresult
11
00
170 }
171  
172 0 ▶sub metadata_in_module_ok {
Subroutine metadata_in_module_ok: not called CC=7 SCAR=40.3
Pod documented
173 0 my $module = shift;
174 0 ▶ my %opts = (@_ && (ref $_[0] eq "HASH")) ? %{(shift)} : ();
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_ ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
175 0 ▶ my $msg = @_ ? shift : "Rinci metadata on $module";
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
176 0 my $res;
177 0 my $ok = 1;
178  
179 0 _set_option_defaults(\%opts);
180  
181 0 my $has_tests;
182  
183 0 ▶ if ($opts{load}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"load"}) 0 0 0
184 0 my $modulep = $module; $modulep =~ s!::!/!g; $modulep .= ".pm";
185 0 require $modulep;
186 }
187  
188 $Test->subtest(
189 $msg,
190 0 ▶ sub {
Subroutine __ANON__: not called CC=20 SCAR=60.4
191 0 my $uri = "pl:/$module/"; $uri =~ s!::!/!g;
192  
193 0 ▶ if ($opts{test_package_metadata} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'test_package_metadata'} and not grep({$_ eq $module;} @{$opts{'exclude_packages'};})) { } 0 0 0
Condition0%0/3
$opts{"test_package_metadata"} and not grep({$_ eq $module;} @{$opts{"exclude_packages"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"test_package_metadata"} and not grep({$_ eq $module;} @{$opts{"exclude_packages"};})
$opts{"test_package_metadata"} not grep({$_ eq $module;} @{$opts{"exclude_packages"};})
Truth table0%0/3
A and not(B)
A= $opts{"test_package_metadata"}B= not grep({$_ eq $module;} @{$opts{"exclude_packages"};})
ABresult
0X0
100
111
194 0 !(grep { $_ eq $module } @{ $opts{exclude_packages} })) {
195 0 $res = $Pa->request(meta => $uri);
196 0 ▶ if ($res->[0] != 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0] != 200) 0 0 0
197 0 ▶ $Test->ok(0, "load package metadata") or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->ok(0, "load package metadata") or $ok = 0 0 0 0
198 0 $Test->diag("Can't meta => $uri: $res->[0] - $res->[1]");
199 0 return 0;
200 }
201 0 $has_tests++;
202 $Test->subtest(
203 0 ▶ "package metadata $module", sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
204 0 _test_package_metadata($uri, \%opts);
205 0 ▶ }) or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->subtest("package metadata $module", sub { _test_package_metadata($uri, \%opts); } ) or $ok = 0 0 0 0
206 } else {
207 0 $Test->diag("Skipped testing package metadata $module");
208 }
209  
210 return unless $opts{test_function_metadata} ||
211 0 ▶ $opts{test_variable_metadata};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"test_function_metadata"} or $opts{"test_variable_metadata"} 0 0 0
Condition0%0/3
$opts{"test_function_metadata"} or $opts{"test_variable_metadata"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"test_function_metadata"} or $opts{"test_variable_metadata"}
$opts{"test_function_metadata"} $opts{"test_variable_metadata"}
Truth table0%0/3
A or B
A= $opts{"test_function_metadata"}B= $opts{"test_variable_metadata"}
ABresult
1X1
011
000
212  
213 0 $res = $Pa->request(list => $uri, {detail=>1});
214 0 ▶ $Test->ok($res->[0] == 200, "list entities") or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->ok($res->[0] == 200, "list entities") or $ok = 0 0 0 0
215 0 ▶ if ($res->[0] != 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0] != 200) 0 0 0
216 0 $Test->diag("Can't list => $uri: $res->[0] - $res->[1]");
217 0 return 0;
218 }
219 0 for my $e (@{$res->[2]}) {
220 0 my $en = $e->{uri};
221 0 my $fen = "$en (in package $module)";
222 0 ▶ if ($e->{type} eq 'function') {
Branch: 2 branches
BranchTrueFalseTotal
if ($e->{'type'} eq 'function') { } 0 0 0
elsif ($e->{'type'} eq 'variable') { } 0 0 0
223 0 ▶ if ($opts{test_function_metadata} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'test_function_metadata'} and not grep({$_ eq $en;} @{$opts{'exclude_functions'};})) { } 0 0 0
Condition0%0/3
$opts{"test_function_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_functions"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"test_function_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_functions"};})
$opts{"test_function_metadata"} not grep({$_ eq $en;} @{$opts{"exclude_functions"};})
Truth table0%0/3
A and not(B)
A= $opts{"test_function_metadata"}B= not grep({$_ eq $en;} @{$opts{"exclude_functions"};})
ABresult
0X0
100
111
224 0 !(grep { $_ eq $en } @{ $opts{exclude_functions} })) {
225 0 $has_tests++;
226 $Test->subtest(
227 0 ▶ "function metadata $fen", sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
228 0 _test_function_metadata("$uri$e->{uri}",
229 \%opts);
230 0 ▶ }) or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->subtest("function metadata $fen", sub { _test_function_metadata(qq[$uri$e->{"uri"}], \%opts); } ) or $ok = 0 0 0 0
231 } else {
232 0 $Test->diag("Skipped function metadata $fen");
233 }
234 } elsif ($e->{type} eq 'variable') {
235 0 ▶ if ($opts{test_variable_metadata} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'test_variable_metadata'} and not grep({$_ eq $en;} @{$opts{'exclude_variables'};})) { } 0 0 0
Condition0%0/3
$opts{"test_variable_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_variables"};})
!ll&&!rl&&r
000
MC/DC0%0/2
$opts{"test_variable_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_variables"};})
$opts{"test_variable_metadata"} not grep({$_ eq $en;} @{$opts{"exclude_variables"};})
Truth table0%0/3
A and not(B)
A= $opts{"test_variable_metadata"}B= not grep({$_ eq $en;} @{$opts{"exclude_variables"};})
ABresult
0X0
100
111
236 0 !(grep { $_ eq $en } @{ $opts{exclude_variables} })) {
237 0 $has_tests++;
238 $Test->subtest(
239 0 ▶ "variable metadata $fen", sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
240 0 _test_variable_metadata("$uri$e->{uri}",
241 \%opts);
242 0 ▶ }) or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->subtest("variable metadata $fen", sub { _test_variable_metadata(qq[$uri$e->{"uri"}], \%opts); } ) or $ok = 0 0 0 0
243 } else {
244 0 $Test->diag("Skipped variable metadata $fen");
245 }
246 } else {
247 $Test->diag("Skipped $e->{type} metadata $fen")
248 0 ▶ unless $e->{type} eq 'package';
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"type"} eq "package" 0 0 0
249 0 next;
250 }
251 } # for list entry
252 } # subtest
253 0 ▶ ) or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->subtest($msg, sub { my $uri = "pl:/$module/"; $uri =~ s[::][/]g; if ($opts{"test_package_metadata"} and not grep({$_ eq $module;} @{$opts{"exclude_packages"};})) { $res = $Pa->request("meta", $uri); if ($res->[0] != 200) { $Test->ok(0, "load package metadata") or $ok = 0; $Test->diag("Can't meta => ${uri}: $res->[0] - $res->[1]"); return 0; } ; ++$has_tests; $Test->subtest("package metadata $module", sub { _test_package_metadata($uri, \%opts); } ) or $ok = 0; } else { $Test->diag("Skipped testing package metadata $module"); } ; return unless $opts{"test_function_metadata"} or $opts{"test_variable_metadata"}; $res = $Pa->request("list", $uri, {"detail", 1}); $Test->ok($res->[0] == 200, "list entities") or $ok = 0; if ($res->[0] != 200) { $Test->diag("Can't list => ${uri}: $res->[0] - $res->[1]"); return 0; } ; foreach my $e (@{$$res[2];}) { my $en = $e->{"uri"}; my $fen = "$en (in package $module)"; if ($e->{"type"} eq "function") { if ($opts{"test_function_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_functions"};})) { ++$has_tests; $Test->subtest("function metadata $fen", sub { _test_function_metadata(qq[$uri$e->{"uri"}], \%opts); } ) or $ok = 0; } else { $Test->diag("Skipped function metadata $fen"); } ; } elsif ($e->{"type"} eq "variable") { if ($opts{"test_variable_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_variables"};})) { ++$has_tests; $Test->subtest("variable metadata $fen", sub { _test_variable_metadata(qq[$uri$e->{"uri"}], \%opts); } ) or $ok = 0; } else { $Test->diag("Skipped variable metadata $fen"); } ; } else { $Test->diag(qq[Skipped $e->{"type"} metadata $fen]) unless $e->{"type"} eq "package"; next; } ; } ; } ) or $ok = 0 0 0 0
254  
255 0 ▶ unless ($has_tests) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_tests) 0 0 0
256 0 $Test->ok(1);
257 0 $Test->diag("No metadata to test");
258 }
259  
260 0 $ok;
261 }
262  
263 # BEGIN copy-pasted from Test::Pod::Coverage, with a bit modification
264  
265 0 ▶sub all_modules {
Subroutine all_modules: not called CC=16 SCAR=56.1
Pod undocumented
266 0 ▶ my @starters = @_ ? @_ : _starting_points();
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
267 0 my %starters = map {$_,1} @starters;
268  
269 0 my @queue = @starters;
270  
271 0 my @modules;
272 0 ▶ while ( @queue ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@queue) 0 0 0
273 0 my $file = shift @queue;
274 0 ▶ if ( -d $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 0 0 0
275 0 local *DH;
276 0 ▶ opendir DH, $file or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir DH, $file or next 0 0 0
277 0 my @newfiles = readdir DH;
278 0 closedir DH;
279  
280 0 @newfiles = File::Spec->no_upwards( @newfiles );
281 0 ▶ @newfiles = grep { $_ ne "CVS" && $_ ne ".svn" } @newfiles;
Condition0%0/3
$_ ne 'CVS' && $_ ne '.svn'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne 'CVS' && $_ ne '.svn'
$_ ne 'CVS' $_ ne '.svn'
Truth table0%0/3
A && B
A= $_ ne 'CVS'B= $_ ne '.svn'
ABresult
0X0
100
111
282  
283 0 push @queue, map "$file/$_", @newfiles;
284 }
285 0 ▶ if ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 0 0 0
286 0 ▶ next unless $file =~ /\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.pm$/ 0 0 0
287  
288 0 my @parts = File::Spec->splitdir( $file );
289 0 ▶ shift @parts if @parts && exists $starters{$parts[0]};
Branch: 1 branch
BranchTrueFalseTotal
if @parts and exists $starters{$parts[0]} 0 0 0
Condition0%0/3
@parts and exists $starters{$parts[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
@parts and exists $starters{$parts[0]}
@parts exists $starters{$parts[0]}
Truth table0%0/3
A and B
A= @partsB= exists $starters{$parts[0]}
ABresult
0X0
100
111
290 0 ▶ shift @parts if @parts && $parts[0] eq "lib";
Branch: 1 branch
BranchTrueFalseTotal
if @parts and $parts[0] eq "lib" 0 0 0
Condition0%0/3
@parts and $parts[0] eq "lib"
!ll&&!rl&&r
000
MC/DC0%0/2
@parts and $parts[0] eq "lib"
@parts $parts[0] eq "lib"
Truth table0%0/3
A and B
A= @partsB= $parts[0] eq "lib"
ABresult
0X0
100
111
291 0 ▶ $parts[-1] =~ s/\.pm$// if @parts;
Branch: 1 branch
BranchTrueFalseTotal
if @parts 0 0 0
292  
293 # Untaint the parts
294 0 for ( @parts ) {
295 0 ▶ if ( /^([a-zA-Z0-9_\.\-]*)$/ && ($_ eq $1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^([a-zA-Z0-9_\.\-]*)$/ and $_ eq $1) { } 0 0 0
Condition0%0/3
/^([a-zA-Z0-9_\.\-]*)$/ and $_ eq $1
!ll&&!rl&&r
000
MC/DC0%0/2
/^([a-zA-Z0-9_\.\-]*)$/ and $_ eq $1
/^([a-zA-Z0-9_\.\-]*)$/ $_ eq $1
Truth table0%0/3
A and B
A= /^([a-zA-Z0-9_\.\-]*)$/B= $_ eq $1
ABresult
0X0
100
111
296 0 $_ = $1; # Untaint the original
297 }
298 else {
299 0 die qq{Invalid and untaintable filename "$file"!};
300 }
301 }
302 0 my $module = join( "::", grep {length} @parts );
303 0 push( @modules, $module );
304 }
305 } # while
306  
307 0 return @modules;
308 }
309  
310 0 ▶sub _starting_points {
Subroutine _starting_points: not called CC=2 SCAR=17.9
311 0 ▶ return 'blib' if -e 'blib';
Branch: 1 branch
BranchTrueFalseTotal
if -e "blib" 0 0 0
312 0 return 'lib';
313 }
314  
315 # END copy-pasted from Test::Pod::Coverage
316  
317 0 ▶sub metadata_in_all_modules_ok {
Subroutine metadata_in_all_modules_ok: not called CC=9 SCAR=45.0
Pod documented
318 0 ▶ my $opts = (@_ && (ref $_[0] eq "HASH")) ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_ ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
319 0 my $msg = shift;
320 0 my $ok = 1;
321  
322 0 _set_option_defaults($opts);
323  
324 0 my @starters = _starting_points();
325 0 local @INC = (@starters, @INC);
326  
327 0 $Test->plan(tests => 1);
328  
329 0 my @include_packages;
330 {
331 0 my $val = delete $opts->{include_packages};
332 0 ▶ last unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
333 0 for my $mod (@$val) {
334 0 push @include_packages, $mod;
335 }
336 }
337 0 my @exclude_packages;
338 {
339 0 my $val = delete $opts->{exclude_packages};
340 0 ▶ last unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
341 0 for my $mod (@$val) {
342 0 push @exclude_packages, $mod;
343 }
344 }
345  
346 0 my @modules = all_modules(@starters);
347 0 ▶ if (@modules) {
Branch: 1 branch
BranchTrueFalseTotal
if (@modules) { } 0 0 0
348 $Test->subtest(
349 "Rinci metadata on all dist's modules",
350 0 ▶ sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
351 0 for my $module (@modules) {
352 0 ▶ if (@include_packages) {
Branch: 1 branch
BranchTrueFalseTotal
if (@include_packages) 0 0 0
353 0 ▶ next unless grep { $module eq $_ } @include_packages;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$module eq $_;} @include_packages 0 0 0
354 }
355 0 ▶ if (@exclude_packages) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude_packages) 0 0 0
356 0 ▶ next if grep { $module eq $_ } @exclude_packages;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$module eq $_;} @exclude_packages 0 0 0
357 }
358 #$log->infof("Processing module %s ...", $module);
359 0 ▶ my $thismsg = defined $msg ? $msg :
Branch: 1 branch
BranchTrueFalseTotal
defined $msg ? : 0 0 0
360 "Rinci metadata on $module";
361 0 ▶ my $thisok = metadata_in_module_ok(
Branch: 1 branch
BranchTrueFalseTotal
my $thisok = metadata_in_module_ok($module, $opts, $thismsg) or $ok = 0 0 0 0
362 $module, $opts, $thismsg)
363 or $ok = 0;
364 }
365 }
366 0 ▶ ) or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
$Test->subtest("Rinci metadata on all dist's modules", sub { foreach my $module (@modules) { if (@include_packages) { next unless grep {$module eq $_;} @include_packages; } ; if (@exclude_packages) { next if grep {$module eq $_;} @exclude_packages; } ; my $thismsg = defined $msg ? $msg : "Rinci metadata on $module"; my $thisok = metadata_in_module_ok($module, $opts, $thismsg) or $ok = 0; } ; } ) or $ok = 0 0 0 0
367 } else {
368 0 $Test->ok(1, "No modules found.");
369 }
370 0 $ok;
371 }
372  
373 1 1;
374 # ABSTRACT: Test Rinci metadata
375  
376 __END__
↑ Summary