5.6 compat
[p5sagit/Sub-Exporter-Progressive.git] / t / tags.t
CommitLineData
47825557 1use strict;
2use warnings;
3
35a1e2d4 4use Test::More;
47825557 5use List::Util 'first';
b94ac53e 6use Carp;
47825557 7use lib 't/lib';
8use A::Junk ':other';
9
b94ac53e 10BEGIN {
69c9647c 11 unshift @INC, sub { croak 'Shouldn\'t load Sub::Exporter' if $_[1] eq 'Sub/Exporter.pm' };
b94ac53e 12}
13
47825557 14ok(!main->can('junk1'), 'junk1 not exported');
15ok(!main->can('junk2'), 'junk2 not exported');
16ok(main->can('junk3'), 'junk3 exported');
17ok(! $INC{'Sub/Exporter.pm'}, 'Sub::Exporter not loaded');
18
b94ac53e 19BEGIN {
69c9647c 20 package Local::Exporter;
21 use Sub::Exporter::Progressive -setup => {
22 exports => [qw/ foo bar baz /],
23 groups => {
24 default => [qw/ foo /],
25 bb => [qw/ bar baz /],
26 },
27 };
6a204448 28 use constant foo => 1;
29 use constant bar => 2;
30 use constant baz => 3;
31
69c9647c 32 $INC{'Local/Exporter.pm'} = __FILE__;
b94ac53e 33};
34
35my $i = 0;
35a1e2d4 36sub check_tag {
69c9647c 37 my ($tag, $should, $shouldnt) = @_;
38 my $pkg = 'Local::Importer' . ++$i;
35a1e2d4 39
40 ok(eval qq{
41 package $pkg;
42 use Local::Exporter qw( $tag );
43 1;
44 }, "'$tag' tag: $pkg compiled") or diag $@;
45
46 ok( $pkg->can($_), "'$tag' tag: $pkg\->can(\"$_\")") for @$should;
47 ok(!$pkg->can($_), "'$tag' tag: $pkg\->can't(\"$_\")") for @$shouldnt;
b94ac53e 48}
49
50check_tag(':default', [qw/foo/], [qw/bar baz/]);
51check_tag('-default', [qw/foo/], [qw/bar baz/]);
52check_tag(':default bar', [qw/foo bar/], [qw/baz/]);
53check_tag('-default bar', [qw/foo bar/], [qw/baz/]);
54check_tag('bar :default', [qw/foo bar/], [qw/baz/]);
55check_tag('bar -default', [qw/foo bar/], [qw/baz/]);
56check_tag(':bb', [qw/bar baz/], [qw/foo/]);
57check_tag('-bb', [qw/bar baz/], [qw/foo/]);
58check_tag(':all', [qw/foo bar baz/], []);
59check_tag('-all', [qw/foo bar baz/], []);
60
47825557 61done_testing;
62