Debian Codegraph @

xt/author/pod_coverage.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 BEGIN {
5 plan skip_all => 'test requires 5.010 or better'
6 unless $] >= 5.010;
7 plan skip_all => 'test requires Test::Pod::Coverage'
8 unless eval q{ use Test::Pod::Coverage; 1 };
9 plan skip_all => 'test requires YAML'
10 unless eval q{ use YAML; 1; };
11 plan skip_all => 'test does not always work in cip check'
12 if defined $ENV{CIPSTATIC} && $ENV{CIPSTATIC} eq 'true';
13 };
14 use Test::Pod::Coverage;
15 use YAML qw( LoadFile );
16 use FindBin;
17 use File::Spec;
18
19 my $config_filename = File::Spec->catfile(
20 $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml'
21 );
22
23 my $config;
24 $config = LoadFile($config_filename)
25 if -r $config_filename;
26
27 plan skip_all => 'disabled' if $config->{pod_coverage}->{skip};
28
29 chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir));
30
31 my @private_classes;
32 my %private_methods;
33
34 push $config->{pod_coverage}->{private}->@*,
35 'Alien::.*::Install::Files#Inline';
36
37 foreach my $private ($config->{pod_coverage}->{private}->@*)
38 {
39 my($class,$method) = split /#/, $private;
40 if(defined $class && $class ne '')
41 {
42 my $regex = eval 'qr{^' . $class . '$}';
43 if(defined $method && $method ne '')
44 {
45 push @private_classes, { regex => $regex, method => $method };
46 }
47 else
48 {
49 push @private_classes, { regex => $regex, all => 1 };
50 }
51 }
52 elsif(defined $method && $method ne '')
53 {
54 $private_methods{$_} = 1 for split /,/, $method;
55 }
56 }
57
58 my @classes = all_modules;
59
60 plan tests => scalar @classes;
61
62 foreach my $class (@classes)
63 {
64 SKIP: {
65 my($is_private_class) = map { 1 } grep { $class =~ $_->{regex} && $_->{all} } @private_classes;
66 skip "private class: $class", 1 if $is_private_class;
67
68 my %methods = map {; $_ => 1 } map { split /,/, $_->{method} } grep { $class =~ $_->{regex} } @private_classes;
69 $methods{$_} = 1 for keys %private_methods;
70
71 my $also_private = eval 'qr{^' . join('|', keys %methods ) . '$}';
72
73 pod_coverage_ok $class, { also_private => [$also_private] };
74 };
75 }
76
77