X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F04-fallback-import-arg.t;fp=t%2F04-fallback-import-arg.t;h=ee2bbd5ee9e14d8a83b621cfd63dc37131238fe3;hb=7b03c18e358942c3388e3ba4d93319333a25b9cf;hp=0000000000000000000000000000000000000000;hpb=46581a5ea4e511b8e7ab3b6498433e08e4de8cb2;p=perl%2Fmodules%2FTest-Leaner.git diff --git a/t/04-fallback-import-arg.t b/t/04-fallback-import-arg.t new file mode 100644 index 0000000..ee2bbd5 --- /dev/null +++ b/t/04-fallback-import-arg.t @@ -0,0 +1,121 @@ +#!perl -T + +use strict; +use warnings; + +BEGIN { $ENV{PERL_TEST_LEANER_USES_TEST_MORE} = 1 } + +use Test::Leaner (); +use Test::More (); + +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 => 8 * @default_exports + 7 + 2); + +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 => [ '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(); +}