X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FVPIT%2FTestHelpers.pm;h=27c814907a08f247b9d5b8c3f0be2c5281922f45;hb=ded5cdb5a343bc4e48b7a3f19968af3af55a7c0f;hp=01aff874a8f7a8563554437cf3aee322870b405a;hpb=c9ae9f1b1179b6241fed5883450f6a39a88ef5e7;p=perl%2Fmodules%2FVPIT-TestHelpers.git diff --git a/lib/VPIT/TestHelpers.pm b/lib/VPIT/TestHelpers.pm index 01aff87..27c8149 100644 --- a/lib/VPIT/TestHelpers.pm +++ b/lib/VPIT/TestHelpers.pm @@ -288,11 +288,19 @@ Dependencies : =item - -Not VMS +Neither VMS nor OS/2 =item - -L, L, L +L + +=item - + +L + +=item - + +L =item - @@ -331,7 +339,8 @@ C (possibly prefixed by C<$p>) sub init_capture { my $p = sanitize_prefix(shift); - skip_all 'Cannot capture output on VMS' if $^O eq 'VMS'; + skip_all 'Cannot capture output on VMS' if $^O eq 'VMS'; + skip_all 'Cannot capture output on OS/2' if $^O eq 'os2'; load_or_skip_all 'IO::Handle', '0', [ ]; load_or_skip_all 'IO::Select', '0', [ ]; @@ -476,6 +485,15 @@ sub capture { 1; }; + if ("$]" < 5.014 and $ok and ($status >> 8) == 255 and defined $content_err + and $content_err =~ /^open3/) { + # Before perl commit 8960aa87 (between 5.12 and 5.14), exceptions in open3 + # could be reported to STDERR instead of being propagated, so work around + # this. + $ok = 0; + $@ = $content_err; + } + if ($ok) { return ($status, $content_out, $content_err); } else { @@ -568,10 +586,6 @@ L 1.67 L 1.14 -=item - - -L - =back =item * @@ -633,8 +647,6 @@ sub init_threads { load_or_skip_all 'threads', $force ? '0' : '1.67', [ ]; load_or_skip_all 'threads::shared', $force ? '0' : '1.14', [ ]; - require Test::Leaner; - diag "Threads testing forced by \$ENV{$force_var}" if $force; return spawn => \&spawn; @@ -660,7 +672,18 @@ sub spawn { Import : - use VPIT::TestHelpers 'usleep' + use VPIT::TestHelpers 'usleep' => [ @impls ]; + +where : + +=over 8 + +=item - + +C<@impls> is the list of desired implementations (which may be C<'Time::HiRes'> or C<'sleep'>), in the order they should be checked. +When the list is empty, it defaults to all of them. + +=back =item * @@ -683,20 +706,39 @@ C =cut sub init_usleep { - my $usleep; + my (@impls) = @_; - if (do { local $@; eval { require Time::HiRes; 1 } }) { - defined and diag "Using usleep() from Time::HiRes $_" + my %impls = ( + 'Time::HiRes' => sub { + if (do { local $@; eval { require Time::HiRes; 1 } }) { + defined and diag "Using usleep() from Time::HiRes $_" for $Time::HiRes::VERSION; - $usleep = \&Time::HiRes::usleep; - } else { - diag 'Using fallback usleep()'; - $usleep = sub { - my $s = int($_[0] / 1e6); - sleep $s if $s; - }; + return \&Time::HiRes::usleep; + } else { + return undef; + } + }, + 'sleep' => sub { + diag 'Using sleep()-based fallback usleep()'; + return sub { + my $s = int($_[0] / 1e6); + sleep $s if $s; + }; + }, + ); + + @impls = qw unless @impls; + + my $usleep; + for my $impl (@impls) { + next unless defined $impl and $impls{$impl}; + $usleep = $impls{$impl}->(); + last if defined $usleep; } + skip_all "Could not find a suitable usleep() implementation among: @impls" + unless $usleep; + return usleep => $usleep; }