| 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
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($res->[0] != 200) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$argspec->{"schema"} and exists $argspec->{"default"}
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"}
| |||||||||||||||||||||||||||||
| 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 //= ""
MC/DC0%0/1
$err //= ""
$err
Truth table0%0/2
A
A= $err
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($opts->{test_function_examples} && $meta->{examples}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts->{"test_function_examples"} and $meta->{"examples"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/2
$eg->{"test"} // 1
MC/DC0%0/1
$eg->{"test"} // 1
$eg->{"test"}
Truth table0%0/2
A
A= $eg->{"test"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/2
$eg->{"status"} // 200
MC/DC0%0/1
$eg->{"status"} // 200
$eg->{"status"}
Truth table0%0/2
A
A= $eg->{"status"}
| |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $actual_r = $meta->{_orig_result_naked} ? $r->[2] : $r; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (exists $eg->{result}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | Test::More::is_deeply( | ||||||||||||||||||||||||||||
| 119 | $actual_r, $eg->{result}, "result") | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 127 | Test::More::is_deeply( | ||||||||||||||||||||||||||||
| 128 | $r, $eg->{env_result}, "env_result") | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 136 | Test::More::is_deeply( | ||||||||||||||||||||||||||||
| 137 | $r->[2], $eg->{naked_result}, "naked_result") | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$opts->{"load"} //= 1
$opts->{"load"}
Truth table0%0/2
A
A= $opts->{"load"}
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $opts->{test_package_metadata} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"test_package_metadata"} //= 1
MC/DC0%0/1
$opts->{"test_package_metadata"} //= 1
$opts->{"test_package_metadata"}
Truth table0%0/2
A
A= $opts->{"test_package_metadata"}
| |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $opts->{include_packages} //= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"include_packages"} //= []
MC/DC0%0/1
$opts->{"include_packages"} //= []
$opts->{"include_packages"}
Truth table0%0/2
A
A= $opts->{"include_packages"}
| |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $opts->{exclude_packages} //= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"exclude_packages"} //= []
MC/DC0%0/1
$opts->{"exclude_packages"} //= []
$opts->{"exclude_packages"}
Truth table0%0/2
A
A= $opts->{"exclude_packages"}
| |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | $opts->{test_function_metadata} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"test_function_metadata"} //= 1
MC/DC0%0/1
$opts->{"test_function_metadata"} //= 1
$opts->{"test_function_metadata"}
Truth table0%0/2
A
A= $opts->{"test_function_metadata"}
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $opts->{wrap_function} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"wrap_function"} //= 1
MC/DC0%0/1
$opts->{"wrap_function"} //= 1
$opts->{"wrap_function"}
Truth table0%0/2
A
A= $opts->{"wrap_function"}
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $opts->{test_function_examples} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"test_function_examples"} //= 1
MC/DC0%0/1
$opts->{"test_function_examples"} //= 1
$opts->{"test_function_examples"}
Truth table0%0/2
A
A= $opts->{"test_function_examples"}
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | $opts->{include_functions} //= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"include_functions"} //= []
MC/DC0%0/1
$opts->{"include_functions"} //= []
$opts->{"include_functions"}
Truth table0%0/2
A
A= $opts->{"include_functions"}
| |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $opts->{exclude_functions} //= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"exclude_functions"} //= []
MC/DC0%0/1
$opts->{"exclude_functions"} //= []
$opts->{"exclude_functions"}
Truth table0%0/2
A
A= $opts->{"exclude_functions"}
| |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | $opts->{test_variable_metadata} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"test_variable_metadata"} //= 1
MC/DC0%0/1
$opts->{"test_variable_metadata"} //= 1
$opts->{"test_variable_metadata"}
Truth table0%0/2
A
A= $opts->{"test_variable_metadata"}
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $opts->{exclude_variables} //= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"exclude_variables"} //= []
MC/DC0%0/1
$opts->{"exclude_variables"} //= []
$opts->{"exclude_variables"}
Truth table0%0/2
A
A= $opts->{"exclude_variables"}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
@_ and ref $_[0] eq "HASH"
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"
| |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $msg = @_ ? shift : "Rinci metadata on $module"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$opts{"test_package_metadata"} and not grep({$_ eq $module;} @{$opts{"exclude_packages"};})
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"};})
| |||||||||||||||||||||||||||||
| 194 | 0 | !(grep { $_ eq $module } @{ $opts{exclude_packages} })) { | |||||||||||||||||||||||||||
| 195 | 0 | $res = $Pa->request(meta => $uri); | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($res->[0] != 200) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | $Test->ok(0, "load package metadata") or $ok = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$opts{"test_function_metadata"} or $opts{"test_variable_metadata"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($res->[0] != 200) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ($opts{test_function_metadata} && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"test_function_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_functions"};})
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"};})
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$opts{"test_variable_metadata"} and not grep({$_ eq $en;} @{$opts{"exclude_variables"};})
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"};})
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 249 | 0 | next; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | } # for list entry | ||||||||||||||||||||||||||||
| 252 | } # subtest | ||||||||||||||||||||||||||||
| 253 | 0 | ▶ | ) or $ok = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | unless ($has_tests) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 273 | 0 | my $file = shift @queue; | |||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ( -d $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 0 | local *DH; | |||||||||||||||||||||||||||
| 276 | 0 | ▶ | opendir DH, $file or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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'
MC/DC0%0/2
$_ ne 'CVS' && $_ ne '.svn'
$_ ne 'CVS'
$_ ne '.svn'
Truth table0%0/3
A && B
A= $_ ne 'CVS'B= $_ ne '.svn'
| |||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 0 | push @queue, map "$file/$_", @newfiles; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | 0 | ▶ | if ( -f $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 0 | ▶ | next unless $file =~ /\.pm$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | my @parts = File::Spec->splitdir( $file ); | |||||||||||||||||||||||||||
| 289 | 0 | ▶ | shift @parts if @parts && exists $starters{$parts[0]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@parts and exists $starters{$parts[0]}
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]}
| |||||||||||||||||||||||||||||
| 290 | 0 | ▶ | shift @parts if @parts && $parts[0] eq "lib"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@parts and $parts[0] eq "lib"
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"
| |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | $parts[-1] =~ s/\.pm$// if @parts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # Untaint the parts | ||||||||||||||||||||||||||||
| 294 | 0 | for ( @parts ) { | |||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ( /^([a-zA-Z0-9_\.\-]*)$/ && ($_ eq $1) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/^([a-zA-Z0-9_\.\-]*)$/ and $_ eq $1
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
@_ and ref $_[0] eq "HASH"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | next unless grep { $module eq $_ } @include_packages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if (@exclude_packages) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | next if grep { $module eq $_ } @exclude_packages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | #$log->infof("Processing module %s ...", $module); | ||||||||||||||||||||||||||||
| 359 | 0 | ▶ | my $thismsg = defined $msg ? $msg : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | "Rinci metadata on $module"; | ||||||||||||||||||||||||||||
| 361 | 0 | ▶ | my $thisok = metadata_in_module_ok( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | $module, $opts, $thismsg) | ||||||||||||||||||||||||||||
| 363 | or $ok = 0; | ||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | 0 | ▶ | ) or $ok = 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||