72dee4900e91076a08eb4e03ea3cc50895995bf4
[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 # format: expected version => code snippet
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
222 # format: expected package name => code snippet
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
262 # 2 tests per each pair of @modules, @pkg_names entry
263 plan tests => 63 + ( @modules ) + ( @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 # fail on invalid filename
292 my $file = File::Spec->catfile( 'Foo', 'Bar.pm' );
293 $pm_info = Module::Metadata->new_from_file( $file, inc => [] );
294 ok( !defined( $pm_info ), 'fail if can\'t find module by file name' );
295
296
297 # construct from module filename
298 $file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm';
299 $pm_info = Module::Metadata->new_from_file( $file );
300 ok( defined( $pm_info ), 'new_from_file() succeeds' );
301
302 # construct from filehandle
303 my $handle = IO::File->new($file);
304 $pm_info = Module::Metadata->new_from_handle( $handle, $file );
305 ok( defined( $pm_info ), 'new_from_handle() succeeds' );
306 $pm_info = Module::Metadata->new_from_handle( $handle );
307 is( $pm_info, undef, "new_from_handle() without filename returns undef" );
308 close($handle);
309
310 # construct from module name, using custom include path
311 $pm_info = Module::Metadata->new_from_module(
312              $dist->name, inc => [ 'lib', @INC ] );
313 ok( defined( $pm_info ), 'new_from_module() succeeds' );
314
315
316 # iterate through @modules pairwise
317 my $test_case = 0;
318 while (++$test_case and my ($expected_version, $code) = splice @modules, 0, 2 ) {
319  SKIP: {
320     skip( "No our() support until perl 5.6", 2 )
321         if $] < 5.006 && $code =~ /\bour\b/;
322     skip( "No package NAME VERSION support until perl 5.11.1", 2 )
323         if $] < 5.011001 && $code =~ /package\s+[\w\:\']+\s+v?[0-9._]+/;
324
325     $dist->change_file( 'lib/Simple.pm', $code );
326     $dist->regen;
327
328     my $warnings = '';
329     local $SIG{__WARN__} = sub { $warnings .= $_ for @_ };
330     my $pm_info = Module::Metadata->new_from_file( $file );
331
332     # Test::Builder will prematurely numify objects, so use this form
333     my $errs;
334     my $got = $pm_info->version;
335
336     is(
337       $got,
338       $expected_version,
339       "case $test_case: correct module version ("
340         . (defined $expected_version? "'$expected_version'" : 'undef')
341         . ')'
342     )
343     or $errs++;
344
345     is( $warnings, '', "case $test_case: no warnings from parsing" ) or $errs++;
346     diag "Got: '$got'\nModule contents:\n$code" if $errs;
347   }
348 }
349
350 # revert to pristine state
351 $dist->regen( clean => 1 );
352
353 $test_case = 0;
354 while (++$test_case and my ($expected_name, $code) = splice @pkg_names, 0, 2) {
355     $dist->change_file( 'lib/Simple.pm', $code);
356     $dist->regen;
357
358     my $warnings = '';
359     local $SIG{__WARN__} = sub { $warnings .= $_ for @_ };
360     my $pm_info = Module::Metadata->new_from_file( $file );
361
362     # Test::Builder will prematurely numify objects, so use this form
363     my $errs;
364     my @got = $pm_info->packages_inside();
365     is_deeply( \@got, $expected_name,
366                "case $test_case: correct package names (expected '" . join(', ', @$expected_name) . "')" )
367             or $errs++;
368     is( $warnings, '', "case $test_case: no warnings from parsing" ) or $errs++;
369     diag "Got: '" . join(', ', @got) . "'\nModule contents:\n$code" if $errs;
370 }
371
372 # revert to pristine state
373 $dist->regen( clean => 1 );
374
375 # Find each package only once
376 $dist->change_file( 'lib/Simple.pm', <<'---' );
377 package Simple;
378 $VERSION = '1.23';
379 package Error::Simple;
380 $VERSION = '2.34';
381 package Simple;
382 ---
383
384 $dist->regen;
385
386 $pm_info = Module::Metadata->new_from_file( $file );
387
388 my @packages = $pm_info->packages_inside;
389 is( @packages, 2, 'record only one occurence of each package' );
390
391
392 # Module 'Simple.pm' does not contain package 'Simple';
393 # constructor should not complain, no default module name or version
394 $dist->change_file( 'lib/Simple.pm', <<'---' );
395 package Simple::Not;
396 $VERSION = '1.23';
397 ---
398
399 $dist->regen;
400 $pm_info = Module::Metadata->new_from_file( $file );
401
402 is( $pm_info->name, undef, 'no default package' );
403 is( $pm_info->version, undef, 'no version w/o default package' );
404
405 # Module 'Simple.pm' contains an alpha version
406 # constructor should report first $VERSION found
407 $dist->change_file( 'lib/Simple.pm', <<'---' );
408 package Simple;
409 $VERSION = '1.23_01';
410 $VERSION = eval $VERSION;
411 ---
412
413 $dist->regen;
414 $pm_info = Module::Metadata->new_from_file( $file );
415
416 is( $pm_info->version, '1.23_01', 'alpha version reported');
417
418 # NOTE the following test has be done this way because Test::Builder is
419 # too smart for our own good and tries to see if the version object is a
420 # dual-var, which breaks with alpha versions:
421 #    Argument "1.23_0100" isn't numeric in addition (+) at
422 #    /usr/lib/perl5/5.8.7/Test/Builder.pm line 505.
423
424 ok( $pm_info->version > 1.23, 'alpha version greater than non');
425
426 # revert to pristine state
427 $dist->regen( clean => 1 );
428
429 # parse $VERSION lines scripts for package main
430 my @scripts = (
431   <<'---', # package main declared
432 #!perl -w
433 package main;
434 $VERSION = '0.01';
435 ---
436   <<'---', # on first non-comment line, non declared package main
437 #!perl -w
438 $VERSION = '0.01';
439 ---
440   <<'---', # after non-comment line
441 #!perl -w
442 use strict;
443 $VERSION = '0.01';
444 ---
445   <<'---', # 1st declared package
446 #!perl -w
447 package main;
448 $VERSION = '0.01';
449 package _private;
450 $VERSION = '999';
451 ---
452   <<'---', # 2nd declared package
453 #!perl -w
454 package _private;
455 $VERSION = '999';
456 package main;
457 $VERSION = '0.01';
458 ---
459   <<'---', # split package
460 #!perl -w
461 package main;
462 package _private;
463 $VERSION = '999';
464 package main;
465 $VERSION = '0.01';
466 ---
467   <<'---', # define 'main' version from other package
468 package _private;
469 $::VERSION = 0.01;
470 $VERSION = '999';
471 ---
472   <<'---', # define 'main' version from other package
473 package _private;
474 $VERSION = '999';
475 $::VERSION = 0.01;
476 ---
477 );
478
479 my ( $i, $n ) = ( 1, scalar( @scripts ) );
480 foreach my $script ( @scripts ) {
481   $dist->change_file( 'bin/simple.plx', $script );
482   $dist->regen;
483   $pm_info = Module::Metadata->new_from_file(
484                File::Spec->catfile( 'bin', 'simple.plx' ) );
485
486   is( $pm_info->version, '0.01', "correct script version ($i of $n)" );
487   $i++;
488 }
489
490
491 # examine properties of a module: name, pod, etc
492 $dist->change_file( 'lib/Simple.pm', <<'---' );
493 package Simple;
494 $VERSION = '0.01';
495 package Simple::Ex;
496 $VERSION = '0.02';
497
498 =head1 NAME
499
500 Simple - It's easy.
501
502 =head1 AUTHOR
503
504 Simple Simon
505
506 You can find me on the IRC channel
507 #simon on irc.perl.org.
508
509 =cut
510 ---
511 $dist->regen;
512
513 $pm_info = Module::Metadata->new_from_module(
514              $dist->name, inc => [ 'lib', @INC ] );
515
516 is( $pm_info->name, 'Simple', 'found default package' );
517 is( $pm_info->version, '0.01', 'version for default package' );
518
519 # got correct version for secondary package
520 is( $pm_info->version( 'Simple::Ex' ), '0.02',
521     'version for secondary package' );
522
523 my $filename = $pm_info->filename;
524 ok( defined( $filename ) && -e $filename,
525     'filename() returns valid path to module file' );
526
527 @packages = $pm_info->packages_inside;
528 is( @packages, 2, 'found correct number of packages' );
529 is( $packages[0], 'Simple', 'packages stored in order found' );
530
531 # we can detect presence of pod regardless of whether we are collecting it
532 ok( $pm_info->contains_pod, 'contains_pod() succeeds' );
533
534 my @pod = $pm_info->pod_inside;
535 is_deeply( \@pod, [qw(NAME AUTHOR)], 'found all pod sections' );
536
537 is( $pm_info->pod('NONE') , undef,
538     'return undef() if pod section not present' );
539
540 is( $pm_info->pod('NAME'), undef,
541     'return undef() if pod section not collected' );
542
543
544 # collect_pod
545 $pm_info = Module::Metadata->new_from_module(
546              $dist->name, inc => [ 'lib', @INC ], collect_pod => 1 );
547
548 {
549   my %pod;
550   for my $section (qw(NAME AUTHOR)) {
551     my $content = $pm_info->pod( $section );
552     if ( $content ) {
553       $content =~ s/^\s+//;
554       $content =~ s/\s+$//;
555     }
556     $pod{$section} = $content;
557   }
558   my %expected = (
559     NAME   => q|Simple - It's easy.|,
560     AUTHOR => <<'EXPECTED'
561 Simple Simon
562
563 You can find me on the IRC channel
564 #simon on irc.perl.org.
565 EXPECTED
566   );
567   for my $text (values %expected) {
568     $text =~ s/^\s+//;
569     $text =~ s/\s+$//;
570   }
571   is( $pod{NAME},   $expected{NAME},   'collected NAME pod section' );
572   is( $pod{AUTHOR}, $expected{AUTHOR}, 'collected AUTHOR pod section' );
573 }
574
575 {
576   # test things that look like POD, but aren't
577 $dist->change_file( 'lib/Simple.pm', <<'---' );
578 package Simple;
579
580 =YES THIS STARTS POD
581
582 our $VERSION = '999';
583
584 =cute
585
586 our $VERSION = '666';
587
588 =cut
589
590 *foo
591 =*no_this_does_not_start_pod;
592
593 our $VERSION = '1.23';
594
595 ---
596   $dist->regen;
597   $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
598   is( $pm_info->name, 'Simple', 'found default package' );
599   is( $pm_info->version, '1.23', 'version for default package' );
600 }
601
602 {
603   # Make sure processing stops after __DATA__
604   $dist->change_file( 'lib/Simple.pm', <<'---' );
605 package Simple;
606 $VERSION = '0.01';
607 __DATA__
608 *UNIVERSAL::VERSION = sub {
609   foo();
610 };
611 ---
612   $dist->regen;
613
614   $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
615   is( $pm_info->name, 'Simple', 'found default package' );
616   is( $pm_info->version, '0.01', 'version for default package' );
617   my @packages = $pm_info->packages_inside;
618   is_deeply(\@packages, ['Simple'], 'packages inside');
619 }
620
621 {
622   # Make sure we handle version.pm $VERSIONs well
623   $dist->change_file( 'lib/Simple.pm', <<'---' );
624 package Simple;
625 $VERSION = version->new('0.60.' . (qw$Revision: 128 $)[1]);
626 package Simple::Simon;
627 $VERSION = version->new('0.61.' . (qw$Revision: 129 $)[1]);
628 ---
629   $dist->regen;
630
631   $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
632   is( $pm_info->name, 'Simple', 'found default package' );
633   is( $pm_info->version, '0.60.128', 'version for default package' );
634   my @packages = $pm_info->packages_inside;
635   is_deeply([sort @packages], ['Simple', 'Simple::Simon'], 'packages inside');
636   is( $pm_info->version('Simple::Simon'), '0.61.129', 'version for embedded package' );
637 }
638
639 # check that package_versions_from_directory works
640
641 $dist->change_file( 'lib/Simple.pm', <<'---' );
642 package Simple;
643 $VERSION = '0.01';
644 package Simple::Ex;
645 $VERSION = '0.02';
646 {
647   package main; # should ignore this
648 }
649 {
650   package DB; # should ignore this
651 }
652 {
653   package Simple::_private; # should ignore this
654 }
655
656 =head1 NAME
657
658 Simple - It's easy.
659
660 =head1 AUTHOR
661
662 Simple Simon
663
664 =cut
665 ---
666 $dist->regen;
667
668 my $exp_pvfd = {
669   'Simple' => {
670     'file' => 'Simple.pm',
671     'version' => '0.01'
672   },
673   'Simple::Ex' => {
674     'file' => 'Simple.pm',
675     'version' => '0.02'
676   }
677 };
678
679 my $got_pvfd = Module::Metadata->package_versions_from_directory('lib');
680
681 is_deeply( $got_pvfd, $exp_pvfd, "package_version_from_directory()" )
682   or diag explain $got_pvfd;
683
684 {
685   my $got_provides = Module::Metadata->provides(dir => 'lib', version => 2);
686   my $exp_provides = {
687     'Simple' => {
688       'file' => 'lib/Simple.pm',
689       'version' => '0.01'
690     },
691     'Simple::Ex' => {
692       'file' => 'lib/Simple.pm',
693       'version' => '0.02'
694     }
695   };
696
697   is_deeply( $got_provides, $exp_provides, "provides()" )
698     or diag explain $got_provides;
699 }
700
701 {
702   my $got_provides = Module::Metadata->provides(dir => 'lib', prefix => 'other', version => 1.4);
703   my $exp_provides = {
704     'Simple' => {
705       'file' => 'other/Simple.pm',
706       'version' => '0.01'
707     },
708     'Simple::Ex' => {
709       'file' => 'other/Simple.pm',
710       'version' => '0.02'
711     }
712   };
713
714   is_deeply( $got_provides, $exp_provides, "provides()" )
715     or diag explain $got_provides;
716 }
717
718 # Check package_versions_from_directory with regard to case-sensitivity
719 {
720   $dist->change_file( 'lib/Simple.pm', <<'---' );
721 package simple;
722 $VERSION = '0.01';
723 ---
724   $dist->regen;
725
726   $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
727   is( $pm_info->name, undef, 'no default package' );
728   is( $pm_info->version, undef, 'version for default package' );
729   is( $pm_info->version('simple'), '0.01', 'version for lower-case package' );
730   is( $pm_info->version('Simple'), undef, 'version for capitalized package' );
731   ok( $pm_info->is_indexable(), 'an indexable package is found' );
732   ok( $pm_info->is_indexable('simple'), 'the simple package is indexable' );
733   ok( !$pm_info->is_indexable('Simple'), 'the Simple package would not be indexed' );
734
735   $dist->change_file( 'lib/Simple.pm', <<'---' );
736 package simple;
737 $VERSION = '0.01';
738 package Simple;
739 $VERSION = '0.02';
740 package SiMpLe;
741 $VERSION = '0.03';
742 ---
743   $dist->regen;
744
745   $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
746   is( $pm_info->name, 'Simple', 'found default package' );
747   is( $pm_info->version, '0.02', 'version for default package' );
748   is( $pm_info->version('simple'), '0.01', 'version for lower-case package' );
749   is( $pm_info->version('Simple'), '0.02', 'version for capitalized package' );
750   is( $pm_info->version('SiMpLe'), '0.03', 'version for mixed-case package' );
751   ok( $pm_info->is_indexable('simple'), 'the simple package is indexable' );
752   ok( $pm_info->is_indexable('Simple'), 'the Simple package is indexable' );
753
754   $dist->change_file( 'lib/Simple.pm', <<'---' );
755 package ## hide from PAUSE
756    simple;
757 $VERSION = '0.01';
758 ---
759
760   $dist->regen;
761
762   $pm_info = Module::Metadata->new_from_file('lib/Simple.pm');
763   is( $pm_info->name, undef, 'no package names found' );
764   ok( !$pm_info->is_indexable('simple'), 'the simple package would not be indexed' );
765   ok( !$pm_info->is_indexable('Simple'), 'the Simple package would not be indexed' );
766   ok( !$pm_info->is_indexable(), 'no indexable package is found' );
767 }