6 BEGIN { delete $ENV{PERL_TEST_LEANER_USES_TEST_MORE} }
14 my ($stash, $name) = @_;
16 my $glob = $stash->{$name};
17 return undef unless $glob;
22 sub has_module_version {
23 my ($module, $version) = @_;
28 "$module"->VERSION(\$version);
33 sub has_test_more_version { has_module_version 'Test::More', @_ }
34 sub has_exporter_version { has_module_version 'Exporter', @_ }
36 my $this_stash = \%main::;
38 my @default_exports = qw<
57 my %imported = map { $_ => 1 } @{ $_[0] || [] };
58 my @not_imported = @{ $_[1] || [] };
62 local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1;
63 Test::More::skip($_[2] => @not_imported + @default_exports) if defined $_[2];
65 for (@not_imported, grep !$imported{$_}, @default_exports) {
66 Test::More::ok(!exists $this_stash->{$_}, "$_ was not imported");
68 for (grep $imported{$_}, @default_exports) {
69 my $code = get_subroutine($this_stash, $_);
70 Test::More::ok($code, "$_ was imported");
74 delete $this_stash->{$_} for @default_exports, keys %imported, @not_imported;
77 Test::More::plan(tests => 9 * @default_exports + 8 + 3);
79 check_imports([ ], [ ], has_test_more_version('0.51') ? undef : 'Test::More::plan exports stuff on Test::More <= 0.51');
81 local *Carp::carp = sub {
82 local $Carp::CarpLevel = ($Carp::CarpLevel || 0) + 1;
84 } unless has_exporter_version('5.565');
89 Test::Leaner->import(import => [ ]);
91 Test::More::is($@, '', 'empty import does not croak');
92 check_imports(\@default_exports);
98 Test::Leaner->import(import => [ 'nonexistent' ]);
100 Test::More::like($@, qr/^"nonexistent" is not exported by the Test::Leaner module/, 'import "nonexistent" croaks');
101 check_imports([ ], [ 'nonexistent' ]);
105 delete $this_stash->{use_ok} unless has_test_more_version('0.51');
108 Test::Leaner->import(import => [ 'use_ok' ]);
110 Test::More::like($@, qr/^"use_ok" is not exported by the Test::Leaner module/, 'import "use_ok" croaks');
111 check_imports([ ], [ 'use_ok' ]);
117 Test::Leaner->import(import => [ 'ok' ]);
119 Test::More::is($@, '', 'import "ok" does not croak');
120 check_imports([ 'ok' ], [ ]);
126 Test::Leaner->import(
127 import => [ qw<like unlike> ],
128 import => [ qw<diag note> ],
131 Test::More::is($@, '', 'import "like", "unlike", "diag" and "note" does not croak');
132 check_imports([ qw<like unlike diag note> ], [ ]);
138 Test::Leaner->import(import => [ '!fail' ]);
140 Test::More::is($@, '', 'import "!fail" does not croak');
141 check_imports([ grep $_ ne 'fail', @default_exports ], [ 'fail' ]);
146 Test::More::skip('Exporter 5.58 required to test negative imports'
147 => 1 + @default_exports) unless has_exporter_version('5.58');
150 Test::Leaner->import(import => [ 'pass' ], import => [ '!fail' ]);
152 Test::More::is($@, '', 'import "pass", "!fail" does not croak');
153 check_imports([ 'pass' ], [ ]);
158 Test::More::skip('Exporter 5.58 required to test negative imports'
159 => 1 + @default_exports) unless has_exporter_version('5.58');
162 Test::Leaner->import(import => [ 'fail' ], import => [ '!fail' ]);
164 Test::More::is($@, '', 'import "fail", "!fail" does not croak');