keep test cases in lists, rather than a hash, for consistent ordering, and providing...
[p5sagit/Module-Metadata.git] / t / metadata.t
CommitLineData
7a4e305a 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
5use strict;
eed8b6fa 6use warnings;
7a4e305a 7use lib 't/lib';
c8b69ebe 8use Test::More;
f33c0a6c 9use IO::File;
7a4e305a 10use MBTest;
11
975132cb 12my $undef;
13
7a4e305a 14# parse various module $VERSION lines
4284ed53 15# format: expected version => code snippet
7a4e305a 16my @modules = (
975132cb 17 $undef => <<'---', # no $VERSION line
18package Simple;
19---
20 $undef => <<'---', # undefined $VERSION
21package Simple;
22our $VERSION;
23---
7a4e305a 24 '1.23' => <<'---', # declared & defined on same line with 'our'
25package Simple;
26our $VERSION = '1.23';
27---
28 '1.23' => <<'---', # declared & defined on separate lines with 'our'
29package Simple;
30our $VERSION;
31$VERSION = '1.23';
32---
ad924b83 33 '1.23' => <<'---', # commented & defined on same line
34package Simple;
35our $VERSION = '1.23'; # our $VERSION = '4.56';
36---
37 '1.23' => <<'---', # commented & defined on separate lines
38package Simple;
39# our $VERSION = '4.56';
40our $VERSION = '1.23';
41---
7a4e305a 42 '1.23' => <<'---', # use vars
43package Simple;
44use vars qw( $VERSION );
45$VERSION = '1.23';
46---
47 '1.23' => <<'---', # choose the right default package based on package/file name
48package Simple::_private;
49$VERSION = '0';
50package Simple;
51$VERSION = '1.23'; # this should be chosen for version
52---
53 '1.23' => <<'---', # just read the first $VERSION line
54package 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)
59package Simple;
60$VERSION = '1.23';
61package Error::Simple;
62$VERSION = '2.34';
63package Simple;
64---
65 '1.23' => <<'---', # just read the first $VERSION line in reopened package (2)
66package Simple;
67package Error::Simple;
68$VERSION = '2.34';
69package Simple;
70$VERSION = '1.23';
71---
72 '1.23' => <<'---', # mentions another module's $VERSION
73package Simple;
74$VERSION = '1.23';
75if ( $Other::VERSION ) {
76 # whatever
77}
78---
79 '1.23' => <<'---', # mentions another module's $VERSION in a different package
80package Simple;
81$VERSION = '1.23';
82package Simple2;
83if ( $Simple::VERSION ) {
84 # whatever
85}
86---
87 '1.23' => <<'---', # $VERSION checked only in assignments, not regexp ops
88package Simple;
89$VERSION = '1.23';
90if ( $VERSION =~ /1\.23/ ) {
91 # whatever
92}
93---
94 '1.23' => <<'---', # $VERSION checked only in assignments, not relational ops
95package Simple;
96$VERSION = '1.23';
97if ( $VERSION == 3.45 ) {
98 # whatever
99}
100---
101 '1.23' => <<'---', # $VERSION checked only in assignments, not relational ops
102package Simple;
103$VERSION = '1.23';
104package Simple2;
105if ( $Simple::VERSION == 3.45 ) {
106 # whatever
107}
108---
109 '1.23' => <<'---', # Fully qualified $VERSION declared in package
110package Simple;
111$Simple::VERSION = 1.23;
112---
113 '1.23' => <<'---', # Differentiate fully qualified $VERSION in a package
114package Simple;
115$Simple2::VERSION = '999';
116$Simple::VERSION = 1.23;
117---
118 '1.23' => <<'---', # Differentiate fully qualified $VERSION and unqualified
119package 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
131package Simple;
132( $VERSION ) = '1.23';
133---
134 '1.23' => <<'---', # $VERSION wrapped in parens - no space inside
135package Simple;
136($VERSION) = '1.23';
137---
138 '1.23' => <<'---', # $VERSION follows a spurious 'package' in a quoted construct
139package Simple;
140__PACKAGE__->mk_accessors(qw(
141 program socket proc
142 package filename line codeline subroutine finished));
143
144our $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'
159package Simple;
160our $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---
92ad06ed 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---
710f253f 194 $undef => <<'---', # package NAME BLOCK, undef $VERSION
195package Simple {
196 our $VERSION;
197}
198---
199 '1.23' => <<'---', # package NAME BLOCK, with $VERSION
200package Simple {
201 our $VERSION = '1.23';
202}
203---
204 '1.23' => <<'---', # package NAME VERSION BLOCK
205package Simple 1.23 {
206 1;
207}
208---
209 'v1.2.3_4' => <<'---', # package NAME VERSION BLOCK
210package Simple v1.2.3_4 {
211 1;
212}
213---
72a35bb9 214 '0' => <<'---', # set from separately-initialised variable
215package Simple;
216 our $CVSVERSION = '$Revision: 1.7 $';
217 our ($VERSION) = ($CVSVERSION =~ /(\d+\.\d+)/);
218}
219---
7a4e305a 220);
7a4e305a 221
4284ed53 222# format: expected package name => code snippet
8e4bef01 223my @pkg_names = (
224 [ 'Simple' ] => <<'---', # package NAME
225package Simple;
226---
227 [ 'Simple::Edward' ] => <<'---', # package NAME::SUBNAME
228package Simple::Edward;
229---
230 [ 'Simple::Edward::' ] => <<'---', # package NAME::SUBNAME::
231package Simple::Edward::;
232---
233 [ "Simple'Edward" ] => <<'---', # package NAME'SUBNAME
234package Simple'Edward;
235---
236 [ "Simple'Edward::" ] => <<'---', # package NAME'SUBNAME::
237package Simple'Edward::;
238---
239 [ 'Simple::::Edward' ] => <<'---', # package NAME::::SUBNAME
240package Simple::::Edward;
241---
242 [ '::Simple::Edward' ] => <<'---', # package ::NAME::SUBNAME
243package ::Simple::Edward;
244---
245 [ 'main' ] => <<'---', # package NAME:SUBNAME (fail)
246package Simple:Edward;
247---
248 [ 'main' ] => <<'---', # package NAME' (fail)
249package Simple';
250---
251 [ 'main' ] => <<'---', # package NAME::SUBNAME' (fail)
252package Simple::Edward';
253---
254 [ 'main' ] => <<'---', # package NAME''SUBNAME (fail)
255package Simple''Edward;
256---
257 [ 'main' ] => <<'---', # package NAME-SUBNAME (fail)
258package Simple-Edward;
259---
260);
8e4bef01 261
4284ed53 262# 2 tests per each pair of @modules, @pkg_names entry
263plan tests => 63 + ( @modules ) + ( @pkg_names );
7a4e305a 264
265require_ok('Module::Metadata');
266
4284ed53 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}
1abfcc9a 273
274#########################
275
7a4e305a 276my $tmp = MBTest->tmpdir;
277
278use DistGen;
279my $dist = DistGen->new( dir => $tmp );
280$dist->regen;
281
282$dist->chdir_in;
283
7a4e305a 284
285# fail on invalid module name
286my $pm_info = Module::Metadata->new_from_module(
141ef4bd 287 'Foo::Bar', inc => [] );
7a4e305a 288ok( !defined( $pm_info ), 'fail if can\'t find module by module name' );
289
290
291# fail on invalid filename
292my $file = File::Spec->catfile( 'Foo', 'Bar.pm' );
293$pm_info = Module::Metadata->new_from_file( $file, inc => [] );
294ok( !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 );
300ok( defined( $pm_info ), 'new_from_file() succeeds' );
301
f33c0a6c 302# construct from filehandle
303my $handle = IO::File->new($file);
304$pm_info = Module::Metadata->new_from_handle( $handle, $file );
305ok( defined( $pm_info ), 'new_from_handle() succeeds' );
306$pm_info = Module::Metadata->new_from_handle( $handle );
307is( $pm_info, undef, "new_from_handle() without filename returns undef" );
02a3d478 308close($handle);
f33c0a6c 309
7a4e305a 310# construct from module name, using custom include path
311$pm_info = Module::Metadata->new_from_module(
141ef4bd 312 $dist->name, inc => [ 'lib', @INC ] );
7a4e305a 313ok( defined( $pm_info ), 'new_from_module() succeeds' );
314
315
4284ed53 316# iterate through @modules pairwise
317my $test_case = 0;
318while (++$test_case and my ($expected_version, $code) = splice @modules, 0, 2 ) {
7a4e305a 319 SKIP: {
320 skip( "No our() support until perl 5.6", 2 )
4284ed53 321 if $] < 5.006 && $code =~ /\bour\b/;
7a4e305a 322 skip( "No package NAME VERSION support until perl 5.11.1", 2 )
4284ed53 323 if $] < 5.011001 && $code =~ /package\s+[\w\:\']+\s+v?[0-9._]+/;
7a4e305a 324
4284ed53 325 $dist->change_file( 'lib/Simple.pm', $code );
7a4e305a 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;
975132cb 334 my $got = $pm_info->version;
4284ed53 335 if ( defined $expected_version ) {
336 ok( $got eq $expected_version,
337 "case $test_case: correct module version (expected '$expected_version')" )
975132cb 338 or $errs++;
339 } else {
340 ok( !defined($got),
4284ed53 341 "case $test_case: correct module version (expected undef)" )
975132cb 342 or $errs++;
343 }
4284ed53 344 is( $warnings, '', "case $test_case: no warnings from parsing" ) or $errs++;
345 diag "Got: '$got'\nModule contents:\n$code" if $errs;
7a4e305a 346 }
347}
348
349# revert to pristine state
8e4bef01 350$dist->regen( clean => 1 );
351
4284ed53 352$test_case = 0;
353while (++$test_case and my ($expected_name, $code) = splice @pkg_names, 0, 2) {
354 $dist->change_file( 'lib/Simple.pm', $code);
8e4bef01 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();
4284ed53 364 is_deeply( \@got, $expected_name,
365 "case $test_case: correct package names (expected '" . join(', ', @$expected_name) . "')" )
8e4bef01 366 or $errs++;
4284ed53 367 is( $warnings, '', "case $test_case: no warnings from parsing" ) or $errs++;
368 diag "Got: '" . join(', ', @got) . "'\nModule contents:\n$code" if $errs;
8e4bef01 369}
370
371# revert to pristine state
7a4e305a 372$dist->regen( clean => 1 );
373
374# Find each package only once
375$dist->change_file( 'lib/Simple.pm', <<'---' );
376package Simple;
377$VERSION = '1.23';
378package Error::Simple;
379$VERSION = '2.34';
380package Simple;
381---
382
383$dist->regen;
384
385$pm_info = Module::Metadata->new_from_file( $file );
386
387my @packages = $pm_info->packages_inside;
388is( @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', <<'---' );
394package Simple::Not;
395$VERSION = '1.23';
396---
397
398$dist->regen;
399$pm_info = Module::Metadata->new_from_file( $file );
400
401is( $pm_info->name, undef, 'no default package' );
402is( $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', <<'---' );
407package 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
415is( $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
423ok( $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
429my @scripts = (
430 <<'---', # package main declared
431#!perl -w
432package 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
441use strict;
442$VERSION = '0.01';
443---
444 <<'---', # 1st declared package
445#!perl -w
446package main;
447$VERSION = '0.01';
448package _private;
449$VERSION = '999';
450---
451 <<'---', # 2nd declared package
452#!perl -w
453package _private;
454$VERSION = '999';
455package main;
456$VERSION = '0.01';
457---
458 <<'---', # split package
459#!perl -w
460package main;
461package _private;
462$VERSION = '999';
463package main;
464$VERSION = '0.01';
465---
466 <<'---', # define 'main' version from other package
467package _private;
468$::VERSION = 0.01;
469$VERSION = '999';
470---
471 <<'---', # define 'main' version from other package
472package _private;
473$VERSION = '999';
474$::VERSION = 0.01;
475---
476);
477
478my ( $i, $n ) = ( 1, scalar( @scripts ) );
479foreach my $script ( @scripts ) {
480 $dist->change_file( 'bin/simple.plx', $script );
481 $dist->regen;
482 $pm_info = Module::Metadata->new_from_file(
141ef4bd 483 File::Spec->catfile( 'bin', 'simple.plx' ) );
7a4e305a 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', <<'---' );
492package Simple;
493$VERSION = '0.01';
494package Simple::Ex;
495$VERSION = '0.02';
388bf282 496
7a4e305a 497=head1 NAME
498
499Simple - It's easy.
500
501=head1 AUTHOR
502
503Simple Simon
504
81ce8c82 505You can find me on the IRC channel
506#simon on irc.perl.org.
507
7a4e305a 508=cut
509---
510$dist->regen;
511
512$pm_info = Module::Metadata->new_from_module(
513 $dist->name, inc => [ 'lib', @INC ] );
514
515is( $pm_info->name, 'Simple', 'found default package' );
516is( $pm_info->version, '0.01', 'version for default package' );
517
518# got correct version for secondary package
519is( $pm_info->version( 'Simple::Ex' ), '0.02',
520 'version for secondary package' );
521
522my $filename = $pm_info->filename;
523ok( defined( $filename ) && -e $filename,
524 'filename() returns valid path to module file' );
525
526@packages = $pm_info->packages_inside;
527is( @packages, 2, 'found correct number of packages' );
528is( $packages[0], 'Simple', 'packages stored in order found' );
529
530# we can detect presence of pod regardless of whether we are collecting it
531ok( $pm_info->contains_pod, 'contains_pod() succeeds' );
532
533my @pod = $pm_info->pod_inside;
534is_deeply( \@pod, [qw(NAME AUTHOR)], 'found all pod sections' );
535
536is( $pm_info->pod('NONE') , undef,
537 'return undef() if pod section not present' );
538
539is( $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
617f8754 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 }
81ce8c82 557 my %expected = (
558 NAME => q|Simple - It's easy.|,
559 AUTHOR => <<'EXPECTED'
560Simple Simon
561
562You can find me on the IRC channel
563#simon on irc.perl.org.
564EXPECTED
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' );
7a4e305a 572}
7a4e305a 573
574{
a4aafbc2 575 # test things that look like POD, but aren't
576$dist->change_file( 'lib/Simple.pm', <<'---' );
577package Simple;
a4aafbc2 578
cfedad89 579=YES THIS STARTS POD
580
581our $VERSION = '999';
a4aafbc2 582
a4aafbc2 583=cute
a4aafbc2 584
cfedad89 585our $VERSION = '666';
586
587=cut
588
589*foo
590=*no_this_does_not_start_pod;
591
592our $VERSION = '1.23';
a4aafbc2 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{
7a4e305a 602 # Make sure processing stops after __DATA__
603 $dist->change_file( 'lib/Simple.pm', <<'---' );
604package 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', <<'---' );
623package Simple;
624$VERSION = version->new('0.60.' . (qw$Revision: 128 $)[1]);
625package 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
388bf282 638# check that package_versions_from_directory works
639
640$dist->change_file( 'lib/Simple.pm', <<'---' );
641package Simple;
642$VERSION = '0.01';
643package 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
657Simple - It's easy.
658
659=head1 AUTHOR
660
661Simple Simon
662
663=cut
664---
665$dist->regen;
666
667my $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
678my $got_pvfd = Module::Metadata->package_versions_from_directory('lib');
679
ca33f3bd 680is_deeply( $got_pvfd, $exp_pvfd, "package_version_from_directory()" )
388bf282 681 or diag explain $got_pvfd;
ca33f3bd 682
683{
c06d0187 684 my $got_provides = Module::Metadata->provides(dir => 'lib', version => 2);
ca33f3bd 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{
c06d0187 701 my $got_provides = Module::Metadata->provides(dir => 'lib', prefix => 'other', version => 1.4);
ca33f3bd 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}
3c614865 716
717# Check package_versions_from_directory with regard to case-sensitivity
718{
719 $dist->change_file( 'lib/Simple.pm', <<'---' );
720package 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' );
22553051 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' );
3c614865 733
734 $dist->change_file( 'lib/Simple.pm', <<'---' );
735package simple;
736$VERSION = '0.01';
737package Simple;
738$VERSION = '0.02';
739package 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' );
22553051 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', <<'---' );
754package ## 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' );
3c614865 766}