1 package Scope::Upper::TestThreads;
6 use Config qw<%Config>;
8 use Scope::Upper qw<SU_THREADSAFE>;
10 use VPIT::TestHelpers;
14 Test::Leaner::diag(@_);
20 skip_all 'This Scope::Upper isn\'t thread safe' unless SU_THREADSAFE;
22 my $force = $ENV{PERL_SCOPE_UPPER_TEST_THREADS} ? 1 : !1;
23 skip_all 'This perl wasn\'t built to support threads'
24 unless $Config{useithreads};
25 skip_all 'perl 5.13.4 required to test thread safety'
26 unless $force or "$]" >= 5.013_004;
28 load_or_skip('threads', $force ? '0' : '1.67', [ ],
29 'required to test thread safety');
36 if (do { local $@; eval { require Time::HiRes; 1 } }) {
37 defined and diag "Using Time::HiRes $_" for $Time::HiRes::VERSION;
38 $exports{usleep} = \&Time::HiRes::usleep;
40 diag 'Using fallback usleep';
41 $exports{usleep} = sub {
42 my $s = int($_[0] / 2.5e5);
48 while (my ($name, $code) = each %exports) {
50 *{$pkg.'::'.$name} = $code;
58 local $SIG{__WARN__} = sub { push @diag, "Thread creation warning: @_" };
61 push @diag, "Thread creation error: $@" if $@;
64 Test::Leaner::diag($_) for @diag;
66 return $thread ? $thread : ();