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