From: Vincent Pit Date: Tue, 14 Apr 2015 16:11:35 +0000 (-0300) Subject: Be more precise when Test::Leaner/Test::More were loaded early X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c9ae9f1b1179b6241fed5883450f6a39a88ef5e7;p=perl%2Fmodules%2FVPIT-TestHelpers.git Be more precise when Test::Leaner/Test::More were loaded early --- diff --git a/lib/VPIT/TestHelpers.pm b/lib/VPIT/TestHelpers.pm index d2484c6..01aff87 100644 --- a/lib/VPIT/TestHelpers.pm +++ b/lib/VPIT/TestHelpers.pm @@ -620,8 +620,14 @@ sub init_threads { skip_all 'perl 5.13.4 required to test thread safety' unless $force or "$]" >= 5.013_004; - if (($INC{'Test/More.pm'} || $INC{'Test/Leaner.pm'}) && !$INC{'threads.pm'}) { - die 'Test::More/Test::Leaner was loaded too soon'; + unless ($INC{'threads.pm'}) { + my $test_module; + if ($INC{'Test/Leaner.pm'}) { + $test_module = 'Test::Leaner'; + } elsif ($INC{'Test/More.pm'}) { + $test_module = 'Test::More'; + } + die "$test_module was loaded too soon" if defined $test_module; } load_or_skip_all 'threads', $force ? '0' : '1.67', [ ]; diff --git a/t/44-threads-too-late.t b/t/44-threads-too-late.t index 5eea92a..f5fa9f4 100644 --- a/t/44-threads-too-late.t +++ b/t/44-threads-too-late.t @@ -5,8 +5,25 @@ use warnings; BEGIN { $ENV{PERL_FORCE_TEST_THREADS} = 1 } -use Test::More tests => 1; +use Test::More; -local $@; -eval 'use VPIT::TestHelpers "threads";'; -like $@, qr/was loaded too soon/, 'cannot use the threads feature after Test::More was loaded'; +use Config; +plan skip_all => 'Cannot test late loading on a non threaded perl' + unless $Config::Config{useithreads}; + +plan tests => 2; + +{ + local $@; + eval 'use VPIT::TestHelpers "threads";'; + like $@, qr/^Test::More was loaded too soon/, + 'cannot use the threads feature after Test::More was loaded'; +} + +SKIP: { + local $@; + eval { require Test::Leaner; 1 } or skip 'No Test::Leaner available' => 1; + eval 'use VPIT::TestHelpers "threads";'; + like $@, qr/^Test::Leaner was loaded too soon/, + 'cannot use the threads feature after Test::Leaner was loaded'; +}