70efc7cfdfa3df8cd7b82b9341af1bcd4a73bddf
[dbsrgits/DBIx-Class.git] / xt / dist / strictures.t
1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_strictures';
2
3 use warnings;
4 use strict;
5
6 use Test::More;
7 use File::Find;
8 use File::Spec;
9 use Config;
10 use lib 't/lib';
11 use DBICTest;
12
13 # The rationale is - if we can load all our optdeps
14 # that are related to lib/ - then we should be able to run
15 # perl -c checks (via syntax_ok), and all should just work
16 my $missing_groupdeps_present = grep
17   { ! DBIx::Class::Optional::Dependencies->req_ok_for($_) }
18   grep
19     { $_ !~ /^ (?: test | rdbms | dist ) _ /x }
20     keys %{DBIx::Class::Optional::Dependencies->req_group_list}
21 ;
22
23 # don't test syntax when RT#106935 is triggered (mainly CI)
24 # FIXME - remove when RT is resolved
25 my $tainted_relpath = (
26   length $ENV{PATH}
27     and
28   ${^TAINT}
29     and
30   grep
31     { ! File::Spec->file_name_is_absolute($_) }
32     split /\Q$Config{path_sep}/, $ENV{PATH}
33 ) ? 1 : 0;
34
35 find({
36   wanted => sub {
37     -f $_ or return;
38     m/\.(?: pm | pl | t )$ /ix or return;
39
40     return if m{^(?:
41       maint/Makefile.PL.inc/.+                        # all the maint inc snippets are auto-strictured
42         |
43       t/lib/DBICTest/Util/OverrideRequire.pm          # no stictures by design (load order sensitive)
44         |
45       lib/DBIx/Class/Optional/Dependencies.pm         # no stictures by design (load spee sensitive)
46     )$}x;
47
48     my $f = $_;
49
50     Test::Strict::strict_ok($f);
51     Test::Strict::warnings_ok($f);
52
53     Test::Strict::syntax_ok($f) if (
54       ! $tainted_relpath
55         and
56       ! $missing_groupdeps_present
57         and
58       $f =~ /^ (?: lib  )/x
59     );
60   },
61   no_chdir => 1,
62 }, (qw(lib t examples maint)) );
63
64 done_testing;