6 BEGIN { $ENV{PERL_TEST_LEANER_USES_TEST_MORE} = 1 }
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 if ($^V ge v5.8.4 and $^V le v5.8.5) {
78 Test::More::plan(skip_all
79 => 'goto may segfault randomly on perl 5.8.4 and 5.8.5');
81 Test::More::plan(tests => 9 * @default_exports + 8 + 3);
84 check_imports([ ], [ ], has_test_more_version('0.51') ? undef : 'Test::More::plan exports stuff on Test::More <= 0.51');
86 local *Carp::carp = sub {
87 local $Carp::CarpLevel = ($Carp::CarpLevel || 0) + 1;
89 } unless has_exporter_version('5.565');
94 Test::Leaner->import(import => [ ]);
96 Test::More::is($@, '', 'empty import does not croak');
97 check_imports(\@default_exports);
103 Test::Leaner->import(import => [ 'nonexistent' ]);
105 Test::More::like($@, qr/^"nonexistent" is not exported by the Test::More module/, 'import "nonexistent" croaks');
106 check_imports([ ], [ 'nonexistent' ]);
110 delete $this_stash->{use_ok} unless has_test_more_version('0.51');
113 Test::Leaner->import(import => [ 'use_ok' ]);
115 Test::More::like($@, qr/^"use_ok" is not exported by the Test::Leaner module/, 'import "use_ok" croaks');
116 check_imports([ ], [ 'use_ok' ]);
122 Test::Leaner->import(import => [ 'ok' ]);
124 Test::More::is($@, '', 'import "ok" does not croak');
125 check_imports([ 'ok' ], [ ]);
131 Test::Leaner->import(
132 import => [ qw<like unlike> ],
133 import => [ qw<diag note> ],
136 Test::More::is($@, '', 'import "like", "unlike", "diag" and "note" does not croak');
137 check_imports([ qw<like unlike diag note> ], [ ]);
143 Test::Leaner->import(import => [ '!fail' ]);
145 Test::More::is($@, '', 'import "!fail" does not croak');
146 check_imports([ grep $_ ne 'fail', @default_exports ], [ 'fail' ]);
151 Test::More::skip('Exporter 5.58 required to test negative imports'
152 => 1 + @default_exports) unless has_exporter_version('5.58');
155 Test::Leaner->import(import => [ 'pass' ], import => [ '!fail' ]);
157 Test::More::is($@, '', 'import "pass", "!fail" does not croak');
158 check_imports([ 'pass' ], [ ]);
163 Test::More::skip('Exporter 5.58 required to test negative imports'
164 => 1 + @default_exports) unless has_exporter_version('5.58');
167 Test::Leaner->import(import => [ 'fail' ], import => [ '!fail' ]);
169 Test::More::is($@, '', 'import "fail", "!fail" does not croak');