From: Vincent Pit Date: Fri, 8 Apr 2011 17:40:34 +0000 (+0200) Subject: Croak when importing symbols from Test::More that aren't in Test::Leaner X-Git-Tag: v0.03~11 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=d8f274f085e5af023435df3abc2d0671f539e627;p=perl%2Fmodules%2FTest-Leaner.git Croak when importing symbols from Test::More that aren't in Test::Leaner --- diff --git a/lib/Test/Leaner.pm b/lib/Test/Leaner.pm index 8e45f3c..f43be92 100644 --- a/lib/Test/Leaner.pm +++ b/lib/Test/Leaner.pm @@ -182,7 +182,7 @@ if ($ENV{PERL_TEST_LEANER_USES_TEST_MORE}) { } my $import = sub { - shift; + my $class = shift; my @imports = &_handle_import_args; @imports = @EXPORT unless @imports; @@ -192,8 +192,11 @@ if ($ENV{PERL_TEST_LEANER_USES_TEST_MORE}) { my $pkg = caller; no strict 'refs'; *{$pkg."::$_"} = $leaner_stash->{$_}; - } else { + } elsif (/^!/ or !exists $more_stash->{$_} or exists $leaner_stash->{$_}) { push @test_more_imports, $_; + } else { + # Croak for symbols in Test::More but not in Test::Leaner + Exporter::import($class, $_); } } diff --git a/t/02-import-arg.t b/t/02-import-arg.t index fd6f0f9..71dc90c 100644 --- a/t/02-import-arg.t +++ b/t/02-import-arg.t @@ -50,7 +50,7 @@ sub check_imports { delete $this_stash->{$_} for @default_exports, keys %imported, @not_imported; } -Test::More::plan(tests => 8 * @default_exports + 7 + 2); +Test::More::plan(tests => 9 * @default_exports + 8 + 3); check_imports(); @@ -72,6 +72,15 @@ check_imports(); check_imports([ ], [ 'nonexistent' ]); } +{ + local $@; + eval { + Test::Leaner->import(import => [ 'use_ok' ]); + }; + Test::More::like($@, qr/^"use_ok" is not exported by the Test::Leaner module/, 'import "use_ok" croaks'); + check_imports([ ], [ 'use_ok' ]); +} + { local $@; eval { diff --git a/t/04-fallback-import-arg.t b/t/04-fallback-import-arg.t index ee2bbd5..2d74d13 100644 --- a/t/04-fallback-import-arg.t +++ b/t/04-fallback-import-arg.t @@ -50,7 +50,7 @@ sub check_imports { delete $this_stash->{$_} for @default_exports, keys %imported, @not_imported; } -Test::More::plan(tests => 8 * @default_exports + 7 + 2); +Test::More::plan(tests => 9 * @default_exports + 8 + 3); check_imports(); @@ -72,6 +72,15 @@ check_imports(); check_imports([ ], [ 'nonexistent' ]); } +{ + local $@; + eval { + Test::Leaner->import(import => [ 'use_ok' ]); + }; + Test::More::like($@, qr/^"use_ok" is not exported by the Test::Leaner module/, 'import "use_ok" croaks'); + check_imports([ ], [ 'use_ok' ]); +} + { local $@; eval {