Introduce M.A.D. within the schema/source instance linkage
[dbsrgits/DBIx-Class.git] / xt / podcoverage.t
1 use warnings;
2 use strict;
3
4 use Test::More;
5 use List::Util 'first';
6 use lib qw(t/lib);
7 use DBICTest;
8 use namespace::clean;
9
10 # Don't run tests for installs
11 if ( DBICTest::RunMode->is_plain ) {
12   plan( skip_all => "Author tests not required for installation" );
13 }
14
15 require DBIx::Class;
16 unless ( DBIx::Class::Optional::Dependencies->req_ok_for ('test_podcoverage') ) {
17   my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('test_podcoverage');
18   $ENV{RELEASE_TESTING} || DBICTest::RunMode->is_author
19     ? die ("Failed to load release-testing module requirements: $missing")
20     : plan skip_all => "Test needs: $missing"
21 }
22
23 # Since this is about checking documentation, a little documentation
24 # of what this is doing might be in order.
25 # The exceptions structure below is a hash keyed by the module
26 # name. Any * in a name is treated like a wildcard and will behave
27 # as expected. Modules are matched by longest string first, so
28 # A::B::C will match even if there is A::B*
29
30 # The value for each is a hash, which contains one or more
31 # (although currently more than one makes no sense) of the following
32 # things:-
33 #   skip   => a true value means this module is not checked
34 #   ignore => array ref containing list of methods which
35 #             do not need to be documented.
36 my $exceptions = {
37     'DBIx::Class' => {
38         ignore => [qw/
39             MODIFY_CODE_ATTRIBUTES
40             component_base_class
41             mk_classdata
42             mk_classaccessor
43         /]
44     },
45     'DBIx::Class::Row' => {
46         ignore => [qw/
47             MULTICREATE_DEBUG
48         /],
49     },
50     'DBIx::Class::Storage::TxnScopeGuard' => {
51         ignore => [qw/
52             IS_BROKEN_PERL
53         /],
54     },
55     'DBIx::Class::FilterColumn' => {
56         ignore => [qw/
57             new
58             update
59             store_column
60             get_column
61             get_columns
62         /],
63     },
64     'DBIx::Class::ResultSource' => {
65         ignore => [qw/
66             compare_relationship_keys
67             pk_depends_on
68             resolve_condition
69             resolve_join
70             resolve_prefetch
71             STORABLE_freeze
72             STORABLE_thaw
73         /],
74     },
75     'DBIx::Class::ResultSet' => {
76         ignore => [qw/
77             STORABLE_freeze
78             STORABLE_thaw
79         /],
80     },
81     'DBIx::Class::ResultSourceHandle' => {
82         ignore => [qw/
83             schema
84             source_moniker
85         /],
86     },
87     'DBIx::Class::Storage' => {
88         ignore => [qw/
89             schema
90             cursor
91         /]
92     },
93     'DBIx::Class::Schema' => {
94         ignore => [qw/
95             setup_connection_class
96         /]
97     },
98
99     'DBIx::Class::Schema::Versioned' => {
100         ignore => [ qw/
101             connection
102         /]
103     },
104
105     'DBIx::Class::Admin'        => {
106         ignore => [ qw/
107             BUILD
108         /]
109      },
110
111     'DBIx::Class::Storage::DBI::Replicated*'        => {
112         ignore => [ qw/
113             connect_call_do_sql
114             disconnect_call_do_sql
115         /]
116     },
117
118     'DBIx::Class::Admin::*'                         => { skip => 1 },
119     'DBIx::Class::ClassResolver::PassThrough'       => { skip => 1 },
120     'DBIx::Class::Componentised'                    => { skip => 1 },
121     'DBIx::Class::Relationship::*'                  => { skip => 1 },
122     'DBIx::Class::ResultSetProxy'                   => { skip => 1 },
123     'DBIx::Class::ResultSourceProxy'                => { skip => 1 },
124     'DBIx::Class::ResultSource::*'                  => { skip => 1 },
125     'DBIx::Class::Storage::Statistics'              => { skip => 1 },
126     'DBIx::Class::Storage::DBI::Replicated::Types'  => { skip => 1 },
127
128 # test some specific components whose parents are exempt below
129     'DBIx::Class::Relationship::Base'               => {},
130     'DBIx::Class::SQLMaker::LimitDialects'          => {},
131
132 # internals
133     'DBIx::Class::SQLMaker*'                        => { skip => 1 },
134     'DBIx::Class::SQLAHacks*'                       => { skip => 1 },
135     'DBIx::Class::Storage::DBI*'                    => { skip => 1 },
136     'SQL::Translator::*'                            => { skip => 1 },
137
138 # deprecated / backcompat stuff
139     'DBIx::Class::Serialize::Storable'              => { skip => 1 },
140     'DBIx::Class::CDBICompat*'                      => { skip => 1 },
141     'DBIx::Class::ResultSetManager'                 => { skip => 1 },
142     'DBIx::Class::DB'                               => { skip => 1 },
143
144 # skipped because the synopsis covers it clearly
145     'DBIx::Class::InflateColumn::File'              => { skip => 1 },
146 };
147
148 my $ex_lookup = {};
149 for my $string (keys %$exceptions) {
150   my $ex = $exceptions->{$string};
151   $string =~ s/\*/'.*?'/ge;
152   my $re = qr/^$string$/;
153   $ex_lookup->{$re} = $ex;
154 }
155
156 my @modules = sort { $a cmp $b } (Test::Pod::Coverage::all_modules());
157
158 foreach my $module (@modules) {
159   SKIP: {
160
161     my ($match) =
162       first { $module =~ $_ }
163       (sort { length $b <=> length $a || $b cmp $a } (keys %$ex_lookup) )
164     ;
165
166     my $ex = $ex_lookup->{$match} if $match;
167
168     skip ("$module exempt", 1) if ($ex->{skip});
169
170     # build parms up from ignore list
171     my $parms = {};
172     $parms->{trustme} =
173       [ map { qr/^$_$/ } @{ $ex->{ignore} } ]
174         if exists($ex->{ignore});
175
176     # run the test with the potentially modified parm set
177     Test::Pod::Coverage::pod_coverage_ok($module, $parms, "$module POD coverage");
178   }
179 }
180
181 done_testing;