1use strict;
2use warnings;
3use Test::More 0.88;
4
5use CPAN::Meta;
6
7delete $ENV{$_} for qw/PERL_JSON_BACKEND PERL_YAML_BACKEND/; # use defaults
8
9my %distmeta = (
10  name     => 'Module-Billed',
11  abstract => 'inscrutable',
12  version  => '1',
13  author   => 'Joe',
14  release_status => 'stable',
15  license  => 'perl_5',
16  'meta-spec' => {
17    version => '2',
18    url     => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
19  },
20  dynamic_config => 1,
21  generated_by   => 'Module::Build version 0.36',
22);
23
24{
25  my $meta = CPAN::Meta->new({ %distmeta });
26
27  ok(
28    $meta->should_index_package('Foo::Bar::Baz'),
29    'we index any old package, without a no_index rule'
30  );
31
32  ok(
33    $meta->should_index_file('lib/Foo/Bar/Baz.pm'),
34    'we index any old file, without a no_index rule'
35  );
36}
37
38{
39  my $meta = CPAN::Meta->new({
40    %distmeta,
41    no_index => {
42      package   => [ 'Foo::Bar' ],
43      namespace => [ 'Foo::Bar::Baz' ],
44    }
45  });
46
47  ok(
48    ! $meta->should_index_package('Foo::Bar'),
49    'exclude a specific package'
50  );
51
52  ok(
53    $meta->should_index_package('Foo::Bar::Baz'),
54    'namespace X does not exclude package X'
55  );
56
57  ok(
58    ! $meta->should_index_package('Foo::Bar::Baz::Quux'),
59    'exclude something under a namespace'
60  );
61}
62
63{
64  my $meta = CPAN::Meta->new({
65    %distmeta,
66    no_index => {
67      file      => [ 'lib/Foo/Bar.pm'  ],
68      directory => [ 'lib/Foo/Bar/Baz' ],
69    }
70  });
71
72  ok(
73    ! $meta->should_index_file('lib/Foo/Bar.pm'),
74    'exclude a specific file'
75  );
76
77  ok(
78    $meta->should_index_file('lib/Foo/Bar/Baz.pm'),
79    'do not exclude a file with a name like an excluded dir',
80  );
81
82  ok(
83    ! $meta->should_index_file('lib/Foo/Bar/Baz/Quux.pm'),
84    'exclude something under a directory'
85  );
86}
87
88done_testing;
89