X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F02-import-arg.t;h=46f2cc175863edc914d31afe15e5ac5c8f4a50c4;hb=c5ef09dc0767113f5a35beeb4d4ce86bc84d774b;hp=71dc90c950372b5753ae996c9a236706a75450a0;hpb=d8f274f085e5af023435df3abc2d0671f539e627;p=perl%2Fmodules%2FTest-Leaner.git diff --git a/t/02-import-arg.t b/t/02-import-arg.t index 71dc90c..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< @@ -40,19 +56,32 @@ my @default_exports = qw< sub check_imports { my %imported = map { $_ => 1 } @{ $_[0] || [] }; my @not_imported = @{ $_[1] || [] }; - for (@not_imported, grep !$imported{$_}, @default_exports) { - Test::More::ok(!exists $this_stash->{$_}, "$_ was not imported"); - } - for (grep $imported{$_}, @default_exports) { - my $code = get_subroutine($this_stash, $_); - Test::More::ok($code, "$_ was imported"); + +SKIP: + { + local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1; + Test::More::skip($_[2] => @not_imported + @default_exports) if defined $_[2]; + + for (@not_imported, grep !$imported{$_}, @default_exports) { + Test::More::ok(!exists $this_stash->{$_}, "$_ was not imported"); + } + for (grep $imported{$_}, @default_exports) { + my $code = get_subroutine($this_stash, $_); + Test::More::ok($code, "$_ was imported"); + } } + delete $this_stash->{$_} for @default_exports, keys %imported, @not_imported; } Test::More::plan(tests => 9 * @default_exports + 8 + 3); -check_imports(); +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 $@; @@ -73,6 +102,7 @@ check_imports(); } { + delete $this_stash->{use_ok} unless has_test_more_version('0.51'); local $@; eval { Test::Leaner->import(import => [ 'use_ok' ]); @@ -111,7 +141,10 @@ check_imports(); 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' ]); @@ -120,7 +153,10 @@ check_imports(); 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' ]);