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