31112912e674ec5fa6405f471191c61aff3dff01
[p5sagit/Module-Metadata.git] / t / metadata.t
1 #!/usr/bin/perl -w
2 # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
3 # vim:ts=8:sw=2:et:sta:sts=2
4
5 use strict;
6 use warnings;
7 use lib 't/lib';
8 use Test::More;
9 use IO::File;
10 use MBTest;
11
12 my $undef;
13
14 # parse various module $VERSION lines
15 # these will be reversed later to create %modules
16 my @modules = (
17   $undef => <<'---', # no $VERSION line
18 package Simple;
19 ---
20   $undef => <<'---', # undefined $VERSION
21 package Simple;
22 our $VERSION;
23 ---
24   '1.23' => <<'---', # declared & defined on same line with 'our'
25 package Simple;
26 our $VERSION = '1.23';
27 ---
28   '1.23' => <<'---', # declared & defined on separate lines with 'our'
29 package Simple;
30 our $VERSION;
31 $VERSION = '1.23';
32 ---
33   '1.23' => <<'---', # commented & defined on same line
34 package Simple;
35 our $VERSION = '1.23'; # our $VERSION = '4.56';
36 ---
37   '1.23' => <<'---', # commented & defined on separate lines
38 package Simple;
39 # our $VERSION = '4.56';
40 our $VERSION = '1.23';
41 ---
42   '1.23' => <<'---', # use vars
43 package Simple;
44 use vars qw( $VERSION );
45 $VERSION = '1.23';
46 ---
47   '1.23' => <<'---', # choose the right default package based on package/file name
48 package Simple::_private;
49 $VERSION = '0';
50 package Simple;
51 $VERSION = '1.23'; # this should be chosen for version
52 ---
53   '1.23' => <<'---', # just read the first $VERSION line
54 package Simple;
55 $VERSION = '1.23'; # we should see this line
56 $VERSION = eval $VERSION; # and ignore this one
57 ---
58   '1.23' => <<'---', # just read the first $VERSION line in reopened package (1)
59 package Simple;
60 $VERSION = '1.23';
61 package Error::Simple;
62 $VERSION = '2.34';
63 package Simple;
64 ---
65   '1.23' => <<'---', # just read the first $VERSION line in reopened package (2)
66 package Simple;
67 package Error::Simple;
68 $VERSION = '2.34';
69 package Simple;
70 $VERSION = '1.23';
71 ---
72   '1.23' => <<'---', # mentions another module's $VERSION
73 package Simple;
74 $VERSION = '1.23';
75 if ( $Other::VERSION ) {
76     # whatever
77 }
78 ---
79   '1.23' => <<'---', # mentions another module's $VERSION in a different package
80 package Simple;
81 $VERSION = '1.23';
82 package Simple2;
83 if ( $Simple::VERSION ) {
84     # whatever
85 }
86 ---
87   '1.23' => <<'---', # $VERSION checked only in assignments, not regexp ops
88 package Simple;
89 $VERSION = '1.23';
90 if ( $VERSION =~ /1\.23/ ) {
91     # whatever
92 }
93 ---
94   '1.23' => <<'---', # $VERSION checked only in assignments, not relational ops
95 package Simple;
96 $VERSION = '1.23';
97 if ( $VERSION == 3.45 ) {
98     # whatever
99 }
100 ---
101   '1.23' => <<'---', # $VERSION checked only in assignments, not relational ops
102 package Simple;
103 $VERSION = '1.23';
104 package Simple2;
105 if ( $Simple::VERSION == 3.45 ) {
106     # whatever
107 }
108 ---
109   '1.23' => <<'---', # Fully qualified $VERSION declared in package
110 package Simple;
111 $Simple::VERSION = 1.23;
112 ---
113   '1.23' => <<'---', # Differentiate fully qualified $VERSION in a package
114 package Simple;
115 $Simple2::VERSION = '999';
116 $Simple::VERSION = 1.23;
117 ---
118   '1.23' => <<'---', # Differentiate fully qualified $VERSION and unqualified
119 package Simple;
120 $Simple2::VERSION = '999';
121 $VERSION = 1.23;
122 ---
123   '1.23' => <<'---', # $VERSION declared as package variable from within 'main' package
124 $Simple::VERSION = '1.23';
125 {
126   package Simple;
127   $x = $y, $cats = $dogs;
128 }
129 ---
130   '1.23' => <<'---', # $VERSION wrapped in parens - space inside
131 package Simple;
132 ( $VERSION ) = '1.23';
133 ---
134   '1.23' => <<'---', # $VERSION wrapped in parens - no space inside
135 package Simple;
136 ($VERSION) = '1.23';
137 ---
138   '1.23' => <<'---', # $VERSION follows a spurious 'package' in a quoted construct
139 package Simple;
140 __PACKAGE__->mk_accessors(qw(
141     program socket proc
142     package filename line codeline subroutine finished));
143
144 our $VERSION = "1.23";
145 ---
146   '1.23' => <<'---', # $VERSION using version.pm
147   package Simple;
148   use version; our $VERSION = version->new('1.23');
149 ---
150   '1.23' => <<'---', # $VERSION using version.pm and qv()
151   package Simple;
152   use version; our $VERSION = qv('1.230');
153 ---
154   '1.23' => <<'---', # Two version assignments, should ignore second one
155   $Simple::VERSION = '1.230';
156   $Simple::VERSION = eval $Simple::VERSION;
157 ---
158   '1.23' => <<'---', # declared & defined on same line with 'our'
159 package Simple;
160 our $VERSION = '1.23_00_00';
161 ---
162   '1.23' => <<'---', # package NAME VERSION
163   package Simple 1.23;
164 ---
165   '1.23_01' => <<'---', # package NAME VERSION
166   package Simple 1.23_01;
167 ---
168   'v1.2.3' => <<'---', # package NAME VERSION
169   package Simple v1.2.3;
170 ---
171   'v1.2_3' => <<'---', # package NAME VERSION
172   package Simple v1.2_3;
173 ---
174   '1.23' => <<'---', # trailing crud
175   package Simple;
176   our $VERSION;
177   $VERSION = '1.23-alpha';
178 ---
179   '1.23' => <<'---', # trailing crud
180   package Simple;
181   our $VERSION;
182   $VERSION = '1.23b';
183 ---
184   '1.234' => <<'---', # multi_underscore
185   package Simple;
186   our $VERSION;
187   $VERSION = '1.2_3_4';
188 ---
189   '0' => <<'---', # non-numeric
190   package Simple;
191   our $VERSION;
192   $VERSION = 'onetwothree';
193 ---
194   $undef => <<'---', # package NAME BLOCK, undef $VERSION
195 package Simple {
196   our $VERSION;
197 }
198 ---
199   '1.23' => <<'---', # package NAME BLOCK, with $VERSION
200 package Simple {
201   our $VERSION = '1.23';
202 }
203 ---
204   '1.23' => <<'---', # package NAME VERSION BLOCK
205 package Simple 1.23 {
206   1;
207 }
208 ---
209   'v1.2.3_4' => <<'---', # package NAME VERSION BLOCK
210 package Simple v1.2.3_4 {
211   1;
212 }
213 ---
214   '0' => <<'---', # set from separately-initialised variable
215 package Simple;
216   our $CVSVERSION   = '$Revision: 1.7 $';
217   our ($VERSION)    = ($CVSVERSION =~ /(\d+\.\d+)/);
218 }
219 ---
220 );
221 my %modules = reverse @modules;
222
223 my @pkg_names = (
224   [ 'Simple' ] => <<'---', # package NAME
225 package Simple;
226 ---
227   [ 'Simple::Edward' ] => <<'---', # package NAME::SUBNAME
228 package Simple::Edward;
229 ---
230   [ 'Simple::Edward::' ] => <<'---', # package NAME::SUBNAME::
231 package Simple::Edward::;
232 ---
233   [ "Simple'Edward" ] => <<'---', # package NAME'SUBNAME
234 package Simple'Edward;
235 ---
236   [ "Simple'Edward::" ] => <<'---', # package NAME'SUBNAME::
237 package Simple'Edward::;
238 ---
239   [ 'Simple::::Edward' ] => <<'---', # package NAME::::SUBNAME
240 package Simple::::Edward;
241 ---
242   [ '::Simple::Edward' ] => <<'---', # package ::NAME::SUBNAME
243 package ::Simple::Edward;
244 ---
245   [ 'main' ] => <<'---', # package NAME:SUBNAME (fail)
246 package Simple:Edward;
247 ---
248   [ 'main' ] => <<'---', # package NAME' (fail)
249 package Simple';
250 ---
251   [ 'main' ] => <<'---', # package NAME::SUBNAME' (fail)
252 package Simple::Edward';
253 ---
254   [ 'main' ] => <<'---', # package NAME''SUBNAME (fail)
255 package Simple''Edward;
256 ---
257   [ 'main' ] => <<'---', # package NAME-SUBNAME (fail)
258 package Simple-Edward;
259 ---
260 );
261 my %pkg_names = reverse @pkg_names;
262
263 plan tests => 63 + (2 * keys( %modules )) + (2 * keys( %pkg_names ));
264
265 require_ok('Module::Metadata');
266
267 {
268   # class method C<find_module_by_name>
269   my $module = Module::Metadata->find_module_by_name(
270                  'Module::Metadata' );
271   ok( -e $module, 'find_module_by_name() succeeds' );
272 }
273
274 #########################
275
276 my $tmp = MBTest->tmpdir;
277
278 use DistGen;
279 my $dist = DistGen->new( dir => $tmp );
280 $dist->regen;
281
282 $dist->chdir_in;
283
284 {
285   # fail on invalid module name
286   my $pm_info = Module::Metadata->new_from_module(
287                   'Foo::Bar', inc => [] );
288   ok( !defined( $pm_info ), 'fail if can\'t find module by module name' );
289 }
290
291 {
292   # fail on invalid filename
293   my $file = File::Spec->catfile( 'Foo', 'Bar.pm' );
294   my $pm_info = Module::Metadata->new_from_file( $file, inc => [] );
295   ok( !defined( $pm_info ), 'fail if can\'t find module by file name' );
296 }
297
298 {
299   # construct from module filename
300   my $file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm';
301   my $pm_info = Module::Metadata->new_from_file( $file );
302   ok( defined( $pm_info ), 'new_from_file() succeeds' );
303
304   # construct from filehandle
305   my $handle = IO::File->new($file);
306   $pm_info = Module::Metadata->new_from_handle( $handle, $file );
307   ok( defined( $pm_info ), 'new_from_handle() succeeds' );
308   $pm_info = Module::Metadata->new_from_handle( $handle );
309   is( $pm_info, undef, "new_from_handle() without filename returns undef" );
310   close($handle);
311
312   # construct from module name, using custom include path
313   $pm_info = Module::Metadata->new_from_module(
314                $dist->name, inc => [ 'lib', @INC ] );
315   ok( defined( $pm_info ), 'new_from_module() succeeds' );
316 }
317
318
319 foreach my $module ( sort keys %modules ) {
320     my $expected = $modules{$module};
321  SKIP: {
322     skip( "No our() support until perl 5.6", 2 )
323         if $] < 5.006 && $module =~ /\bour\b/;
324     skip( "No package NAME VERSION support until perl 5.11.1", 2 )
325         if $] < 5.011001 && $module =~ /package\s+[\w\:\']+\s+v?[0-9._]+/;
326
327     $dist->change_file( 'lib/Simple.pm', $module );
328     $dist->regen;
329
330     my $warnings = '';
331     local $SIG{__WARN__} = sub { $warnings .= $_ for @_ };
332     my $file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm';
333     my $pm_info = Module::Metadata->new_from_file( $file );
334
335     # Test::Builder will prematurely numify objects, so use this form
336     my $errs;
337     my $got = $pm_info->version;
338     if ( defined $expected ) {
339         ok( $got eq $expected,
340             "correct module version (expected '$expected')" )
341             or $errs++;
342     } else {
343         ok( !defined($got),
344             "correct module version (expected undef)" )
345             or $errs++;
346     }
347     is( $warnings, '', 'no warnings from parsing' ) or $errs++;
348     diag "Got: '$got'\nModule contents:\n$module" if $errs;
349   }
350 }
351
352 # revert to pristine state
353 $dist->regen( clean => 1 );
354
355 foreach my $pkg_name ( sort keys %pkg_names ) {
356     my $expected = $pkg_names{$pkg_name};
357
358     $dist->change_file( 'lib/Simple.pm', $pkg_name );
359     $dist->regen;
360
361     my $warnings = '';
362     local $SIG{__WARN__} = sub { $warnings .= $_ for @_ };
363     my $file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm';
364     my $pm_info = Module::Metadata->new_from_file( $file );
365
366     # Test::Builder will prematurely numify objects, so use this form
367     my $errs;
368     my @got = $pm_info->packages_inside();
369     is_deeply( \@got, $expected,
370                "correct package names (expected '" . join(', ', @$expected) . "')" )
371             or $errs++;
372     is( $warnings, '', 'no warnings from parsing' ) or $errs++;
373     diag "Got: '" . join(', ', @got) . "'\nModule contents:\n$pkg_name" if $errs;
374 }
375
376 # revert to pristine state
377 $dist->regen( clean => 1 );
378
379 {
380   # Find each package only once
381   $dist->change_file( 'lib/Simple.pm', <<'---' );
382 package Simple;
383 $VERSION = '1.23';
384 package Error::Simple;
385 $VERSION = '2.34';
386 package Simple;
387 ---
388
389   $dist->regen;
390
391   my $file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm';
392   my $pm_info = Module::Metadata->new_from_file( $file );
393
394   my @packages = $pm_info->packages_inside;
395   is( @packages, 2, 'record only one occurence of each package' );
396 }
397
398 {
399   # Module 'Simple.pm' does not contain package 'Simple';
400   # constructor should not complain, no default module name or version
401   $dist->change_file( 'lib/Simple.pm', <<'---' );
402 package Simple::Not;
403 $VERSION = '1.23';
404 ---
405
406   $dist->regen;
407   my $file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm';
408   my $pm_info = Module::Metadata->new_from_file( $file );
409
410   is( $pm_info->name, undef, 'no default package' );
411   is( $pm_info->version, undef, 'no version w/o default package' );
412 }
413
414 {
415   # Module 'Simple.pm' contains an alpha version
416   # constructor should report first $VERSION found
417   $dist->change_file( 'lib/Simple.pm', <<'---' );
418 package Simple;
419 $VERSION = '1.23_01';
420 $VERSION = eval $VERSION;
421 ---
422
423   $dist->regen;
424   my $file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm';
425   my $pm_info = Module::Metadata->new_from_file( $file );
426
427   is( $pm_info->version, '1.23_01', 'alpha version reported');
428
429   # NOTE the following test has be done this way because Test::Builder is
430   # too smart for our own good and tries to see if the version object is a
431   # dual-var, which breaks with alpha versions:
432   #    Argument "1.23_0100" isn't numeric in addition (+) at
433   #    /usr/lib/perl5/5.8.7/Test/Builder.pm line 505.
434
435   ok( $pm_info->version > 1.23, 'alpha version greater than non');
436 }
437
438 # revert to pristine state
439 $dist->regen( clean => 1 );
440
441 # parse $VERSION lines scripts for package main
442 my @scripts = (
443   <<'---', # package main declared
444 #!perl -w
445 package main;
446 $VERSION = '0.01';
447 ---
448   <<'---', # on first non-comment line, non declared package main
449 #!perl -w
450 $VERSION = '0.01';
451 ---
452   <<'---', # after non-comment line
453 #!perl -w
454 use strict;
455 $VERSION = '0.01';
456 ---
457   <<'---', # 1st declared package
458 #!perl -w
459 package main;
460 $VERSION = '0.01';
461 package _private;
462 $VERSION = '999';
463 ---
464   <<'---', # 2nd declared package
465 #!perl -w
466 package _private;
467 $VERSION = '999';
468 package main;
469 $VERSION = '0.01';
470 ---
471   <<'---', # split package
472 #!perl -w
473 package main;
474 package _private;
475 $VERSION = '999';
476 package main;
477 $VERSION = '0.01';
478 ---
479   <<'---', # define 'main' version from other package
480 package _private;
481 $::VERSION = 0.01;
482 $VERSION = '999';
483 ---
484   <<'---', # define 'main' version from other package
485 package _private;
486 $VERSION = '999';
487 $::VERSION = 0.01;
488 ---
489 );
490
491 my ( $i, $n ) = ( 1, scalar( @scripts ) );
492 foreach my $script ( @scripts ) {
493   $dist->change_file( 'bin/simple.plx', $script );
494   $dist->regen;
495   my $pm_info = Module::Metadata->new_from_file(
496                File::Spec->catfile( 'bin', 'simple.plx' ) );
497
498   is( $pm_info->version, '0.01', "correct script version ($i of $n)" );
499   $i++;
500 }
501
502 {
503   # examine properties of a module: name, pod, etc
504   $dist->change_file( 'lib/Simple.pm', <<'---' );
505 package Simple;
506 $VERSION = '0.01';
507 package Simple::Ex;
508 $VERSION = '0.02';
509
510 =head1 NAME
511
512 Simple - It's easy.
513
514 =head1 AUTHOR
515
516 Simple Simon
517
518 You can find me on the IRC channel
519 #simon on irc.perl.org.
520
521 =cut
522 ---
523   $dist->regen;
524
525   my $pm_info = Module::Metadata->new_from_module(
526              $dist->name, inc => [ 'lib', @INC ] );
527
528   is( $pm_info->name, 'Simple', 'found default package' );
529   is( $pm_info->version, '0.01', 'version for default package' );
530
531   # got correct version for secondary package
532   is( $pm_info->version( 'Simple::Ex' ), '0.02',
533       'version for secondary package' );
534
535   my $filename = $pm_info->filename;
536   ok( defined( $filename ) && -e $filename,
537       'filename() returns valid path to module file' );
538
539   my @packages = $pm_info->packages_inside;
540   is( @packages, 2, 'found correct number of packages' );
541   is( $packages[0], 'Simple', 'packages stored in order found' );
542
543   # we can detect presence of pod regardless of whether we are collecting it
544   ok( $pm_info->contains_pod, 'contains_pod() succeeds' );
545
546   my @pod = $pm_info->pod_inside;
547   is_deeply( \@pod, [qw(NAME AUTHOR)], 'found all pod sections' );
548
549   is( $pm_info->pod('NONE') , undef,
550       'return undef() if pod section not present' );
551
552   is( $pm_info->pod('NAME'), undef,
553       'return undef() if pod section not collected' );
554
555
556   # collect_pod
557   $pm_info = Module::Metadata->new_from_module(
558                $dist->name, inc => [ 'lib', @INC ], collect_pod => 1 );
559
560   my %pod;
561   for my $section (qw(NAME AUTHOR)) {
562     my $content = $pm_info->pod( $section );
563     if ( $content ) {
564       $content =~ s/^\s+//;
565       $content =~ s/\s+$//;
566     }
567     $pod{$section} = $content;
568   }
569   my %expected = (
570     NAME   => q|Simple - It's easy.|,
571     AUTHOR => <<'EXPECTED'
572 Simple Simon
573
574 You can find me on the IRC channel
575 #simon on irc.perl.org.
576 EXPECTED
577   );
578   for my $text (values %expected) {
579     $text =~ s/^\s+//;
580     $text =~ s/\s+$//;
581   }
582   is( $pod{NAME},   $expected{NAME},   'collected NAME pod section' );
583   is( $pod{AUTHOR}, $expected{AUTHOR}, 'collected AUTHOR pod section' );
584 }
585
586 {
587   # test things that look like POD, but aren't
588 $dist->change_file( 'lib/Simple.pm', <<'---' );
589 package Simple;
590
591 =YES THIS STARTS POD
592
593 our $VERSION = '999';
594
595 =cute
596
597 our $VERSION = '666';
598
599 =cut
600
601 *foo
602 =*no_this_does_not_start_pod;
603
604 our $VERSION = '1.23';
605
606 ---
607   $dist->regen;
608   my $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
609   is( $pm_info->name, 'Simple', 'found default package' );
610   is( $pm_info->version, '1.23', 'version for default package' );
611 }
612
613 {
614   # Make sure processing stops after __DATA__
615   $dist->change_file( 'lib/Simple.pm', <<'---' );
616 package Simple;
617 $VERSION = '0.01';
618 __DATA__
619 *UNIVERSAL::VERSION = sub {
620   foo();
621 };
622 ---
623   $dist->regen;
624
625   my $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
626   is( $pm_info->name, 'Simple', 'found default package' );
627   is( $pm_info->version, '0.01', 'version for default package' );
628   my @packages = $pm_info->packages_inside;
629   is_deeply(\@packages, ['Simple'], 'packages inside');
630 }
631
632 {
633   # Make sure we handle version.pm $VERSIONs well
634   $dist->change_file( 'lib/Simple.pm', <<'---' );
635 package Simple;
636 $VERSION = version->new('0.60.' . (qw$Revision: 128 $)[1]);
637 package Simple::Simon;
638 $VERSION = version->new('0.61.' . (qw$Revision: 129 $)[1]);
639 ---
640   $dist->regen;
641
642   my $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
643   is( $pm_info->name, 'Simple', 'found default package' );
644   is( $pm_info->version, '0.60.128', 'version for default package' );
645   my @packages = $pm_info->packages_inside;
646   is_deeply([sort @packages], ['Simple', 'Simple::Simon'], 'packages inside');
647   is( $pm_info->version('Simple::Simon'), '0.61.129', 'version for embedded package' );
648 }
649
650 # check that package_versions_from_directory works
651
652 {
653   $dist->change_file( 'lib/Simple.pm', <<'---' );
654 package Simple;
655 $VERSION = '0.01';
656 package Simple::Ex;
657 $VERSION = '0.02';
658 {
659   package main; # should ignore this
660 }
661 {
662   package DB; # should ignore this
663 }
664 {
665   package Simple::_private; # should ignore this
666 }
667
668 =head1 NAME
669
670 Simple - It's easy.
671
672 =head1 AUTHOR
673
674 Simple Simon
675
676 =cut
677 ---
678   $dist->regen;
679
680   my $exp_pvfd = {
681     'Simple' => {
682       'file' => 'Simple.pm',
683       'version' => '0.01'
684     },
685     'Simple::Ex' => {
686       'file' => 'Simple.pm',
687       'version' => '0.02'
688     }
689   };
690
691   my $got_pvfd = Module::Metadata->package_versions_from_directory('lib');
692
693   is_deeply( $got_pvfd, $exp_pvfd, "package_version_from_directory()" )
694     or diag explain $got_pvfd;
695
696 {
697   my $got_provides = Module::Metadata->provides(dir => 'lib', version => 2);
698   my $exp_provides = {
699     'Simple' => {
700       'file' => 'lib/Simple.pm',
701       'version' => '0.01'
702     },
703     'Simple::Ex' => {
704       'file' => 'lib/Simple.pm',
705       'version' => '0.02'
706     }
707   };
708
709   is_deeply( $got_provides, $exp_provides, "provides()" )
710     or diag explain $got_provides;
711 }
712
713 {
714   my $got_provides = Module::Metadata->provides(dir => 'lib', prefix => 'other', version => 1.4);
715   my $exp_provides = {
716     'Simple' => {
717       'file' => 'other/Simple.pm',
718       'version' => '0.01'
719     },
720     'Simple::Ex' => {
721       'file' => 'other/Simple.pm',
722       'version' => '0.02'
723     }
724   };
725
726   is_deeply( $got_provides, $exp_provides, "provides()" )
727     or diag explain $got_provides;
728 }
729 }
730
731 # Check package_versions_from_directory with regard to case-sensitivity
732 {
733   $dist->change_file( 'lib/Simple.pm', <<'---' );
734 package simple;
735 $VERSION = '0.01';
736 ---
737   $dist->regen;
738
739   my $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
740   is( $pm_info->name, undef, 'no default package' );
741   is( $pm_info->version, undef, 'version for default package' );
742   is( $pm_info->version('simple'), '0.01', 'version for lower-case package' );
743   is( $pm_info->version('Simple'), undef, 'version for capitalized package' );
744   ok( $pm_info->is_indexable(), 'an indexable package is found' );
745   ok( $pm_info->is_indexable('simple'), 'the simple package is indexable' );
746   ok( !$pm_info->is_indexable('Simple'), 'the Simple package would not be indexed' );
747 }
748
749 {
750   $dist->change_file( 'lib/Simple.pm', <<'---' );
751 package simple;
752 $VERSION = '0.01';
753 package Simple;
754 $VERSION = '0.02';
755 package SiMpLe;
756 $VERSION = '0.03';
757 ---
758   $dist->regen;
759
760   my $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
761   is( $pm_info->name, 'Simple', 'found default package' );
762   is( $pm_info->version, '0.02', 'version for default package' );
763   is( $pm_info->version('simple'), '0.01', 'version for lower-case package' );
764   is( $pm_info->version('Simple'), '0.02', 'version for capitalized package' );
765   is( $pm_info->version('SiMpLe'), '0.03', 'version for mixed-case package' );
766   ok( $pm_info->is_indexable('simple'), 'the simple package is indexable' );
767   ok( $pm_info->is_indexable('Simple'), 'the Simple package is indexable' );
768 }
769
770 {
771   $dist->change_file( 'lib/Simple.pm', <<'---' );
772 package ## hide from PAUSE
773    simple;
774 $VERSION = '0.01';
775 ---
776
777   $dist->regen;
778
779   my $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
780   is( $pm_info->name, undef, 'no package names found' );
781   ok( !$pm_info->is_indexable('simple'), 'the simple package would not be indexed' );
782   ok( !$pm_info->is_indexable('Simple'), 'the Simple package would not be indexed' );
783   ok( !$pm_info->is_indexable(), 'no indexable package is found' );
784 }