X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F04-fallback-import-arg.t;h=e0b3e4eafa1e1e246006eebd5d4cf49d77e763f2;hb=929c8bab7d9cc5a7247006772efa931797016d59;hp=2d74d136737ff9bd2faaeead9e92b553895512d9;hpb=d8f274f085e5af023435df3abc2d0671f539e627;p=perl%2Fmodules%2FTest-Leaner.git diff --git a/t/04-fallback-import-arg.t b/t/04-fallback-import-arg.t index 2d74d13..e0b3e4e 100644 --- a/t/04-fallback-import-arg.t +++ b/t/04-fallback-import-arg.t @@ -5,126 +5,7 @@ use warnings; BEGIN { $ENV{PERL_TEST_LEANER_USES_TEST_MORE} = 1 } -use Test::Leaner (); -use Test::More (); +use lib 't/lib'; +use Test::Leaner::TestImport 'test_import_arg'; -sub get_subroutine { - my ($stash, $name) = @_; - - my $glob = $stash->{$name}; - return undef unless $glob; - - return *$glob{CODE}; -} - -my $this_stash = \%main::; - -my @default_exports = qw< - plan - skip - done_testing - pass - fail - ok - is - isnt - like - unlike - cmp_ok - is_deeply - diag - note - BAIL_OUT ->; - -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"); - } - delete $this_stash->{$_} for @default_exports, keys %imported, @not_imported; -} - -Test::More::plan(tests => 9 * @default_exports + 8 + 3); - -check_imports(); - -{ - local $@; - eval { - Test::Leaner->import(import => [ ]); - }; - Test::More::is($@, '', 'empty import does not croak'); - check_imports(\@default_exports); -} - -{ - local $@; - eval { - Test::Leaner->import(import => [ 'nonexistent' ]); - }; - Test::More::like($@, qr/^"nonexistent" is not exported by the Test::More module/, 'import "nonexistent" croaks'); - 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 { - Test::Leaner->import(import => [ 'ok' ]); - }; - Test::More::is($@, '', 'import "ok" does not croak'); - check_imports([ 'ok' ], [ ]); -} - -{ - local $@; - eval { - Test::Leaner->import( - import => [ qw ], - import => [ qw ], - ); - }; - Test::More::is($@, '', 'import "like", "unlike", "diag" and "note" does not croak'); - check_imports([ qw ], [ ]); -} - -{ - local $@; - eval { - Test::Leaner->import(import => [ '!fail' ]); - }; - Test::More::is($@, '', 'import "!fail" does not croak'); - check_imports([ grep $_ ne 'fail', @default_exports ], [ 'fail' ]); -} - -{ - local $@; - eval { - Test::Leaner->import(import => [ 'pass' ], import => [ '!fail' ]); - }; - Test::More::is($@, '', 'import "pass", "!fail" does not croak'); - check_imports([ 'pass' ], [ ]); -} - -{ - local $@; - eval { - Test::Leaner->import(import => [ 'fail' ], import => [ '!fail' ]); - }; - Test::More::is($@, '', 'import "fail", "!fail" does not croak'); - check_imports(); -} +test_import_arg;