27629a71a1cbcd1682901553a231d61b5a6df889
[dbsrgits/DBIx-Class.git] / xt / dist / loadable_standalone_testschema_resultclasses.t
1 BEGIN {
2   delete $ENV{DBICTEST_VERSION_WARNS_INDISCRIMINATELY};
3   do "./t/lib/ANFANG.pm" or die ( $@ || $! )
4 }
5
6 use warnings;
7 use strict;
8
9 use DBIx::Class::_Util 'sigwarn_silencer';
10 use if DBIx::Class::_ENV_::BROKEN_FORK, 'threads';
11
12 use Test::More;
13 use File::Find;
14 use Time::HiRes 'sleep';
15
16 my $worker = sub {
17   my $fn = shift;
18
19   if (my @offenders = grep { $_ !~ m{DBIx/Class/(?:_Util|Carp)\.pm} } grep { $_ =~ /(^|\/)DBI/ } keys %INC) {
20     die "Wtf - DBI* modules present in %INC: @offenders";
21   }
22
23   local $SIG{__WARN__} = sigwarn_silencer( qr/\bdeprecated\b/i );
24   require( ( $fn =~ m| t/lib/ (.+) |x )[0] ); # untaint and strip lib-part (. is unavailable under -T)
25
26   return 42;
27 };
28
29
30 find({
31   wanted => sub {
32
33     return unless ( -f $_ and $_ =~ /\.pm$/ );
34
35     if (DBIx::Class::_ENV_::BROKEN_FORK) {
36       # older perls crash if threads are spawned way too quickly, sleep for 100 msecs
37       my $t = threads->create(sub { $worker->($_) });
38       sleep 0.1;
39       is ($t->join, 42, "Thread loading $_ did not finish successfully")
40         || diag ($t->can('error') ? $t->error : 'threads.pm too old to retrieve the error :(' );
41     }
42     else {
43       my $pid = fork();
44       if (! defined $pid) {
45         die "fork failed: $!"
46       }
47       elsif (!$pid) {
48         $worker->($_);
49         exit 0;
50       }
51
52       is ( waitpid($pid, 0), $pid, "Fork $pid terminated sucessfully");
53       my $ex = $? >> 8;
54       is ( $ex, 0, "Loading $_ ($pid) exitted with $ex" );
55     }
56   },
57
58   no_chdir => 1,
59 }, 't/lib/DBICTest/Schema/');
60
61 done_testing;