Generalize leak-trace handling
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / RunMode.pm
CommitLineData
ab340f7f 1package # hide from PAUSE
39c9c72d 2 DBICTest::RunMode;
ab340f7f 3
4use strict;
5use warnings;
6
7use Path::Class qw/file dir/;
8
9_check_author_makefile() unless $ENV{DBICTEST_NO_MAKEFILE_VERIFICATION};
10
11# Die if the author did not update his makefile
12#
13# This is pretty heavy handed, so the check is pretty solid:
14#
15# 1) Assume that this particular module is loaded from -I <$root>/t/lib
16# 2) Make sure <$root>/Makefile.PL exists
17# 3) Make sure we can stat() <$root>/Makefile.PL
18#
19# If all of the above is satisfied
20#
21# *) die if <$root>/inc does not exist
22# *) die if no stat() results for <$root>/Makefile (covers no Makefile)
23# *) die if Makefile.PL mtime > Makefile mtime
24#
25sub _check_author_makefile {
26
27 my $root = _find_co_root()
28 or return;
29
7159a456 30 my $optdeps = file('lib/DBIx/Class/Optional/Dependencies.pm');
31
ab340f7f 32 # not using file->stat as it invokes File::stat which in turn breaks stat(_)
7159a456 33 my ($mf_pl_mtime, $mf_mtime, $optdeps_mtime) = ( map
50360f3e 34 { (stat ($root->file ($_)) )[9] || undef } # stat returns () on nonexistent files
7159a456 35 (qw|Makefile.PL Makefile|, $optdeps)
ab340f7f 36 );
37
38 return unless $mf_pl_mtime; # something went wrong during co_root detection ?
39
7159a456 40 my @fail_reasons;
ab340f7f 41
7159a456 42 if(not -d $root->subdir ('inc')) {
43 push @fail_reasons, "Missing ./inc directory";
44 }
ab340f7f 45
a256e995 46 if(not $mf_mtime) {
7159a456 47 push @fail_reasons, "Missing ./Makefile";
48 }
a256e995 49 else {
50 if($mf_mtime < $mf_pl_mtime) {
51 push @fail_reasons, "./Makefile.PL is newer than ./Makefile";
52 }
53 if($mf_mtime < $optdeps_mtime) {
54 push @fail_reasons, "./$optdeps is newer than ./Makefile";
55 }
7159a456 56 }
57
58 if (@fail_reasons) {
59 print STDERR <<'EOE';
ab340f7f 60
61
62!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
63======================== FATAL ERROR ===========================
64!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65
66We have a number of reasons to believe that this is a development
67checkout and that you, the user, did not run `perl Makefile.PL`
68before using this code. You absolutely _must_ perform this step,
0424d17a 69to ensure you have all required dependencies present. Not doing
dc4600b2 70so often results in a lot of wasted time for other contributors
71trying to assit you with spurious "its broken!" problems.
ab340f7f 72
0424d17a 73By default DBICs Makefile.PL turns all optional dependenciess into
74*HARD REQUIREMENTS*, in order to make sure that the entire test
75suite is executed, and no tests are skipped due to missing modules.
76If you for some reason need to disable this behavior - supply the
77--skip_author_deps option when running perl Makefile.PL
78
ab340f7f 79If you are seeing this message unexpectedly (i.e. you are in fact
dc4600b2 80attempting a regular installation be it through CPAN or manually),
81please report the situation to either the mailing list or to the
82irc channel as described in
ab340f7f 83
84http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class.pm#GETTING_HELP/SUPPORT
85
ab340f7f 86The DBIC team
87
88
7159a456 89Reasons you received this message:
ab340f7f 90
91EOE
92
7159a456 93 foreach my $r (@fail_reasons) {
94 print STDERR " * $r\n";
95 }
96 print STDERR "\n\n\n";
97
ab340f7f 98 exit 1;
99 }
100}
101
d5e5fb4b 102sub peepeeness {
103 return ! $ENV{DBICTEST_ALL_LEAKS} if defined $ENV{DBICTEST_ALL_LEAKS};
104
105 # don't smoke perls with known issues:
106 if (__PACKAGE__->is_smoker) {
107 if ($] == '5.013006') {
108 # leaky 5.13.6 (fixed in blead/cefd5c7c)
109 return 1;
110 }
111 elsif ($] == '5.013005') {
112 # not sure why this one leaks, but disable anyway - ANDK seems to make it weep
113 return 1;
114 }
115 }
116
117 return 0;
118}
119
dc4600b2 120# Mimic $Module::Install::AUTHOR
121sub is_author {
122
123 my $root = _find_co_root()
124 or return undef;
125
126 return (
127 ( not -d $root->subdir ('inc') )
128 or
39c9c72d 129 ( -e $root->subdir ('inc')->subdir ($^O eq 'VMS' ? '_author' : '.author') )
dc4600b2 130 );
131}
132
39c9c72d 133sub is_smoker {
134 return ( $ENV{AUTOMATED_TESTING} && ! $ENV{PERL5_CPANM_IS_RUNNING} && ! $ENV{RELEASE_TESTING} )
135}
136
137sub is_plain {
138 return (! __PACKAGE__->is_smoker && ! __PACKAGE__->is_author && ! $ENV{RELEASE_TESTING} )
139}
140
ab340f7f 141# Try to determine the root of a checkout/untar if possible
142# or return undef
143sub _find_co_root {
144
145 my @mod_parts = split /::/, (__PACKAGE__ . '.pm');
fd3d890d 146 my $rel_path = join ('/', @mod_parts); # %INC stores paths with / regardless of OS
ab340f7f 147
148 return undef unless ($INC{$rel_path});
149
150 # a bit convoluted, but what we do here essentially is:
151 # - get the file name of this particular module
152 # - do 'cd ..' as many times as necessary to get to t/lib/../..
153
154 my $root = dir ($INC{$rel_path});
fd3d890d 155 for (1 .. @mod_parts + 2) {
ab340f7f 156 $root = $root->parent;
157 }
158
159 return (-f $root->file ('Makefile.PL') )
160 ? $root
161 : undef
162 ;
163}
164
1651;