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