From: Vincent Pit Date: Mon, 18 Apr 2011 23:29:06 +0000 (+0200) Subject: Solve all test failures with combinations of old perl, Test::More and Exporter X-Git-Tag: v0.03~5 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c5ef09dc0767113f5a35beeb4d4ce86bc84d774b;p=perl%2Fmodules%2FTest-Leaner.git Solve all test failures with combinations of old perl, Test::More and Exporter --- diff --git a/t/02-import-arg.t b/t/02-import-arg.t index ee3da6b..46f2cc1 100644 --- a/t/02-import-arg.t +++ b/t/02-import-arg.t @@ -5,6 +5,8 @@ use warnings; BEGIN { delete $ENV{PERL_TEST_LEANER_USES_TEST_MORE} } +use Carp (); + use Test::Leaner (); use Test::More (); @@ -17,6 +19,20 @@ sub get_subroutine { return *$glob{CODE}; } +sub has_module_version { + my ($module, $version) = @_; + + local $@; + eval qq{ + require $module; + "$module"->VERSION(\$version); + 1; + } +} + +sub has_test_more_version { has_module_version 'Test::More', @_ } +sub has_exporter_version { has_module_version 'Exporter', @_ } + my $this_stash = \%main::; my @default_exports = qw< @@ -60,7 +76,12 @@ SKIP: Test::More::plan(tests => 9 * @default_exports + 8 + 3); -check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan exports stuff on Test::More <= 0.51'); +check_imports([ ], [ ], has_test_more_version('0.51') ? undef : 'Test::More::plan exports stuff on Test::More <= 0.51'); + +local *Carp::carp = sub { + local $Carp::CarpLevel = ($Carp::CarpLevel || 0) + 1; + Carp::croak(@_); +} unless has_exporter_version('5.565'); { local $@; @@ -81,6 +102,7 @@ check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan } { + delete $this_stash->{use_ok} unless has_test_more_version('0.51'); local $@; eval { Test::Leaner->import(import => [ 'use_ok' ]); @@ -119,7 +141,10 @@ check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan check_imports([ grep $_ ne 'fail', @default_exports ], [ 'fail' ]); } +SKIP: { + Test::More::skip('Exporter 5.58 required to test negative imports' + => 1 + @default_exports) unless has_exporter_version('5.58'); local $@; eval { Test::Leaner->import(import => [ 'pass' ], import => [ '!fail' ]); @@ -128,7 +153,10 @@ check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan check_imports([ 'pass' ], [ ]); } +SKIP: { + Test::More::skip('Exporter 5.58 required to test negative imports' + => 1 + @default_exports) unless has_exporter_version('5.58'); local $@; eval { Test::Leaner->import(import => [ 'fail' ], import => [ '!fail' ]); diff --git a/t/03-fallback.t b/t/03-fallback.t index 3bda266..93129ae 100644 --- a/t/03-fallback.t +++ b/t/03-fallback.t @@ -3,6 +3,14 @@ use strict; use warnings; +BEGIN { + if ($^V ge v5.8.4 and $^V le v5.8.5) { + require Test::More; + Test::More::plan(skip_all + => 'goto may segfault randomly on perl 5.8.4 and 5.8.5'); + } +} + BEGIN { $ENV{PERL_TEST_LEANER_USES_TEST_MORE} = 1 } use Test::Leaner; @@ -29,6 +37,19 @@ sub get_subroutine { return *$glob{CODE}; } +sub has_module_version { + my ($module, $version) = @_; + + local $@; + eval qq{ + require $module; + "$module"->VERSION(\$version); + 1; + } +} + +sub has_test_more_version { has_module_version 'Test::More', @_ } + my $leaner_stash = \%Test::Leaner::; my $more_stash = \%Test::More::; my $this_stash = \%main::; @@ -98,27 +119,33 @@ for (@only_in_test_leaner) { "$_ was not imported into main"); } -my @only_in_test_more = qw< - use_ok - require_ok - can_ok - isa_ok - new_ok - subtest - explain - todo_skip ->; - -for (@only_in_test_more) { - my $more_variant = get_subroutine($more_stash, $_); - - SKIP: { - Test::More::skip("$_ is not implemented in this version of Test::More" => 2) - unless defined $more_variant; - - Test::More::ok(!exists $leaner_stash->{$_}, - "$_ was not imported into Test::Leaner"); - Test::More::ok(!exists $this_stash->{$_}, - "$_ was not imported into main"); +SKIP: +{ + Test::More::skip('Test::More::plan exports stuff on Test::More <= 0.51' + => 2 * 8) unless has_test_more_version('0.51'); + + my @only_in_test_more = qw< + use_ok + require_ok + can_ok + isa_ok + new_ok + subtest + explain + todo_skip + >; + + for (@only_in_test_more) { + my $more_variant = get_subroutine($more_stash, $_); + + SKIP: { + Test::More::skip("$_ is not implemented in this version of Test::More" => 2) + unless defined $more_variant; + + Test::More::ok(!exists $leaner_stash->{$_}, + "$_ was not imported into Test::Leaner"); + Test::More::ok(!exists $this_stash->{$_}, + "$_ was not imported into main"); + } } } diff --git a/t/04-fallback-import-arg.t b/t/04-fallback-import-arg.t index 968a750..ed9ad43 100644 --- a/t/04-fallback-import-arg.t +++ b/t/04-fallback-import-arg.t @@ -5,6 +5,8 @@ use warnings; BEGIN { $ENV{PERL_TEST_LEANER_USES_TEST_MORE} = 1 } +use Carp (); + use Test::Leaner (); use Test::More (); @@ -17,6 +19,20 @@ sub get_subroutine { return *$glob{CODE}; } +sub has_module_version { + my ($module, $version) = @_; + + local $@; + eval qq{ + require $module; + "$module"->VERSION(\$version); + 1; + } +} + +sub has_test_more_version { has_module_version 'Test::More', @_ } +sub has_exporter_version { has_module_version 'Exporter', @_ } + my $this_stash = \%main::; my @default_exports = qw< @@ -58,9 +74,19 @@ SKIP: delete $this_stash->{$_} for @default_exports, keys %imported, @not_imported; } -Test::More::plan(tests => 9 * @default_exports + 8 + 3); +if ($^V ge v5.8.4 and $^V le v5.8.5) { + Test::More::plan(skip_all + => 'goto may segfault randomly on perl 5.8.4 and 5.8.5'); +} else { + Test::More::plan(tests => 9 * @default_exports + 8 + 3); +} + +check_imports([ ], [ ], has_test_more_version('0.51') ? undef : 'Test::More::plan exports stuff on Test::More <= 0.51'); -check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan exports stuff on Test::More <= 0.51'); +local *Carp::carp = sub { + local $Carp::CarpLevel = ($Carp::CarpLevel || 0) + 1; + Carp::croak(@_); +} unless has_exporter_version('5.565'); { local $@; @@ -81,6 +107,7 @@ check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan } { + delete $this_stash->{use_ok} unless has_test_more_version('0.51'); local $@; eval { Test::Leaner->import(import => [ 'use_ok' ]); @@ -119,7 +146,10 @@ check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan check_imports([ grep $_ ne 'fail', @default_exports ], [ 'fail' ]); } +SKIP: { + Test::More::skip('Exporter 5.58 required to test negative imports' + => 1 + @default_exports) unless has_exporter_version('5.58'); local $@; eval { Test::Leaner->import(import => [ 'pass' ], import => [ '!fail' ]); @@ -128,7 +158,10 @@ check_imports([ ], [ ], $Test::More::VERSION > 0.51 ? undef : 'Test::More::plan check_imports([ 'pass' ], [ ]); } +SKIP: { + Test::More::skip('Exporter 5.58 required to test negative imports' + => 1 + @default_exports) unless has_exporter_version('5.58'); local $@; eval { Test::Leaner->import(import => [ 'fail' ], import => [ '!fail' ]);