5 use MBTest tests => 53;
7 use_ok 'Module::Build';
8 ensure_blib('Module::Build');
10 my $tmp = MBTest->tmpdir;
12 use Module::Build::ConfigData;
16 module_name => 'Simple',
17 dist_version => '3.14159265',
18 dist_author => [ 'Simple Simon <ss\@somewhere.priv>' ],
19 dist_abstract => 'Something interesting',
22 keywords => [qw(super duper something)],
23 resources => {homepage => 'http://foo.example.com'},
29 my $dist = DistGen->new( dir => $tmp );
30 $dist->change_build_pl( \%metadata );
33 my $simple_file = 'lib/Simple.pm';
34 my $simple2_file = 'lib/Simple2.pm';
36 # Traditional VMS will return the file in in lower case, and is_deeply
37 # does exact case comparisons.
38 # When ODS-5 support is active for preserved case file names we do not
41 my $lower_case_expect = 1;
43 if (eval 'require VMS::Feature') {
44 $vms_efs_case = VMS::Feature::current("efs_case_preserve");
46 my $efs_case = $ENV{'DECC$EFS_CASE_PRESERVE'} || '';
47 $vms_efs_case = $efs_case =~ /^[ET1]/i;
49 $lower_case_expect = 0 if $vms_efs_case;
50 if ($lower_case_expect) {
51 $simple_file = lc($simple_file);
52 $simple2_file = lc($simple2_file);
60 my $mb = Module::Build->new_from_context;
62 ##################################################
64 # Test for valid META.yml
67 my $mb_prereq = { 'Module::Build' => $Module::Build::VERSION };
69 'Module::Build' => int($Module::Build::VERSION * 100)/100
71 my $node = $mb->prepare_metadata( {} );
73 # exists() doesn't seem to work here
74 is $node->{name}, $metadata{module_name};
75 is $node->{version}, $metadata{dist_version};
76 is $node->{abstract}, $metadata{dist_abstract};
77 is_deeply $node->{author}, $metadata{dist_author};
78 is $node->{license}, $metadata{license};
79 is_deeply $node->{configure_requires}, $mb_config_req, 'Add M::B to configure_requires';
80 like $node->{generated_by}, qr{Module::Build};
81 ok defined( $node->{'meta-spec'}{version} ),
82 "'meta-spec' -> 'version' field present in META.yml";
83 ok defined( $node->{'meta-spec'}{url} ),
84 "'meta-spec' -> 'url' field present in META.yml";
85 is_deeply $node->{keywords}, $metadata{meta_add}{keywords};
86 is_deeply $node->{resources}, $metadata{meta_add}{resources};
90 my $mb_prereq = { 'Module::Build' => 0 };
91 $mb->configure_requires( $mb_prereq );
92 my $node = $mb->prepare_metadata( {} );
95 # exists() doesn't seem to work here
96 is_deeply $node->{configure_requires}, $mb_prereq, 'Add M::B to configure_requires';
102 ##################################################
104 # Tests to ensure that the correct packages and versions are
105 # recorded for the 'provides' field of META.yml
107 my $provides; # Used a bunch of times below
109 sub new_build { return Module::Build->new_from_context( quiet => 1, @_ ) }
111 ############################## Single Module
113 # File with corresponding package (w/ or w/o version)
114 # Simple.pm => Simple v1.23
116 $dist->change_file( 'lib/Simple.pm', <<'---' );
120 $dist->regen( clean => 1 );
122 is_deeply($mb->find_dist_packages,
123 {'Simple' => {file => $simple_file,
124 version => '1.23'}});
126 $dist->change_file( 'lib/Simple.pm', <<'---' );
129 $dist->regen( clean => 1 );
131 is_deeply($mb->find_dist_packages,
132 {'Simple' => {file => $simple_file}});
134 # File with no corresponding package (w/ or w/o version)
135 # Simple.pm => Foo::Bar v1.23
137 $dist->change_file( 'lib/Simple.pm', <<'---' );
141 $dist->regen( clean => 1 );
143 is_deeply($mb->find_dist_packages,
144 {'Foo::Bar' => { file => $simple_file,
145 version => '1.23' }});
147 $dist->change_file( 'lib/Simple.pm', <<'---' );
150 $dist->regen( clean => 1 );
152 is_deeply($mb->find_dist_packages,
153 {'Foo::Bar' => { file => $simple_file}});
156 # Single file with multiple differing packages (w/ or w/o version)
157 # Simple.pm => Simple
158 # Simple.pm => Foo::Bar
160 $dist->change_file( 'lib/Simple.pm', <<'---' );
166 $dist->regen( clean => 1 );
168 is_deeply($mb->find_dist_packages,
169 {'Simple' => { file => $simple_file,
171 'Foo::Bar' => { file => $simple_file,
172 version => '1.23' }});
175 $dist->change_file( 'lib/Simple.pm', <<'---' );
177 $VERSION = version->new('0.60.' . (qw$Revision: 128 $)[1]);
178 package Simple::Simon;
179 $VERSION = version->new('0.61.' . (qw$Revision: 129 $)[1]);
182 my $provides = new_build()->prepare_metadata()->{provides};
183 is $provides->{'Simple'}{version}, 'v0.60.128', "Check version";
184 is $provides->{'Simple::Simon'}{version}, 'v0.61.129', "Check version";
185 is ref($provides->{'Simple'}{version}), '', "Versions from prepare_metadata() aren't refs";
186 is ref($provides->{'Simple::Simon'}{version}), '', "Versions from prepare_metadata() aren't refs";
190 # Single file with multiple differing packages, no corresponding package
192 # Simple.pm => Foo::Bar
194 $dist->change_file( 'lib/Simple.pm', <<'---' );
200 $dist->regen( clean => 1 );
202 is_deeply($mb->find_dist_packages,
203 {'Foo' => { file => $simple_file,
205 'Foo::Bar' => { file => $simple_file,
206 version => '1.23' }});
209 # Single file with same package appearing multiple times, no version
210 # only record a single instance
211 # Simple.pm => Simple
212 # Simple.pm => Simple
214 $dist->change_file( 'lib/Simple.pm', <<'---' );
218 $dist->regen( clean => 1 );
220 is_deeply($mb->find_dist_packages,
221 {'Simple' => { file => $simple_file }});
224 # Single file with same package appearing multiple times, single
225 # version 1st package:
226 # Simple.pm => Simple v1.23
227 # Simple.pm => Simple
229 $dist->change_file( 'lib/Simple.pm', <<'---' );
234 $dist->regen( clean => 1 );
236 is_deeply($mb->find_dist_packages,
237 {'Simple' => { file => $simple_file,
238 version => '1.23' }});
241 # Single file with same package appearing multiple times, single
242 # version 2nd package
243 # Simple.pm => Simple
244 # Simple.pm => Simple v1.23
246 $dist->change_file( 'lib/Simple.pm', <<'---' );
251 $dist->regen( clean => 1 );
253 is_deeply($mb->find_dist_packages,
254 {'Simple' => { file => $simple_file,
255 version => '1.23' }});
258 # Single file with same package appearing multiple times, conflicting versions
259 # Simple.pm => Simple v1.23
260 # Simple.pm => Simple v2.34
262 $dist->change_file( 'lib/Simple.pm', <<'---' );
268 $dist->regen( clean => 1 );
270 $err = stderr_of( sub { $mb = new_build() } );
271 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
273 {'Simple' => { file => $simple_file,
274 version => '1.23' }}); # XXX should be 2.34?
275 like( $err, qr/already declared/, ' with conflicting versions reported' );
278 # (Same as above three cases except with no corresponding package)
279 # Simple.pm => Foo v1.23
280 # Simple.pm => Foo v2.34
282 $dist->change_file( 'lib/Simple.pm', <<'---' );
288 $dist->regen( clean => 1 );
289 $err = stderr_of( sub { $mb = new_build() } );
290 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
292 {'Foo' => { file => $simple_file,
293 version => '1.23' }}); # XXX should be 2.34?
294 like( $err, qr/already declared/, ' with conflicting versions reported' );
298 ############################## Multiple Modules
300 # Multiple files with same package, no version
301 # Simple.pm => Simple
302 # Simple2.pm => Simple
304 $dist->change_file( 'lib/Simple.pm', <<'---' );
307 $dist->add_file( 'lib/Simple2.pm', <<'---' );
310 $dist->regen( clean => 1 );
312 is_deeply($mb->find_dist_packages,
313 {'Simple' => { file => $simple_file }});
314 $dist->remove_file( 'lib/Simple2.pm' );
317 # Multiple files with same package, single version in corresponding package
318 # Simple.pm => Simple v1.23
319 # Simple2.pm => Simple
321 $dist->change_file( 'lib/Simple.pm', <<'---' );
325 $dist->add_file( 'lib/Simple2.pm', <<'---' );
328 $dist->regen( clean => 1 );
330 is_deeply($mb->find_dist_packages,
331 {'Simple' => { file => $simple_file,
332 version => '1.23' }});
333 $dist->remove_file( 'lib/Simple2.pm' );
336 # Multiple files with same package,
337 # single version in non-corresponding package
338 # Simple.pm => Simple
339 # Simple2.pm => Simple v1.23
341 $dist->change_file( 'lib/Simple.pm', <<'---' );
344 $dist->add_file( 'lib/Simple2.pm', <<'---' );
348 $dist->regen( clean => 1 );
350 is_deeply($mb->find_dist_packages,
351 {'Simple' => { file => $simple2_file,
352 version => '1.23' }});
353 $dist->remove_file( 'lib/Simple2.pm' );
356 # Multiple files with same package, conflicting versions
357 # Simple.pm => Simple v1.23
358 # Simple2.pm => Simple v2.34
360 $dist->change_file( 'lib/Simple.pm', <<'---' );
364 $dist->add_file( 'lib/Simple2.pm', <<'---' );
368 $dist->regen( clean => 1 );
370 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
372 {'Simple' => { file => $simple_file,
373 version => '1.23' }});
374 like( $err, qr/Found conflicting versions for package/,
375 ' with conflicting versions reported' );
376 $dist->remove_file( 'lib/Simple2.pm' );
379 # Multiple files with same package, multiple agreeing versions
380 # Simple.pm => Simple v1.23
381 # Simple2.pm => Simple v1.23
383 $dist->change_file( 'lib/Simple.pm', <<'---' );
387 $dist->add_file( 'lib/Simple2.pm', <<'---' );
391 $dist->regen( clean => 1 );
393 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
395 {'Simple' => { file => $simple_file,
396 version => '1.23' }});
397 $dist->remove_file( 'lib/Simple2.pm' );
400 ############################################################
402 # (Same as above five cases except with non-corresponding package)
405 # Multiple files with same package, no version
409 $dist->change_file( 'lib/Simple.pm', <<'---' );
412 $dist->add_file( 'lib/Simple2.pm', <<'---' );
415 $dist->regen( clean => 1 );
417 $provides = $mb->find_dist_packages;
418 ok( exists( $provides->{Foo} ) ); # it exist, can't predict which file
419 $dist->remove_file( 'lib/Simple2.pm' );
422 # Multiple files with same package, version in first file
423 # Simple.pm => Foo v1.23
426 $dist->change_file( 'lib/Simple.pm', <<'---' );
430 $dist->add_file( 'lib/Simple2.pm', <<'---' );
433 $dist->regen( clean => 1 );
435 is_deeply($mb->find_dist_packages,
436 {'Foo' => { file => $simple_file,
437 version => '1.23' }});
438 $dist->remove_file( 'lib/Simple2.pm' );
441 # Multiple files with same package, version in second file
443 # Simple2.pm => Foo v1.23
445 $dist->change_file( 'lib/Simple.pm', <<'---' );
448 $dist->add_file( 'lib/Simple2.pm', <<'---' );
452 $dist->regen( clean => 1 );
454 is_deeply($mb->find_dist_packages,
455 {'Foo' => { file => $simple2_file,
456 version => '1.23' }});
457 $dist->remove_file( 'lib/Simple2.pm' );
460 # Multiple files with same package, conflicting versions
461 # Simple.pm => Foo v1.23
462 # Simple2.pm => Foo v2.34
464 $dist->change_file( 'lib/Simple.pm', <<'---' );
468 $dist->add_file( 'lib/Simple2.pm', <<'---' );
472 $dist->regen( clean => 1 );
474 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
475 # XXX Should 'Foo' exist ??? Can't predict values for file & version
476 ok( exists( $provides->{Foo} ) );
477 like( $err, qr/Found conflicting versions for package/,
478 ' with conflicting versions reported' );
479 $dist->remove_file( 'lib/Simple2.pm' );
482 # Multiple files with same package, multiple agreeing versions
483 # Simple.pm => Foo v1.23
484 # Simple2.pm => Foo v1.23
486 $dist->change_file( 'lib/Simple.pm', <<'---' );
490 $dist->add_file( 'lib/Simple2.pm', <<'---' );
494 $dist->regen( clean => 1 );
496 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
497 ok( exists( $provides->{Foo} ) );
498 is( $provides->{Foo}{version}, '1.23' );
499 ok( exists( $provides->{Foo}{file} ) ); # Can't predict which file
500 is( $err, '', ' no conflicts reported' );
501 $dist->remove_file( 'lib/Simple2.pm' );
503 ############################################################
504 # Conflicts among primary & multiple alternatives
506 # multiple files, conflicting version in corresponding file
507 $dist->change_file( 'lib/Simple.pm', <<'---' );
511 $dist->add_file( 'lib/Simple2.pm', <<'---' );
515 $dist->add_file( 'lib/Simple3.pm', <<'---' );
519 $dist->regen( clean => 1 );
520 $err = stderr_of( sub {
523 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
525 {'Simple' => { file => $simple_file,
526 version => '1.23' }});
527 like( $err, qr/Found conflicting versions for package/,
528 ' corresponding package conflicts with multiple alternatives' );
529 $dist->remove_file( 'lib/Simple2.pm' );
530 $dist->remove_file( 'lib/Simple3.pm' );
532 # multiple files, conflicting version in non-corresponding file
533 $dist->change_file( 'lib/Simple.pm', <<'---' );
537 $dist->add_file( 'lib/Simple2.pm', <<'---' );
541 $dist->add_file( 'lib/Simple3.pm', <<'---' );
545 $dist->regen( clean => 1 );
546 $err = stderr_of( sub {
549 $err = stderr_of( sub { $provides = $mb->find_dist_packages } );
551 {'Simple' => { file => $simple_file,
552 version => '1.23' }});
553 like( $err, qr/Found conflicting versions for package/,
554 ' only one alternative conflicts with corresponding package' );
555 $dist->remove_file( 'lib/Simple2.pm' );
556 $dist->remove_file( 'lib/Simple3.pm' );
559 ############################################################
560 # Don't record private packages (beginning with underscore)
561 # Simple.pm => Simple::_private
562 # Simple.pm => Simple::_private::too
564 $dist->change_file( 'lib/Simple.pm', <<'---' );
567 package Simple::_private;
569 package Simple::_private::too;
572 $dist->regen( clean => 1 );
574 is_deeply($mb->find_dist_packages,
575 {'Simple' => { file => $simple_file,
576 version => '1.23' }});
579 ############################################################
580 # Files with no packages?
582 # Simple.pm => <empty>
584 $dist->change_file( 'lib/Simple.pm', '' );
585 $dist->regen( clean => 1 );
587 is_deeply( $mb->find_dist_packages, {} );
589 # Simple.pm => =pod..=cut (no package declaration)
590 $dist->change_file( 'lib/Simple.pm', <<'---' );
595 Simple - Pure Documentation
603 $dist->regen( clean => 1 );
605 is_deeply($mb->find_dist_packages, {});
607 ############################################################