diff options
author | David Golden <dagolden@cpan.org> | 2009-11-18 00:52:18 -0500 |
---|---|---|
committer | David Golden <dagolden@cpan.org> | 2009-11-18 00:52:18 -0500 |
commit | 613f422f899872b39e45f0f48c3285ac4cece8c7 (patch) | |
tree | 8a11a9316ba0a7dc5dae3d983ee987ac851a1421 /cpan/Module-Build/t | |
parent | 6821e3836b3437b3deb760f4225a6b3dbe4d7015 (diff) | |
download | perl-613f422f899872b39e45f0f48c3285ac4cece8c7.tar.gz |
Updated Module::Build to 0.35_08
0.35_08 - Mon Nov 16 22:38:28 EST 2009
Bug fixes:
- Multiple tests were failing due to dependency problems. Author
dependencies have been largely removed from core 'requires' into
optional features. Feature prereq detection and messaging have been
expanded and bugs on older Perls have been removed.
0.35_07 - Sat Nov 14 17:14:39 EST 2009
Bug fixes:
- Auto-detection of abstract and author fixed for mixed-case POD headers
(RT#51117) [David Wheeler]
- resume() was not restoring additions to @INC added in Build.PL
(RT#50145) [David Golden]
- When tarball paths are less than 100 characters, disables 'prefix'
mode of Archive::Tar for maximum compatibility (RT#50571) [David Golden]
0.35_06 - Fri Nov 13 14:51:28 EST 2009
Enhancements:
- Added experimental inc/ bundling; see Module::Build::Bundling for
details. [David Golden and Eric Wilhelm]
- Clarified that 'apache' in the license attribute indicates the Apache
License 2.0 and added 'apache_1_1' for the older version of the license
(RT#50614) [David Golden]
Bug fixes:
- Merging 'requires' and 'build_requires' in Module::Build::Compat could
lead to duplicate PREREQ_PM entries; now the highest version is used
for PREREQ_PM. (RT#50948) [David Golden]
- Module::Build::Compat will now die with an error if advanced,
non-numeric prerequisites are given, as these are not supported by
ExtUtils::MakeMaker in PREREQ_PM [David Golden]
- Made MYMETA generation non-fatal if fields required for META.yml
are missing [David Golden]
- Added Pod::Simple to requirements for manpage support; avoids
problems if a user has a broken Pod::Man/Pod::Simple. (RT#50081)
[David Golden]
- Won't die if installed Pod::Readme is broken [David Golden]
Other:
- Fixed Module::Build::Notes POD [David Golden]
- Some commands had become silent by default, so added a few short status
messages so users know something actually happened [David Golden]
- Cleaned up Changes file formatting [David Golden]
- Removed most PERL_CORE customizations from test files due to
reorganization of dual-life modules in core (RT#49522) [David Golden]
0.35_05 - Wed Oct 28 17:20:59 EDT 2009
Bug fixes:
- Fix test failure in t/actions/installdeps.t when $^X is not the default
perl [David Golden]
- Work around $VERSION numbers in ActiveState with multiple underscores
that prevent Module::Build from installing on Win32 [David Golden]
- Fix bug cleaning compatibility Makefile when older ExtUtils::Manifest is
installed [David Golden with help from David Cantrell]
Other:
- Suppressed more warnings from tests [David Golden]
- Add provisional support for 'package NAME VERSION' syntax added in
Perl 5.11.1 [David Golden]
0.35_04 - Fri Oct 23 11:20:41 EDT 2009
Bug fixes:
- Fix test failure if IPC::Cmd isn't installed [David Golden]
Other:
- Suppressed warning messages from various tests [David Golden]
0.35_03 - Wed Oct 21 21:20:59 EDT 2009
*** API CHANGE ***
- The prepare_metadata() method used to take a YAML::Node object as an
argument for modification. The method now takes no arguments and just
returns a hash reference of metadata. [David Golden]
Enhancements
- Command line options may be set via the PERL_MB_OPT environment
variable (similar to PERL_MM_OPT in ExtUtils::MakeMaker)
Bug fixes:
- Updated PPM generation to PPM v4 (RT#49600) [Olivier Mengue]
- When c_source is specified, the directory scan will include additional,
less-common C++ extensions (RT49298) [David Golden]
- When module_name is not supplied, no packlist was being written; fixed
by guessing module_name from dist_version_from or the directory name
(just like ExtUtils::Manifest does without NAME) [David Golden]
- Bumped IO::File prereq to fix binmode failures in PPMMaker on Perl
prior to 5.8.8 [David Golden]
Other:
- Replaced use of YAML.pm with YAML::Tiny; Module::Build::YAML is now
based on YAML::Tiny as well [David Golden]
- Reduced amount of console output under normal operation (use --verbose
to see all output) [David Golden]
0.35_02 - Mon Sep 7 22:37:42 EDT 2009
Enhancements:
- Added 'needs_compiler' property. Defaults to true if XS or c_source
exist. If true, ExtUtils::CBuilder is also added to build_requires.
[David Golden]
- File::ShareDir automatically added to 'requires' if 'share_dir' is set
[David Golden]
- Added 'Build installdeps' action to install needed dependencies via
a user-configurable command line program. (Defaults to 'cpan'.)
[Eric Wilhelm]
Bug fixes:
- Failure to detect a compiler will now warn during Build.PL and be a
fatal error when trying to compile during Build. (RT#48918) [David
Golden]
- Fixed directory sorting failure in share_dir.t [David Golden]
- Property defaults that are data structures were being assigned as
references to new objects. Changed so that defaults are cloned instead.
(This mostly affects testing, which often creates multiple objects in the
same process) [David Golden]
- Simplified error message on exit under use_tap_harness [suggested by
David Wheeler]
- Fixed typemap search to use a dist-level typemap if a typemap is not
found in the directory with the *.xs file; (was manifesting as warnings
in Perl 5.6 tests) [David Golden]
Other:
- Replaced guts of new_from_context(). Build.PL is now executed in a
separate process before resume() is called. (This is generally only of
interest to Module::Build or toolchain developers) (RT#49350) [David
Golden, Eric Wilhelm, Ken Williams]
- Revised test helper classes to fix potential bugs and add new features
to make writing tests simpler and easier. Changes incorporated into
t/README.pod and t/sample.t as examples for new testing. [David Golden]
0.35_01 - Mon Aug 31 12:11:10 EDT 2009
Enhancements:
- Generates MYMETA.yml during Build.PL (new standard protocol for
communicating configuration results between toolchain components)
[David Golden]
- Added 'share_dir' property to provide File::ShareDir support;
set automatically if a directory called 'share' exists
[David Golden]
Bug fixes:
- Fix the t/destinations.t fix. [David Golden, with thanks to Eric Wilhelm]
- Fix recursive test files in generated Makefile.PL (RT#49254) [Sawyer X]
- Guard against trying :utf8 when :utf8 isn't available
- The "test" action now dies when using the 'use_tap_harness'
option and tests fail, matching the behavior under Test::Harness.
(RT#49080) [initial patch from David Wheeler; revised by David Golden]
Other:
- Added t/README.pod and t/sample.t to guide developers writing new tests
[David Golden, with some code from Eric Wilhelm]
- Module::Build::Compat 'passthrough' style has been deprecated. Using
'passthrough' will issue warnings on Makefile.PL generation. See
Module::Build::Compat documentation for rationale.
Diffstat (limited to 'cpan/Module-Build/t')
45 files changed, 1450 insertions, 783 deletions
diff --git a/cpan/Module-Build/t/PL_files.t b/cpan/Module-Build/t/PL_files.t index a22171458c..68614c80e4 100644 --- a/cpan/Module-Build/t/PL_files.t +++ b/cpan/Module-Build/t/PL_files.t @@ -4,7 +4,7 @@ use strict; use lib 't/lib'; use MBTest tests => 8; use DistGen; -use Module::Build; +blib_load('Module::Build'); my $dist; diff --git a/cpan/Module-Build/t/README.pod b/cpan/Module-Build/t/README.pod new file mode 100644 index 0000000000..b2d0579d3e --- /dev/null +++ b/cpan/Module-Build/t/README.pod @@ -0,0 +1,94 @@ +=head1 A GUIDE TO WRITING TESTS FOR MODULE::BUILD + +This document provides tips on writing new tests for Module::Build. Please +note that many existing tests were written prior to these guidelines and +have many different styles. Please don't copy/paste old tests by rote without +considering better ways to test. See C<sample.t> for a starter test file. + +=head1 TEST FILE PREAMBLE + +Every Module::Build test should begin with the same preamble to ensure that the +test library is set properly and that the correct version of Module::Build is +being tested. + + use strict; + use lib 't/lib'; + use MBTest tests => 2; # or 'no_plan' + + blib_load('Module::Build'); + +The C<MBTest> module is in C<t/lib/> and subclasses Test::More. When loaded +it cleans up several environment variables that could cause problems, +tweaks C<@INC> and exports several helper functions. See that module for +details. + +=head1 CREATING A TEST DISTRIBUTION + +The C<DistGen> module in C<t/lib/> should be used to create sample +distributions for testing. It provides numerous helpful methods to +create a skeleton distribution, add files, change files, and so on. +Run C<perldoc> on C<t/lib/DistGen.pm> to see the documentation. + + # CREATE A TEST DISTRIBUTION + + use DistGen; + + # create dist object in a temp directory + my $dist = DistGen->new; + + # enter the test distribution directory before further testing + $dist->chdir_in; + + # generate the skeleton files + $dist->regen; + + +=head1 GETTING A MODULE::BUILD OBJECT + +From inside the test distribution, you can get the Module::Build object +configured in Build.PL using the C<new_from_context> method on the +dist object. This is just like Module::Build's C<new_from_context> except +it passes C<< quiet => 1 >> to avoid sending output to the terminal. +Use the Module::Build object to test the programmatic API. + + my $mb = $dist->new_from_context( quiet => 1 ); + isa_ok( $mb, "Module::Build" ); + is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); + +=head1 TESTING THE COMMAND LINE API + +The command line API is tested by running subprocesses, not via a Module::Build +object. The C<DistGen> object has helper methods for running C<Build.PL> and +C<Build> and passing arguments on the command line. + + $dist->run_build_pl( '--quiet' ); + $dist->run_build( 'test' ); + +=head1 TYPICAL TESTING CYCLE + +The typical testing cycle is to generate or modify a test distribution, either +through the C<DistGen> object or directly in the filesystem, then regenerate +the distribution and test it (or run command line tests and observe the +result.) + + # Modify the distribution + + $dist->change_build_pl( + { + module_name => $dist->name, + license => 'artistic', + } + ); + $dist->regen; + + # Get a new build object and test it + + $mb = $dist->new_from_context; + is( $mb->license, "artistic", "saw 'artistic' license" ); + + +=head1 COPYRIGHT + +This documentation is Copyright (C) 2009 by David Golden. You can redistribute +it and/or modify it under the same terms as Perl 5.10.0. + diff --git a/cpan/Module-Build/t/actions/installdeps.t b/cpan/Module-Build/t/actions/installdeps.t new file mode 100644 index 0000000000..95e221d0ad --- /dev/null +++ b/cpan/Module-Build/t/actions/installdeps.t @@ -0,0 +1,48 @@ +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 7; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in; + +$dist->change_build_pl( + module_name => $dist->name, + requires => { + 'File::Spec' => 9999, + }, + build_requires => { + 'Getopt::Long' => 9998, + }, + cpan_client => $^X . ' -le print($_)for($^X,@ARGV)', +)->regen; + +# get a Module::Build object and test with it +my $mb; +stdout_stderr_of( sub { $mb = $dist->new_from_context('verbose' => 1) } ); +isa_ok( $mb, "Module::Build" ); +like( $mb->cpan_client, qr/^\Q$^X\E/, "cpan_client is mocked with perl" ); + +my $out = stdout_of( sub { + $dist->run_build('installdeps') +}); +ok( length($out), "ran mocked Build installdeps"); +my $expected = quotemeta(Module::Build->find_command($^X)); +like( $out, qr/$expected/i, "relative cpan_client resolved relative to \$^X" ); +like( $out, qr/File::Spec/, "saw File::Spec prereq" ); +like( $out, qr/Getopt::Long/, "saw Getopt::Long prereq" ); + +$out = stdout_stderr_of( sub { + $dist->run_build('installdeps', '--cpan_client', 'ADLKASJDFLASDJ') +}); +like( $out, qr/cpan_client .* is not executable/, + "Build installdeps with bad cpan_client dies" +); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/cpan/Module-Build/t/add_property.t b/cpan/Module-Build/t/add_property.t index 6032b0929d..e0b25ae00f 100644 --- a/cpan/Module-Build/t/add_property.t +++ b/cpan/Module-Build/t/add_property.t @@ -2,12 +2,11 @@ use strict; use lib 't/lib'; -use MBTest tests => 29; +use MBTest tests => 27; #use MBTest 'no_plan'; use DistGen; -BEGIN { use_ok 'Module::Build' or die; } -ensure_blib 'Module::Build'; +blib_load 'Module::Build'; my $tmp = MBTest->tmpdir; my $dist = DistGen->new( dir => $tmp ); diff --git a/cpan/Module-Build/t/basic.t b/cpan/Module-Build/t/basic.t index f46be0a4c9..74c50b6178 100644 --- a/cpan/Module-Build/t/basic.t +++ b/cpan/Module-Build/t/basic.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 60; +use MBTest tests => 58; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; @@ -28,7 +27,7 @@ $dist->chdir_in; $mb = Module::Build->new( dist_name => $dist->name, dist_version => 7 ); ok $mb; - ok ! $mb->module_name; # Make sure it's defined + ok $mb->module_name; # Set via heuristics is $mb->dist_name, $dist->name; } @@ -163,10 +162,7 @@ $dist->chdir_in; is $args{foo}, 1; # revert test distribution to pristine state because we modified a file - $dist->remove; - $dist = DistGen->new( dir => $tmp ); - $dist->regen; - $dist->chdir_in; + $dist->regen( clean => 1 ); } # Test author stuff @@ -236,5 +232,3 @@ $dist->chdir_in; is_deeply $mb->include_dirs, ['/foo'], 'Should have single include dir'; } -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/bundle_inc.t b/cpan/Module-Build/t/bundle_inc.t new file mode 100644 index 0000000000..edb1aa94cd --- /dev/null +++ b/cpan/Module-Build/t/bundle_inc.t @@ -0,0 +1,194 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; # or 'no_plan' +use DistGen; +use Config; +use IO::File; +use File::Spec; +use ExtUtils::Packlist; +use File::Path; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +if ( Module::Build::ConfigData->feature('inc_bundling_support') ) { + plan tests => 18; +} else { + plan skip_all => 'inc_bundling_support feature is not enabled'; +} + +# need to do a temp install of M::B being tested to ensure a packlist +# is available for bundling + +my $current_mb = Module::Build->resume(); +my $temp_install = MBTest->tmpdir(); +my $arch = $Config{archname}; +my $lib_path = File::Spec->catdir($temp_install,qw/lib perl5/); +my $arch_path = File::Spec->catdir( $lib_path, $arch ); +mkpath ( $arch_path ); +ok( -d $arch_path, "created temporary M::B pseudo-install directory"); + +unshift @INC, $lib_path, $arch_path; +local $ENV{PERL5LIB} = join( $Config{path_sep}, + $lib_path, $arch_path, ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : () ) +); + +stdout_of( sub { $current_mb->dispatch('install', install_base => $temp_install) } ); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new( inc => 1 )->chdir_in->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); +is_deeply( $mb->bundle_inc, [ 'Module::Build' ], + "Module::Build is flagged for bundling" +); + +# see what gets bundled +stdout_stderr_of( sub { $mb->dispatch('distdir') } ); + +my $dist_inc = File::Spec->catdir($mb->dist_dir, 'inc'); +ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ), + "./inc/latest.pm created" +); + +ok( -d File::Spec->catdir( $dist_inc, 'inc_Module-Build' ), + "dist_dir/inc/inc_Module_Build created" +); + +my $mb_file = + File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build.pm/ ); + +ok( -e $mb_file, + "dist_dir/inc/inc_Module_Build/Module/Build.pm created" +); + +ok( -e File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build Base.pm/ ), + "dist_dir/inc/inc_Module_Build/Module/Build/Base.pm created" +); + +# Force bundled M::B to a higher version so it gets loaded + +my $fh = IO::File->new($mb_file, "+<") or die "Could not open $mb_file: $!"; +my $mb_code = do { local $/; <$fh> }; +$mb_code =~ s{\$VERSION\s+=\s+\S+}{\$VERSION = 9999;}; +$fh->seek(0,0); +print {$fh} $mb_code; +$fh->close; + +# test the bundling in dist_dir +chdir $mb->dist_dir; + +stdout_of( sub { Module::Build->run_perl_script('Build.PL',[],[]) } ); + +my $meta = IO::File->new('MYMETA.yml'); +ok( $meta, "found MYMETA.yml" ); +ok( scalar( grep { /generated_by:.*9999/ } <$meta> ), + "dist_dir Build.PL loaded bundled Module::Build" +); + +#--------------------------------------------------------------------------# +# test identification of dependencies +#--------------------------------------------------------------------------# + +$dist->chdir_in; + +$dist->add_file( 'mylib/Foo.pm', << 'HERE' ); +package Foo; +our $VERSION = 1; +1; +HERE + +$dist->add_file( 'mylib/Bar.pm', << 'HERE' ); +package Bar; +use Foo; +our $VERSION = 42; +1; +HERE + +$dist->change_file( 'Build.PL', << "HERE" ); +use inc::latest 'Module::Build'; +use inc::latest 'Foo'; + +Module::Build->new( + module_name => '$dist->{name}', + license => 'perl', +)->create_build_script; +HERE + +$dist->regen( clean => 1 ); + +make_packlist($_,'mylib') for qw/Foo Bar/; + +# get a Module::Build object and test with it +my $abs_mylib = File::Spec->rel2abs('mylib'); + + +unshift @INC, $abs_mylib; +$mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is_deeply( [sort @{$mb->bundle_inc}], [ 'Foo', 'Module::Build' ], + "Module::Build and Foo are flagged for bundling" +); + +my $output = stdout_stderr_of( sub { $mb->dispatch('distdir') } ); + +ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ), + "./inc/latest.pm created" +); + +ok( -d File::Spec->catdir( $dist_inc, 'inc_Foo' ), + "dist_dir/inc/inc_Foo created" +); + +$dist->change_file( 'Build.PL', << "HERE" ); +use inc::latest 'Module::Build'; +use inc::latest 'Bar'; + +Module::Build->new( + module_name => '$dist->{name}', + license => 'perl', +)->create_build_script; +HERE + +$dist->regen( clean => 1 ); +make_packlist($_,'mylib') for qw/Foo Bar/; + +$mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is_deeply( [sort @{$mb->bundle_inc}], [ 'Bar', 'Module::Build' ], + "Module::Build and Bar are flagged for bundling" +); + +$output = stdout_stderr_of( sub { $mb->dispatch('distdir') } ); + +ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ), + "./inc/latest.pm created" +); + +ok( -d File::Spec->catdir( $dist_inc, 'inc_Bar' ), + "dist_dir/inc/inc_Bar created" +); + + + +sub make_packlist { + my ($mod, $lib) = @_; + my $arch = $Config{archname}; + (my $mod_path = $mod) =~ s{::}{/}g; + my $mod_file = File::Spec->catfile( $lib, "$mod_path\.pm" ); + my $abs = File::Spec->rel2abs($mod_file); + my $packlist_path = File::Spec->catdir($lib, $arch, 'auto', $mod_path); + mkpath $packlist_path; + my $packlist = ExtUtils::Packlist->new; + $packlist->{$abs}++; + $packlist->write( File::Spec->catfile( $packlist_path, '.packlist' )); +} + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/cpan/Module-Build/t/compat.t b/cpan/Module-Build/t/compat.t index 88e5953408..f84b79b744 100644 --- a/cpan/Module-Build/t/compat.t +++ b/cpan/Module-Build/t/compat.t @@ -25,8 +25,8 @@ if ( $Config{make} && $^O ne 'VMS' ? find_in_path($Config{make}) : 1 ) { my $is_vms_mms = ($^O eq 'VMS') && ($Config{make} =~ /MM[SK]/i); -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); +blib_load('Module::Build::Version'); ######################### @@ -43,8 +43,8 @@ $dist->chdir_in; ######################### -use Module::Build; -use Module::Build::Compat; +blib_load('Module::Build'); +blib_load('Module::Build::Compat'); use Carp; $SIG{__WARN__} = \&Carp::cluck; @@ -72,10 +72,11 @@ $dist->change_build_pl({ license => 'perl', requires => { 'perl' => $], - 'File::Spec' => 0, + 'File::Spec' => 0.2, }, - build_requires => { - 'Test::More' => 0, + build_requires => { + 'Test::More' => 0, + 'File::Spec' => 0, }, PL_files => { 'foo.PL' => 'foo' }, }); @@ -90,8 +91,11 @@ $dist->regen; test_makefile_types( requires => { 'perl' => $], - 'File::Spec' => 0, + 'File::Spec' => 0.2, + }, + build_requires => { 'Test::More' => 0, + 'File::Spec' => 0, }, PL_files => { 'foo.PL' => 'foo', @@ -108,7 +112,7 @@ $dist->regen; # Create M::B instance but don't pollute STDOUT my $mb; -stdout_of( sub { +stdout_stderr_of( sub { $mb = Module::Build->new_from_context; }); ok $mb, "Module::Build->new_from_context"; @@ -131,7 +135,7 @@ ok $mb, "Module::Build->new_from_context"; # Makefile.PL - make sure it fails in the right way here. local @Foo::Builder::ISA = qw(Module::Build); my $foo_builder; - stdout_of( sub { + stdout_stderr_of( sub { $foo_builder = Foo::Builder->new_from_context; }); foreach my $style ('passthrough', 'small') { @@ -148,13 +152,13 @@ ok $mb, "Module::Build->new_from_context"; # Now make sure it can actually work. my $bar_builder; - stdout_of( sub { + stdout_stderr_of( sub { $bar_builder = Module::Build->subclass( class => 'Bar::Builder' )->new_from_context; }); foreach my $style ('passthrough', 'small') { create_makefile_pl($style, $bar_builder); my $result; - stdout_of( sub { + stdout_stderr_of( sub { $result = $mb->run_perl_script('Makefile.PL'); }); ok $result, "Makefile.PL ran without error"; @@ -167,7 +171,7 @@ ok $mb, "Module::Build->new_from_context"; my $libdir = File::Spec->catdir( $tmp, 'libdir' ); my $result; - stdout_of( sub { + stdout_stderr_of( sub { $result = $mb->run_perl_script('Makefile.PL', [], [ "LIB=$libdir", @@ -188,7 +192,7 @@ ok $mb, "Module::Build->new_from_context"; # Make sure those switches actually had an effect my ($ran_ok, $output); - $output = stdout_of( sub { $ran_ok = $new_build->do_system(@make, 'test') } ); + $output = stdout_stderr_of( sub { $ran_ok = $new_build->do_system(@make, 'test') } ); ok $ran_ok, "make test ran without error"; $output =~ s/^/# /gm; # Don't confuse our own test output like $output, qr/(?:# ok \d+\s+)+/, 'Should be verbose'; @@ -201,7 +205,7 @@ ok $mb, "Module::Build->new_from_context"; $make_macro = '/macro=("' . $make_macro . '")'; } - $output = stdout_of( sub { + $output = stdout_stderr_of( sub { local $ENV{HARNESS_TIMER}; # RT#39635 - timer messes with output $ran_ok = $mb->do_system(@make, 'test', $make_macro) } ); @@ -258,7 +262,7 @@ ok $mb, "Module::Build->new_from_context"; } } - stdout_of( sub { $mb->do_system(@make, 'realclean'); } ); + stdout_stderr_of( sub { $mb->do_system(@make, 'realclean'); } ); ok ! -e $makefile, "$makefile shouldn't exist"; 1 while unlink 'Makefile.PL'; @@ -274,14 +278,14 @@ ok $mb, "Module::Build->new_from_context"; create_makefile_pl('passthrough', $mb); - stdout_of( sub { + stdout_stderr_of( sub { $mb->run_perl_script('Makefile.PL', [], ['INSTALL_BASE=~/foo']); }); my $b2 = Module::Build->current; ok $b2->install_base, "install_base set"; unlike $b2->install_base, qr/^~/, "Tildes should be expanded"; - stdout_of( sub { $mb->do_system(@make, 'realclean'); } ); + stdout_stderr_of( sub { $mb->do_system(@make, 'realclean'); } ); ok ! -e $makefile, "$makefile shouldn't exist"; 1 while unlink 'Makefile.PL'; @@ -293,34 +297,53 @@ ok $mb, "Module::Build->new_from_context"; $dist->regen; my $mb; - stdout_of( sub { + stdout_stderr_of( sub { $mb = Module::Build->new_from_context( recursive_test_files => 1 ); }); create_makefile_pl('traditional', $mb); my $args = extract_writemakefile_args() || {}; - is $args->{TESTS}, - join( q{ }, - File::Spec->catfile(qw(t *.t)), - File::Spec->catfile(qw(t deep *.t)) - ), - 'Makefile.PL has correct TESTS line for recursive test files'; -} -# cleanup -$dist->remove; + if ( exists $args->{test}->{TESTS} ) { + is $args->{test}->{TESTS}, + join( q{ }, + File::Spec->catfile(qw(t *.t)), + File::Spec->catfile(qw(t deep *.t)) + ), + 'Makefile.PL has correct TESTS line for recursive test files'; + } else { + ok( ! exists $args->{TESTS}, 'Not using incorrect recursive tests key' ); + } + +} ######################################################### +sub _merge_prereqs { + my ($first, $second) = @_; + my $new = { %$first }; + for my $k (keys %$second) { + if ( exists $new->{$k} ) { + my ($v1,$v2) = ($new->{$k},$second->{$k}); + $new->{$k} = ($v1 > $v2 ? $v1 : $v2); + } + else { + $new->{$k} = $second->{$k}; + } + } + return $new; +} + sub test_makefile_types { my %opts = @_; $opts{requires} ||= {}; + $opts{build_requires} ||= {}; $opts{PL_files} ||= {}; foreach my $type (@makefile_types) { # Create M::B instance my $mb; - stdout_of( sub { + stdout_stderr_of( sub { $mb = Module::Build->new_from_context; }); ok $mb, "Module::Build->new_from_context"; @@ -330,12 +353,12 @@ sub test_makefile_types { test_makefile_pl_requires_perl( $opts{requires}{perl} ); test_makefile_creation($mb); - test_makefile_prereq_pm( $opts{requires} ); + test_makefile_prereq_pm( _merge_prereqs($opts{requires}, $opts{build_requires}) ); test_makefile_pl_files( $opts{PL_files} ) if $type eq 'traditional'; my ($output,$success); # Capture output to keep our STDOUT clean - $output = stdout_of( sub { + $output = stdout_stderr_of( sub { $success = $mb->do_system(@make); }); ok $success, "make ran without error"; @@ -345,13 +368,13 @@ sub test_makefile_types { } # Can't let 'test' STDOUT go to our STDOUT, or it'll confuse Test::Harness. - $output = stdout_of( sub { + $output = stdout_stderr_of( sub { $success = $mb->do_system(@make, 'test'); }); ok $success, "make test ran without error"; like uc $output, qr{DONE\.|SUCCESS}, "make test output indicated success"; - $output = stdout_of( sub { + $output = stdout_stderr_of( sub { $success = $mb->do_system(@make, 'realclean'); }); ok $success, "make realclean ran without error"; @@ -372,7 +395,7 @@ sub test_makefile_creation { my ($output, $result); # capture output to avoid polluting our test output - $output = stdout_of( sub { + $output = stdout_stderr_of( sub { $result = $build->run_perl_script('Makefile.PL', $preargs, $postargs); }); my $label = "Makefile.PL ran without error"; @@ -472,7 +495,8 @@ sub extract_writemakefile_args { } sub create_makefile_pl { - Module::Build::Compat->create_makefile_pl(@_); + my @args = @_; + stdout_stderr_of( sub { Module::Build::Compat->create_makefile_pl(@args) } ); my $ok = ok -e 'Makefile.PL', "$_[0] Makefile.PL created"; # Some really conservative make's, like HP/UX, assume files with the same diff --git a/cpan/Module-Build/t/compat/exit.t b/cpan/Module-Build/t/compat/exit.t index 78269a97a3..3672c938c3 100644..100755 --- a/cpan/Module-Build/t/compat/exit.t +++ b/cpan/Module-Build/t/compat/exit.t @@ -3,10 +3,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 5; +use MBTest tests => 3; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); ######################### @@ -24,11 +23,13 @@ $dist->chdir_in; my $mb; stdout_of(sub{ $mb = Module::Build->new_from_context}); -use Module::Build::Compat; +blib_load('Module::Build::Compat'); $dist->regen; -Module::Build::Compat->create_makefile_pl('passthrough', $mb); +stdout_stderr_of( + sub{ Module::Build::Compat->create_makefile_pl('passthrough', $mb); } +); # as silly as all of this exit(0) business is, that is what the cpan # testers have instructed everybody to do so... diff --git a/cpan/Module-Build/t/debug.t b/cpan/Module-Build/t/debug.t index c9b4fa581c..e0b8f60817 100644 --- a/cpan/Module-Build/t/debug.t +++ b/cpan/Module-Build/t/debug.t @@ -2,18 +2,15 @@ use strict; use lib 't/lib'; -use MBTest tests => 3; +use MBTest tests => 1; -require_ok('Module::Build'); -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; use DistGen; my $dist = DistGen->new( dir => $tmp ); $dist->regen; -END{ $dist->remove } - $dist->chdir_in; ######################### @@ -28,6 +25,3 @@ $dist->chdir_in; ); } -######################### - -# cleanup diff --git a/cpan/Module-Build/t/destinations.t b/cpan/Module-Build/t/destinations.t index 4af99d0031..07247a32ba 100644 --- a/cpan/Module-Build/t/destinations.t +++ b/cpan/Module-Build/t/destinations.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 115; +use MBTest tests => 113; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; @@ -248,7 +247,8 @@ $mb->prefix(undef); } # Poke at the innards of MB to change the default install locations. - my $old = $mb->install_sets->{site} = \%test_config; + my $old = $mb->install_sets->{site}; + $mb->install_sets->{site} = \%test_config; $mb->config(siteprefixexp => catdir(File::Spec->rootdir, 'wierd', 'prefix')); @@ -321,5 +321,3 @@ sub test_install_destinations { } } - -$dist->remove; diff --git a/cpan/Module-Build/t/ext.t b/cpan/Module-Build/t/ext.t index 8045761c2a..6101bccd16 100644 --- a/cpan/Module-Build/t/ext.t +++ b/cpan/Module-Build/t/ext.t @@ -4,8 +4,6 @@ use strict; use lib 't/lib'; use MBTest; -use Module::Build; - my @unix_splits = ( { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] }, @@ -58,9 +56,11 @@ my @win_splits = { 'a " b " c' => [ 'a', ' b ', 'c' ] }, ); -plan tests => 10 + 4*@unix_splits + 4*@win_splits; +plan tests => 9 + 4*@unix_splits + 4*@win_splits; -ensure_blib('Module::Build'); +blib_load('Module::Build'); +blib_load('Module::Build::Platform::Unix'); +blib_load('Module::Build::Platform::Windows'); ######################### @@ -74,7 +74,6 @@ foreach my $platform ('', '::Platform::Unix', '::Platform::Windows') { # I think 3.24 isn't actually the majik version, my 3.23 seems to pass... my $low_TPW_version = Text::ParseWords->VERSION < 3.24; -use Module::Build::Platform::Unix; foreach my $test (@unix_splits) { # Text::ParseWords bug: local $TODO = $low_TPW_version && ((keys %$test)[0] =~ m{\\\n}); @@ -82,7 +81,6 @@ foreach my $test (@unix_splits) { do_split_tests('Module::Build::Platform::Unix', $test); } -use Module::Build::Platform::Windows; foreach my $test (@win_splits) { do_split_tests('Module::Build::Platform::Windows', $test); } diff --git a/cpan/Module-Build/t/extend.t b/cpan/Module-Build/t/extend.t index db99eec70b..36ff4b6946 100644 --- a/cpan/Module-Build/t/extend.t +++ b/cpan/Module-Build/t/extend.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 66; +use MBTest tests => 64; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; @@ -79,7 +78,7 @@ print "Hello, World!\n"; $mb->add_build_element('foo'); $mb->add_build_element('foo'); - is_deeply $mb->build_elements, [qw(PL support pm xs pod script foo)], + is_deeply $mb->build_elements, [qw(PL support pm xs share_dir pod script foo)], 'The foo element should be in build_elements only once'; $mb->dispatch('build'); @@ -187,21 +186,20 @@ print "Hello, World!\n"; meta_add => {foo => 'bar'}, conflicts => {'Foo::Barxx' => 0}, ); - my %data; - $mb->prepare_metadata( \%data ); - is $data{foo}, 'bar'; + my $data = $mb->prepare_metadata; + is $data->{foo}, 'bar'; $mb->meta_merge(foo => 'baz'); - $mb->prepare_metadata( \%data ); - is $data{foo}, 'baz'; + $data = $mb->prepare_metadata; + is $data->{foo}, 'baz'; $mb->meta_merge(conflicts => {'Foo::Fooxx' => 0}); - $mb->prepare_metadata( \%data ); - is_deeply $data{conflicts}, {'Foo::Barxx' => 0, 'Foo::Fooxx' => 0}; + $data = $mb->prepare_metadata; + is_deeply $data->{conflicts}, {'Foo::Barxx' => 0, 'Foo::Fooxx' => 0}; $mb->meta_add(conflicts => {'Foo::Bazxx' => 0}); - $mb->prepare_metadata( \%data ); - is_deeply $data{conflicts}, {'Foo::Bazxx' => 0, 'Foo::Fooxx' => 0}; + $data = $mb->prepare_metadata; + is_deeply $data->{conflicts}, {'Foo::Bazxx' => 0, 'Foo::Fooxx' => 0}; } { @@ -275,5 +273,3 @@ print "Hello, World!\n"; } -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/files.t b/cpan/Module-Build/t/files.t index 87b192eaba..cf822fb091 100644 --- a/cpan/Module-Build/t/files.t +++ b/cpan/Module-Build/t/files.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 6; +use MBTest tests => 4; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); use IO::File; my $tmp = MBTest->tmpdir; @@ -46,5 +45,3 @@ my $mb = Module::Build->new_from_context; ok( Module::Build->dir_contains($first, $second) ); } -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/help.t b/cpan/Module-Build/t/help.t index 8408315f07..2bf34c8d50 100644 --- a/cpan/Module-Build/t/help.t +++ b/cpan/Module-Build/t/help.t @@ -2,38 +2,23 @@ use strict; use lib 't/lib'; -use MBTest tests => 25; +use MBTest tests => 23; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); - -use Cwd (); -use File::Path (); - -my $cwd = Cwd::cwd(); -my $tmp = MBTest->tmpdir; +blib_load('Module::Build'); use DistGen; -my $dist = DistGen->new(dir => $tmp); - - +my $dist = DistGen->new; $dist->regen; +$dist->chdir_in; my $restart = sub { - $dist->clean(); - DistGen::chdir_all( $cwd ); - File::Path::rmtree( $tmp ); # we're redefining the same package as we go, so... delete($::{'MyModuleBuilder::'}); delete($INC{'MyModuleBuilder.pm'}); - $dist->regen; - chdir($dist->dirname) or - die "Can't chdir to '@{[$dist->dirname]}': $!"; + $dist->regen( clean => 1 ); }; -chdir($dist->dirname) or die "Can't chdir to '@{[$dist->dirname]}': $!"; - ######################################################################## { # check the =item style my $mb = Module::Build->subclass( @@ -274,7 +259,5 @@ is($mb->get_action_docs('batz'), undef, 'nothing after uplevel'); # cleanup $dist->clean(); -DistGen::chdir_all($cwd); -File::Path::rmtree( $tmp ); # vim:ts=2:sw=2:et:sta diff --git a/cpan/Module-Build/t/install.t b/cpan/Module-Build/t/install.t index 2cadaa39da..66cdd5c94a 100644 --- a/cpan/Module-Build/t/install.t +++ b/cpan/Module-Build/t/install.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 36; +use MBTest tests => 34; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); use Config; use Cwd (); @@ -225,10 +224,7 @@ Simple Man <simple@example.com> is keys %$pms, 0; # revert to pristine state - $dist->remove; - $dist = DistGen->new( dir => $tmp ); - $dist->regen; - $dist->chdir_in; + $dist->regen( clean => 1 ); } sub strip_volume { @@ -243,6 +239,3 @@ sub file_exists { ok -e $file or diag("Expected $file to exist, but it doesn't"); } - -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/install_extra_target.t b/cpan/Module-Build/t/install_extra_target.t index c717ce5eee..21d0c272ae 100644 --- a/cpan/Module-Build/t/install_extra_target.t +++ b/cpan/Module-Build/t/install_extra_target.t @@ -3,10 +3,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 8; +use MBTest tests => 6; -require_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); use File::Spec::Functions qw( catdir ); @@ -46,11 +45,11 @@ sub process_etc_files } #Copy share files to blib -sub process_share_files +sub process_shared_files { my $self = shift; - $self->copy_files("share"); + $self->copy_files("shared"); } 1; @@ -62,23 +61,23 @@ my $build = $subclass->new( ); $build->add_build_element('etc'); -$build->add_build_element('share'); +$build->add_build_element('shared'); my $distdir = lc $build->dist_name(); foreach my $id ('core', 'site', 'vendor') { #Where to install these build types when using prefix symantics - $build->prefix_relpaths($id, 'share' => "share/$distdir"); + $build->prefix_relpaths($id, 'shared' => "shared/$distdir"); $build->prefix_relpaths($id, 'etc' => "etc/$distdir"); #Where to install these build types when using default symantics my $set = $build->install_sets($id); - $set->{'share'} = '/usr/'.($id eq 'site' ? 'local/':'')."share/$distdir"; + $set->{'shared'} = '/usr/'.($id eq 'site' ? 'local/':'')."shared/$distdir"; $set->{'etc'} = ($id eq 'site' ? '/usr/local/etc/':'/etc/').$distdir; } #Where to install these types when using install_base symantics -$build->install_base_relpaths('share' => "share/$distdir"); +$build->install_base_relpaths('shared' => "shared/$distdir"); $build->install_base_relpaths('etc' => "etc/$distdir"); $build->create_build_script(); @@ -97,12 +96,12 @@ stardate = 1234344 ===EOF=== -$dist->add_file("share/data", <<'===EOF==='); +$dist->add_file("shared/data", <<'===EOF==='); 7 * 9 = 42? ===EOF=== -$dist->add_file("share/html/index.html", <<'===EOF==='); +$dist->add_file("shared/html/index.html", <<'===EOF==='); <HTML> <BODY> <H1>Hello World!</H1> @@ -122,16 +121,15 @@ $output .= stdout_of sub { $dist->run_build }; my $error; $error++ unless ok(-e "blib/etc/config", "Built etc/config"); -$error++ unless ok(-e "blib/share/data", "Built share/data"); -$error++ unless ok(-e "blib/share/html/index.html", "Built share/html"); +$error++ unless ok(-e "blib/shared/data", "Built shared/data"); +$error++ unless ok(-e "blib/shared/html/index.html", "Built shared/html"); diag "OUTPUT:\n$output" if $error; $output = stdout_of sub { $dist->run_build('install') }; $error = 0; $error++ unless ok(-e "$installdest/etc/simple/config", "installed etc/config"); -$error++ unless ok(-e "$installdest/share/simple/data", "installed share/data"); -$error++ unless ok(-e "$installdest/share/simple/html/index.html", "installed share/html"); +$error++ unless ok(-e "$installdest/shared/simple/data", "installed shared/data"); +$error++ unless ok(-e "$installdest/shared/simple/html/index.html", "installed shared/html"); diag "OUTPUT:\n$output" if $error; -$dist->remove(); diff --git a/cpan/Module-Build/t/lib/DistGen.pm b/cpan/Module-Build/t/lib/DistGen.pm index 86ee794f3b..d1fb260d60 100644 --- a/cpan/Module-Build/t/lib/DistGen.pm +++ b/cpan/Module-Build/t/lib/DistGen.pm @@ -7,9 +7,9 @@ use vars qw( $VERSION $VERBOSE @EXPORT_OK); $VERSION = '0.01'; $VERBOSE = 0; - use Carp; +use MBTest (); use Cwd (); use File::Basename (); use File::Find (); @@ -38,7 +38,7 @@ BEGIN { $vms_efs_case = VMS::Feature::current("efs_case_preserve"); } else { my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; - $unix_rpt = $env_unix_rpt =~ /^[ET1]/i; + $unix_rpt = $env_unix_rpt =~ /^[ET1]/i; my $efs_case = $ENV{'DECC$EFS_CASE_PRESERVE'} || ''; $vms_efs_case = $efs_case =~ /^[ET1]/i; } @@ -64,44 +64,76 @@ sub undent { } sub chdir_all ($) { - # OS/2 has "current directory per disk", undeletable; + # OS/2 has "current directory per disk", undeletable; # doing chdir() to another disk won't change cur-dir of initial disk... chdir('/') if $^O eq 'os2'; chdir shift; } + ######################################################################## +END { chdir_all(MBTest->original_cwd); } + sub new { - my $package = shift; + my $self = bless {}, shift; + $self->reset(@_); +} + +sub reset { + my $self = shift; my %options = @_; $options{name} ||= 'Simple'; - $options{dir} ||= Cwd::cwd(); + $options{dir} = File::Spec->rel2abs( + defined $options{dir} ? $options{dir} : MBTest->tmpdir + ); my %data = ( no_manifest => 0, xs => 0, + inc => 0, %options, ); - my $self = bless( \%data, $package ); - - # So we can clean up later even if the caller chdir()s - $self->{dir} = File::Spec->rel2abs($self->{dir}); + %$self = %data; tie %{$self->{filedata}}, 'Tie::CPHash'; tie %{$self->{pending}{change}}, 'Tie::CPHash'; + # start with a fresh, empty directory if ( -d $self->dirname ) { warn "Warning: Removing existing directory '@{[$self->dirname]}'\n"; - $self->remove; + File::Path::rmtree( $self->dirname ); } + File::Path::mkpath( $self->dirname ); $self->_gen_default_filedata(); return $self; } +sub remove { + my $self = shift; + $self->chdir_original if($self->did_chdir); + File::Path::rmtree( $self->dirname ); + return $self; +} + +sub revert { + my ($self, $file) = @_; + if ( defined $file ) { + delete $self->{filedata}{$file}; + delete $self->{pending}{$_}{$file} for qw/change remove/; + } + else { + delete $self->{filedata}{$_} for keys %{ $self->{filedata} }; + for my $pend ( qw/change remove/ ) { + delete $self->{pending}{$pend}{$_} for keys %{ $self->{pending}{$pend} }; + } + } + $self->_gen_default_filedata; +} + sub _gen_default_filedata { my $self = shift; @@ -112,17 +144,32 @@ sub _gen_default_filedata { $self->add_file($member, $data) unless($self->{filedata}{$member}); }; - $self->$add_unless('Build.PL', undent(<<" ---")); - use strict; - use Module::Build; + if ( ! $self->{inc} ) { + $self->$add_unless('Build.PL', undent(<<" ---")); + use strict; + use Module::Build; - my \$builder = Module::Build->new( - module_name => '$self->{name}', - license => 'perl', - ); + my \$builder = Module::Build->new( + module_name => '$self->{name}', + license => 'perl', + ); - \$builder->create_build_script(); - --- + \$builder->create_build_script(); + --- + } + else { + $self->$add_unless('Build.PL', undent(<<" ---")); + use strict; + use inc::latest 'Module::Build'; + + my \$builder = Module::Build->new( + module_name => '$self->{name}', + license => 'perl', + ); + + \$builder->create_build_script(); + --- + } my $module_filename = join( '/', ('lib', split(/::/, $self->{name})) ) . '.pm'; @@ -229,7 +276,7 @@ sub _gen_default_filedata { # 5.6 is missing const char * in its typemap $self->$add_unless('typemap', undent(<<" ---")); - const char * T_PV + const char *\tT_PV --- $self->$add_unless('t/basic.t', undent(<<" ---")); @@ -249,7 +296,6 @@ sub _gen_manifest { my $manifest = shift; my $fh = IO::File->new( ">$manifest" ) or do { - $self->remove(); die "Can't write '$manifest'\n"; }; @@ -312,7 +358,6 @@ sub regen { my $dirname = File::Basename::dirname( $fullname ); unless ( -d $dirname ) { File::Path::mkpath( $dirname ) or do { - $self->remove(); die "Can't create '$dirname'\n"; }; } @@ -322,7 +367,6 @@ sub regen { } my $fh = IO::File->new(">$fullname") or do { - $self->remove(); die "Can't write '$fullname'\n"; }; print $fh $self->{filedata}{$file}; @@ -339,6 +383,7 @@ sub regen { } $self->_gen_manifest( $manifest ); } + return $self; } sub clean { @@ -396,20 +441,7 @@ sub clean { }, ($^O eq 'VMS' ? './' : File::Spec->curdir) ); chdir_all( $here ); -} - -sub remove { - my $self = shift; - croak("invalid usage -- remove()") if(@_); - $self->chdir_original if($self->did_chdir); - File::Path::rmtree( $self->dirname ); - # might as well check - croak("\nthis test should have used chdir_in()") unless(Cwd::getcwd); -} - -sub revert { - my $self = shift; - die "Unimplemented.\n"; + return $self; } sub add_file { @@ -425,10 +457,13 @@ sub remove_file { } delete( $self->{filedata}{$file} ); $self->{pending}{remove}{$file} = 1; + return $self; } sub change_build_pl { - my ($self, $opts) = @_; + my ($self, @opts) = @_; + + my $opts = ref $opts[0] eq 'HASH' ? $opts[0] : { @opts }; local $Data::Dumper::Terse = 1; (my $args = Dumper($opts)) =~ s/^\s*\{|\}\s*$//g; @@ -437,16 +472,17 @@ sub change_build_pl { use strict; use Module::Build; my \$b = Module::Build->new( - # Some CPANPLUS::Dist::Build versions need to allow mismatches + # Some CPANPLUS::Dist::Build versions need to allow mismatches # On logic: thanks to Module::Install, CPAN.pm must set both keys, but # CPANPLUS sets only the one - allow_mb_mismatch => ( + allow_mb_mismatch => ( \$ENV{PERL5_CPANPLUS_IS_RUNNING} && ! \$ENV{PERL5_CPAN_IS_RUNNING} ? 1 : 0 ), $args ); \$b->create_build_script(); --- + return $self; } sub change_file { @@ -455,6 +491,7 @@ sub change_file { my $data = shift; $self->{filedata}{$file} = $data; $self->{pending}{change}{$file} = 1; + return $self; } sub get_file { @@ -466,40 +503,43 @@ sub get_file { sub chdir_in { my $self = shift; - - $self->{original_dir} ||= Cwd::cwd; # only once + $self->{original_dir} ||= Cwd::cwd; # only once! my $dir = $self->dirname; chdir($dir) or die "Can't chdir to '$dir': $!"; + return $self; } ######################################################################## -sub did_chdir { - my $self = shift; +sub did_chdir { exists shift()->{original_dir} } - return exists($self->{original_dir}); -} ######################################################################## sub chdir_original { my $self = shift; - croak("never called chdir_in()") unless($self->{original_dir}); - my $dir = $self->{original_dir}; + my $dir = delete $self->{original_dir}; chdir_all($dir) or die "Can't chdir to '$dir': $!"; + return $self; } ######################################################################## +sub new_from_context { + my ($self, @args) = @_; + require Module::Build; + return Module::Build->new_from_context( quiet => 1, @args ); +} + sub run_build_pl { my ($self, @args) = @_; require Module::Build; - Module::Build->run_perl_script('Build.PL', [], [@args]) + return Module::Build->run_perl_script('Build.PL', [], [@args]) } sub run_build { my ($self, @args) = @_; require Module::Build; my $build_script = $^O eq 'VMS' ? 'Build.com' : 'Build'; - Module::Build->run_perl_script($build_script, [], [@args]) + return Module::Build->run_perl_script($build_script, [], [@args]) } 1; @@ -516,8 +556,7 @@ DistGen - Creates simple distributions for testing. use DistGen; # create distribution and prepare to test - my $dist = DistGen->new(name => 'Foo::Bar', dir => $tmp); - $dist->regen; + my $dist = DistGen->new(name => 'Foo::Bar'); $dist->chdir_in; # change distribution files @@ -526,42 +565,48 @@ DistGen - Creates simple distributions for testing. $dist->remove_file('t/some_test.t'); $dist->regen; - # clean up extraneous files + # undo changes and clean up extraneous files + $dist->revert; $dist->clean; # exercise the command-line interface $dist->run_build_pl(); $dist->run_build('test'); - # finish testing and clean up - $dist->chdir_original; - $dist->remove; + # start over as a new distribution + $dist->reset( name => 'Foo::Bar', xs => 1 ); + $dist->chdir_in; =head1 USAGE A DistGen object manages a set of files in a distribution directory. -The constructor and some methods only define the target state of the -distribution. They do B<not> make any changes to the filesystem: +The C<new()> constructor initializes the object and creates an empty +directory for the distribution. It does not create files or chdir into +the directory. The C<reset()> method re-initializes the object in a +new directory with new parameters. It also does not create files or change +the current directory. + +Some methods only define the target state of the distribution. They do B<not> +make any changes to the filesystem: - new add_file change_file change_build_pl remove_file + revert Other methods then change the filesystem to match the target state of -the distribution (or to remove it entirely): +the distribution: - regen clean + regen remove Other methods are provided for a convenience during testing. The -most important are ones that manage the current directory: +most important is the one to enter the distribution directory: chdir_in - chdir_original Additional methods portably encapsulate running Build.PL and Build: @@ -570,16 +615,19 @@ Additional methods portably encapsulate running Build.PL and Build: =head1 API -=head2 Constructor +=head2 Constructors =head3 new() -Create a new object. Does not write its contents (see L</regen()>.) +Create a new object and an empty directory to hold the distribution's files. +If no C<dir> option is provided, it defaults to MBTest->tmpdir, which sets +a different temp directory for Perl core testing and CPAN testing. + +The C<new> method does not write any files -- see L</regen()> below. - my $tmp = MBTest->tmpdir; my $dist = DistGen->new( name => 'Foo::Bar', - dir => $tmp, + dir => MBTest->tmpdir, xs => 1, no_manifest => 0, ); @@ -596,9 +644,14 @@ dist name. =item dir -The (parent) directory in which to create the distribution directory. -The default is File::Spec->curdir. The distribution will be created -under this according to the "dist" form of C<name> (e.g. "Foo-Bar".) +The (parent) directory in which to create the distribution directory. The +distribution will be created under this according to the "dist" form of C<name> +(e.g. "Foo-Bar".) Defaults to a temporary directory. + + $dist = DistGen->new( dir => '/tmp/MB-test' ); + $dist->regen; + + # distribution files have been created in /tmp/MB-test/Simple =item xs @@ -622,6 +675,13 @@ the following files are also added: typemap lib/Simple.xs # based on name parameter +=head3 reset() + +The C<reset> method re-initializes the object as if it were generated +from a fresh call to C<new>. It takes the same optional parameters as C<new>. + + $dist->reset( name => 'Foo::Bar', xs => 0 ); + =head2 Adding and editing files Note that C<$filename> should always be specified with unix-style paths, @@ -669,6 +729,14 @@ Removes C<$filename> from the distribution. $dist->remove_file( $filename ); +=head3 revert() + +Returns the object to its initial state, or given a $filename it returns that +file to its initial state if it is one of the built-in files. + + $dist->revert; + $dist->revert($filename); + =head2 Changing the distribution directory These methods immediately affect the filesystem. @@ -680,8 +748,10 @@ flagged for removal with remove_file(). $dist->regen(clean => 1); -If the optional C<clean> argument is given, it also removes any -extraneous files that do not belong to the distribution. +If the optional C<clean> argument is given, it also calls C<clean>. These +can also be chained like this, instead: + + $dist->clean->regen; =head3 clean() @@ -689,22 +759,19 @@ Removes any files that are not part of the distribution. $dist->clean; -=begin TODO - -=head3 revert() - -[Unimplemented] Returns the object to its initial state, or given a -$filename it returns that file to it's initial state if it is one of -the built-in files. +=head3 remove() - $dist->revert; - $dist->revert($filename); +Changes back to the original directory and removes the distribution +directory (but not the temporary directory set during C<new()>). -=end TODO + $dist = DistGen->new->chdir->regen; + # ... do some testing ... -=head3 remove() + $dist->remove->chdir_in->regen; + # ... do more testing ... -Removes the entire distribution directory. +This is like a more aggressive form of C<clean>. Generally, calling C<clean> +and C<regen> should be sufficient. =head2 Changing directories diff --git a/cpan/Module-Build/t/lib/MBTest.pm b/cpan/Module-Build/t/lib/MBTest.pm index dc2410b399..8a5acd257a 100644 --- a/cpan/Module-Build/t/lib/MBTest.pm +++ b/cpan/Module-Build/t/lib/MBTest.pm @@ -13,6 +13,7 @@ BEGIN { my @delete_env_keys = qw( DEVEL_COVER_OPTIONS MODULEBUILDRC + PERL_MB_OPT HARNESS_TIMER HARNESS_OPTIONS HARNESS_VERBOSE @@ -49,7 +50,15 @@ BEGIN { # In case the test wants to use our other bundled # modules, make sure they can be loaded. - push @INC, File::Spec->catdir('t', 'bundled'); + my $t_lib = File::Spec->catdir('t', 'bundled'); + push @INC, $t_lib; # Let user's installed version override + + if ($ENV{PERL_CORE}) { + # We change directories, so expand @INC and $^X to absolute paths + # Also add . + @INC = (map(File::Spec->rel2abs($_), @INC), "."); + $^X = File::Spec->rel2abs($^X); + } } use Exporter; @@ -74,7 +83,7 @@ my @extra_exports = qw( find_in_path check_compiler have_module - ensure_blib + blib_load ); push @EXPORT, @extra_exports; __PACKAGE__->export(scalar caller, @extra_exports); @@ -85,7 +94,9 @@ __PACKAGE__->export(scalar caller, @extra_exports); # always return to the current directory { - my $cwd = Cwd::cwd; + my $cwd = File::Spec->rel2abs(Cwd::cwd); + + sub original_cwd { return $cwd } END { # Go back to where you came from! @@ -103,13 +114,11 @@ __PACKAGE__->export(scalar caller, @extra_exports); } ######################################################################## -# Setup a temp directory -sub tmpdir { - my ($self, $usr_tmp) = @_; - return File::Temp::tempdir( 'MB-XXXXXXXX', - CLEANUP => 1, DIR => $ENV{PERL_CORE} ? Cwd::cwd : - $usr_tmp ? $usr_tmp : File::Spec->tmpdir - ); +# Setup a temp directory +sub tmpdir { + my ($self, @args) = @_; + my $dir = $ENV{PERL_CORE} ? MBTest->original_cwd : File::Spec->tmpdir; + return File::Temp::tempdir('MB-XXXXXXXX', CLEANUP => 1, DIR => $dir, @args); } sub save_handle { @@ -137,7 +146,7 @@ sub stdout_stderr_of { $stdout = stdout_of ( sub { $stderr = stderr_of( $subr ) }); - return ($stdout, $stderr); + return wantarray ? ($stdout, $stderr) : $stdout . $stderr; } sub slurp { @@ -160,13 +169,20 @@ sub exe_exts { sub find_in_path { my $thing = shift; - - my @path = split $Config{path_sep}, $ENV{PATH}; + my @exe_ext = exe_exts(); - foreach (@path) { - my $fullpath = File::Spec->catfile($_, $thing); + if ( File::Spec->file_name_is_absolute( $thing ) ) { foreach my $ext ( '', @exe_ext ) { - return "$fullpath$ext" if -e "$fullpath$ext"; + return "$thing$ext" if -e "$thing$ext"; + } + } + else { + my @path = split $Config{path_sep}, $ENV{PATH}; + foreach (@path) { + my $fullpath = File::Spec->catfile($_, $thing); + foreach my $ext ( '', @exe_ext ) { + return "$fullpath$ext" if -e "$fullpath$ext"; + } } } return; @@ -178,6 +194,7 @@ sub check_compiler { local $SIG{__WARN__} = sub {}; + blib_load('Module::Build'); my $mb = Module::Build->current; $mb->verbose( 0 ); @@ -202,21 +219,23 @@ sub check_compiler { sub have_module { my $module = shift; - return eval "use $module; 1"; + return eval "require $module; 1"; } -sub ensure_blib { - # Make sure the given module was loaded from blib/, not the larger system +sub blib_load { + # Load the given module and ensure it came from blib/, not the larger system my $mod = shift; + have_module($mod) or die "Error loading $mod\: $@\n"; + (my $path = $mod) =~ s{::}{/}g; - - local $Test::Builder::Level = $Test::Builder::Level + 1; - SKIP: { - skip "no blib in core", 1 if $ENV{PERL_CORE}; - like $INC{"$path.pm"}, qr/\bblib\b/, "Make sure $mod was loaded from blib/" - or diag "PERL5LIB: " . ($ENV{PERL5LIB} || '') . "\n" . - "PERL5OPT: " . ($ENV{PERL5OPT} || '') . "\n" . - "\@INC contains:\n " . join("\n ", @INC) . "\n"; + $path .= ".pm"; + my ($pkg, $file, $line) = caller; + unless($ENV{PERL_CORE}) { + unless($INC{$path} =~ m/\bblib\b/) { + (my $load_from = $INC{$path}) =~ s{$path$}{}; + die "$mod loaded from '$load_from'\nIt should have been loaded from blib. \@INC contains:\n ", + join("\n ", @INC) . "\nFatal error occured in blib_load() at $file, line $line.\n"; + } } } diff --git a/cpan/Module-Build/t/manifypods.t b/cpan/Module-Build/t/manifypods.t index 31c9e8ea83..5947646d13 100644 --- a/cpan/Module-Build/t/manifypods.t +++ b/cpan/Module-Build/t/manifypods.t @@ -3,15 +3,14 @@ use strict; use lib 't/lib'; use MBTest; -use Module::Build; -use Module::Build::ConfigData; +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); if ( Module::Build::ConfigData->feature('manpage_support') ) { - plan tests => 22; + plan tests => 21; } else { plan skip_all => 'manpage_support feature is not enabled'; } -ensure_blib('Module::Build'); ######################### @@ -139,11 +138,7 @@ $mb->dispatch('realclean'); # revert to a pristine state -$dist->remove; -$dist = DistGen->new( dir => $tmp ); -$dist->regen; -$dist->chdir_in; - +$dist->regen( clean => 1 ); my $mb2 = Module::Build->new( module_name => $dist->name, @@ -163,6 +158,3 @@ foreach ('testcover', 'disttest') { unlike $docs, qr/\n=/, $docs; } - -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/mbyaml.t b/cpan/Module-Build/t/mbyaml.t deleted file mode 100644 index d2cb0d547f..0000000000 --- a/cpan/Module-Build/t/mbyaml.t +++ /dev/null @@ -1,262 +0,0 @@ -#!/usr/local/bin/perl -w - -use strict; -use lib 't/lib'; -use MBTest 'no_plan'; - -use_ok 'Module::Build::YAML'; -ensure_blib('Module::Build::YAML'); - -my ($dir); -$dir = "."; -$dir = "t" if (-d "t"); - -{ - my ($expected, $got, $var); - ########################################################## - # Test a typical-looking Module::Build structure (alphabetized) - ########################################################## - $var = { - 'resources' => { - 'license' => 'http://opensource.org/licenses/artistic-license.php' - }, - 'meta-spec' => { - 'version' => '1.2', - 'url' => 'http://module-build.sourceforge.net/META-spec-v1.2.html' - }, - 'generated_by' => 'Module::Build version 0.2709', - 'version' => '0.13', - 'name' => 'js-app', - 'dynamic_config' => '1', - 'author' => [ - '"Stephen Adkins" <spadkins@gmail.com>' - ], - 'license' => 'lgpl', - 'build_requires' => { - 'App::Build' => '0', - 'File::Spec' => '0', - 'Module::Build' => '0' - }, - 'provides' => { - 'JavaScript::App' => { - 'version' => '0', - 'file' => 'lib/JavaScript/App.pm' - } - }, - 'requires' => { - 'App::Options' => '0' - }, - 'abstract' => 'A framework for building dynamic widgets or full applications in Javascript' - }; - $expected = <<'EOF'; ---- -abstract: A framework for building dynamic widgets or full applications in Javascript -author: - - '"Stephen Adkins" <spadkins@gmail.com>' -build_requires: - App::Build: 0 - File::Spec: 0 - Module::Build: 0 -dynamic_config: 1 -generated_by: Module::Build version 0.2709 -license: lgpl -meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.2.html - version: 1.2 -name: js-app -provides: - JavaScript::App: - file: lib/JavaScript/App.pm - version: 0 -requires: - App::Options: 0 -resources: - license: http://opensource.org/licenses/artistic-license.php -version: 0.13 -EOF - $got = &Module::Build::YAML::Dump($var); - is($got, $expected, "Dump(): single deep hash"); - - ########################################################## - # Test a typical-looking Module::Build structure (ordered) - ########################################################## - $expected = <<'EOF'; ---- -name: js-app -version: 0.13 -author: - - '"Stephen Adkins" <spadkins@gmail.com>' -abstract: A framework for building dynamic widgets or full applications in Javascript -license: lgpl -resources: - license: http://opensource.org/licenses/artistic-license.php -requires: - App::Options: 0 -build_requires: - App::Build: 0 - File::Spec: 0 - Module::Build: 0 -dynamic_config: 1 -provides: - JavaScript::App: - file: lib/JavaScript/App.pm - version: 0 -generated_by: Module::Build version 0.2709 -meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.2.html - version: 1.2 -EOF - $var->{_order} = [qw(name version author abstract license resources requires build_requires dynamic_config provides)]; - $got = &Module::Build::YAML::Dump($var); - is($got, $expected, "Dump(): single deep hash, ordered"); - - ########################################################## - # Test that an array turns into multiple documents - ########################################################## - $var = [ - "e", - 2.71828, - [ "pi", "is", 3.1416 ], - { fun => "under_sun", 6 => undef, "more", undef }, - ]; - $expected = <<'EOF'; ---- -e ---- -2.71828 ---- -- pi -- is -- 3.1416 ---- -6: ~ -fun: under_sun -more: ~ -EOF - $got = &Module::Build::YAML::Dump(@$var); - is($got, $expected, "Dump(): multiple, various"); - - ########################################################## - # Test that a single array ref turns into one document - ########################################################## - $expected = <<'EOF'; ---- -- e -- 2.71828 -- - - pi - - is - - 3.1416 -- - 6: ~ - fun: under_sun - more: ~ -EOF - $got = &Module::Build::YAML::Dump($var); - is($got, $expected, "Dump(): single array of various"); - - ########################################################## - # Test Object-Oriented Flavor of the API - ########################################################## - my $y = Module::Build::YAML->new(); - $got = $y->Dump($var); - is($got, $expected, "Dump(): single array of various (OO)"); - - ########################################################## - # Test Quoting Conditions (newlines, quotes, tildas, undefs) - ########################################################## - $var = { - 'foo01' => '`~!@#$%^&*()_+-={}|[]\\;\':",./?<> -<nl>', - 'foo02' => '~!@#$%^&*()_+-={}|[]\\;:,./<>?', - 'foo03' => undef, - 'foo04' => '~', - }; - $expected = <<'EOF'; ---- -foo01: "`~!@#$%^&*()_+-={}|[]\;':\",./?<>\n<nl>" -foo02: "~!@#$%^&*()_+-={}|[]\;:,./<>?" -foo03: ~ -foo04: "~" -EOF - $got = &Module::Build::YAML::Dump($var); - is($got, $expected, "Dump(): tricky embedded characters"); - - $var = { - 'foo10' => undef, - 'foo40' => '!', - 'foo41' => '@', - 'foo42' => '#', - 'foo43' => '$', - 'foo44' => '%', - 'foo45' => '^', - 'foo47' => '&', - 'foo48' => '*', - 'foo49' => '(', - 'foo50' => ')', - 'foo51' => '_', - 'foo52' => '+', - 'foo53' => '-', - 'foo54' => '=', - 'foo55' => '{', - 'foo56' => '}', - 'foo57' => '|', - 'foo58' => '[', - 'foo59' => ']', - 'foo60' => '\\', - 'foo61' => ';', - 'foo62' => ':', - 'foo63' => ',', - 'foo64' => '.', - 'foo65' => '/', - 'foo66' => '<', - 'foo67' => '>', - 'foo68' => '?', - 'foo69' => '\'', - 'foo70' => '"', - 'foo71' => '`', - 'foo72' => ' -', - }; - $expected = <<'EOF'; ---- -foo10: ~ -foo40: "!" -foo41: '@' -foo42: "#" -foo43: $ -foo44: % -foo45: "^" -foo47: "&" -foo48: "*" -foo49: "(" -foo50: ")" -foo51: _ -foo52: + -foo53: - -foo54: = -foo55: "{" -foo56: "}" -foo57: "|" -foo58: "[" -foo59: "]" -foo60: \ -foo61: ; -foo62: : -foo63: , -foo64: . -foo65: / -foo66: '<' -foo67: '>' -foo68: "?" -foo69: "'" -foo70: '"' -foo71: "`" -foo72: "\n" -EOF - $got = &Module::Build::YAML::Dump($var); - is($got, $expected, "Dump(): tricky embedded characters (singles)"); - -} - - diff --git a/cpan/Module-Build/t/metadata.t b/cpan/Module-Build/t/metadata.t index 6f53c1d225..2850bea24c 100644 --- a/cpan/Module-Build/t/metadata.t +++ b/cpan/Module-Build/t/metadata.t @@ -2,15 +2,13 @@ use strict; use lib 't/lib'; -use MBTest tests => 53; +use MBTest tests => 51; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); my $tmp = MBTest->tmpdir; -use Module::Build::ConfigData; - my %metadata = ( module_name => 'Simple', @@ -56,7 +54,6 @@ my $simple2_file = 'lib/Simple2.pm'; $dist->chdir_in; -use Module::Build; my $mb = Module::Build->new_from_context; ################################################## @@ -68,7 +65,7 @@ my $mb = Module::Build->new_from_context; my $mb_config_req = { 'Module::Build' => int($Module::Build::VERSION * 100)/100 }; - my $node = $mb->prepare_metadata( {} ); + my $node = $mb->prepare_metadata( ); # exists() doesn't seem to work here is $node->{name}, $metadata{module_name}; @@ -89,7 +86,7 @@ my $mb = Module::Build->new_from_context; { my $mb_prereq = { 'Module::Build' => 0 }; $mb->configure_requires( $mb_prereq ); - my $node = $mb->prepare_metadata( {} ); + my $node = $mb->prepare_metadata( ); # exists() doesn't seem to work here @@ -366,7 +363,7 @@ package Simple; $VERSION = '2.34'; --- $dist->regen( clean => 1 ); -$mb = new_build(); +stderr_of( sub { $mb = new_build(); } ); $err = stderr_of( sub { $provides = $mb->find_dist_packages } ); is_deeply($provides, {'Simple' => { file => $simple_file, @@ -470,7 +467,7 @@ package Foo; $VERSION = '2.34'; --- $dist->regen( clean => 1 ); -$mb = new_build(); +stderr_of( sub { $mb = new_build(); } ); $err = stderr_of( sub { $provides = $mb->find_dist_packages } ); # XXX Should 'Foo' exist ??? Can't predict values for file & version ok( exists( $provides->{Foo} ) ); @@ -604,6 +601,3 @@ $dist->regen( clean => 1 ); $mb = new_build(); is_deeply($mb->find_dist_packages, {}); -############################################################ -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/metadata2.t b/cpan/Module-Build/t/metadata2.t index a5af034dc0..954b6589a0 100644 --- a/cpan/Module-Build/t/metadata2.t +++ b/cpan/Module-Build/t/metadata2.t @@ -2,14 +2,11 @@ use strict; use lib 't/lib'; -use MBTest tests => 20; +use MBTest tests => 18; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); -my $tmp = MBTest->tmpdir; - -use Module::Build::ConfigData; use DistGen; @@ -19,14 +16,12 @@ SKIP: { skip( 'YAML_support feature is not enabled', 4 ) unless Module::Build::ConfigData->feature('YAML_support'); - my $dist = DistGen->new( dir => $tmp, no_manifest => 1 ); - $dist->regen; - - $dist->chdir_in; + my $dist = DistGen->new( no_manifest => 1 )->chdir_in->regen; ok ! -e 'MANIFEST'; - my $mb = Module::Build->new_from_context; + my $mb; + stderr_of( sub { $mb = Module::Build->new_from_context } ); my $out; $out = eval { stderr_of(sub{$mb->dispatch('distmeta')}) }; @@ -36,7 +31,6 @@ SKIP: { ok -e 'META.yml'; - $dist->remove; } @@ -62,7 +56,7 @@ Simple Simon <simon@simple.sim> =cut --- -my $dist = DistGen->new( dir => $tmp ); +my $dist = DistGen->new->chdir_in; $dist->change_build_pl ({ @@ -71,10 +65,6 @@ $dist->change_build_pl license => 'perl', create_readme => 1, }); -$dist->regen; - -$dist->chdir_in; - # .pm File with pod # @@ -139,7 +129,3 @@ is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>', is( $mb->dist_abstract, "A simple module", "Extracting abstract from .pod over .pm"); - -############################################################ -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/moduleinfo.t b/cpan/Module-Build/t/moduleinfo.t index ca7eb048e5..e28726d493 100644 --- a/cpan/Module-Build/t/moduleinfo.t +++ b/cpan/Module-Build/t/moduleinfo.t @@ -4,99 +4,58 @@ use strict; use lib 't/lib'; -use MBTest tests => 82; - -use_ok 'Module::Build::ModuleInfo'; -ensure_blib('Module::Build::ModuleInfo'); - -my $tmp = MBTest->tmpdir; - -use DistGen; -my $dist = DistGen->new( dir => $tmp ); -$dist->regen; - -$dist->chdir_in; - -######################### - -# class method C<find_module_by_name> -my $module = Module::Build::ModuleInfo->find_module_by_name( - 'Module::Build::ModuleInfo' ); -ok( -e $module, 'find_module_by_name() succeeds' ); - - -# fail on invalid module name -my $pm_info = Module::Build::ModuleInfo->new_from_module( - 'Foo::Bar', inc => [] ); -ok( !defined( $pm_info ), 'fail if can\'t find module by module name' ); - - -# fail on invalid filename -my $file = File::Spec->catfile( 'Foo', 'Bar.pm' ); -$pm_info = Module::Build::ModuleInfo->new_from_file( $file, inc => [] ); -ok( !defined( $pm_info ), 'fail if can\'t find module by file name' ); - - -# construct from module filename -$file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm'; -$pm_info = Module::Build::ModuleInfo->new_from_file( $file ); -ok( defined( $pm_info ), 'new_from_file() succeeds' ); - -# construct from module name, using custom include path -$pm_info = Module::Build::ModuleInfo->new_from_module( - $dist->name, inc => [ 'lib', @INC ] ); -ok( defined( $pm_info ), 'new_from_module() succeeds' ); - +use MBTest; # parse various module $VERSION lines +# these will be reversed later to create %modules my @modules = ( - <<'---', # declared & defined on same line with 'our' + '1.23' => <<'---', # declared & defined on same line with 'our' package Simple; our $VERSION = '1.23'; --- - <<'---', # declared & defined on separate lines with 'our' + '1.23' => <<'---', # declared & defined on separate lines with 'our' package Simple; our $VERSION; $VERSION = '1.23'; --- - <<'---', # use vars + '1.23' => <<'---', # use vars package Simple; use vars qw( $VERSION ); $VERSION = '1.23'; --- - <<'---', # choose the right default package based on package/file name + '1.23' => <<'---', # choose the right default package based on package/file name package Simple::_private; $VERSION = '0'; package Simple; $VERSION = '1.23'; # this should be chosen for version --- - <<'---', # just read the first $VERSION line + '1.23' => <<'---', # just read the first $VERSION line package Simple; $VERSION = '1.23'; # we should see this line $VERSION = eval $VERSION; # and ignore this one --- - <<'---', # just read the first $VERSION line in reopened package (1) + '1.23' => <<'---', # just read the first $VERSION line in reopened package (1) package Simple; $VERSION = '1.23'; package Error::Simple; $VERSION = '2.34'; package Simple; --- - <<'---', # just read the first $VERSION line in reopened package (2) + '1.23' => <<'---', # just read the first $VERSION line in reopened package (2) package Simple; package Error::Simple; $VERSION = '2.34'; package Simple; $VERSION = '1.23'; --- - <<'---', # mentions another module's $VERSION + '1.23' => <<'---', # mentions another module's $VERSION package Simple; $VERSION = '1.23'; if ( $Other::VERSION ) { # whatever } --- - <<'---', # mentions another module's $VERSION in a different package + '1.23' => <<'---', # mentions another module's $VERSION in a different package package Simple; $VERSION = '1.23'; package Simple2; @@ -104,21 +63,21 @@ if ( $Simple::VERSION ) { # whatever } --- - <<'---', # $VERSION checked only in assignments, not regexp ops + '1.23' => <<'---', # $VERSION checked only in assignments, not regexp ops package Simple; $VERSION = '1.23'; if ( $VERSION =~ /1\.23/ ) { # whatever } --- - <<'---', # $VERSION checked only in assignments, not relational ops + '1.23' => <<'---', # $VERSION checked only in assignments, not relational ops package Simple; $VERSION = '1.23'; if ( $VERSION == 3.45 ) { # whatever } --- - <<'---', # $VERSION checked only in assignments, not relational ops + '1.23' => <<'---', # $VERSION checked only in assignments, not relational ops package Simple; $VERSION = '1.23'; package Simple2; @@ -126,36 +85,36 @@ if ( $Simple::VERSION == 3.45 ) { # whatever } --- - <<'---', # Fully qualified $VERSION declared in package + '1.23' => <<'---', # Fully qualified $VERSION declared in package package Simple; $Simple::VERSION = 1.23; --- - <<'---', # Differentiate fully qualified $VERSION in a package + '1.23' => <<'---', # Differentiate fully qualified $VERSION in a package package Simple; $Simple2::VERSION = '999'; $Simple::VERSION = 1.23; --- - <<'---', # Differentiate fully qualified $VERSION and unqualified + '1.23' => <<'---', # Differentiate fully qualified $VERSION and unqualified package Simple; $Simple2::VERSION = '999'; $VERSION = 1.23; --- - <<'---', # $VERSION declared as package variable from within 'main' package + '1.23' => <<'---', # $VERSION declared as package variable from within 'main' package $Simple::VERSION = '1.23'; { package Simple; $x = $y, $cats = $dogs; } --- - <<'---', # $VERSION wrapped in parens - space inside + '1.23' => <<'---', # $VERSION wrapped in parens - space inside package Simple; ( $VERSION ) = '1.23'; --- - <<'---', # $VERSION wrapped in parens - no space inside + '1.23' => <<'---', # $VERSION wrapped in parens - no space inside package Simple; ($VERSION) = '1.23'; --- - <<'---', # $VERSION follows a spurious 'package' in a quoted construct + '1.23' => <<'---', # $VERSION follows a spurious 'package' in a quoted construct package Simple; __PACKAGE__->mk_accessors(qw( program socket proc @@ -163,25 +122,87 @@ __PACKAGE__->mk_accessors(qw( our $VERSION = "1.23"; --- - <<'---', # $VERSION using version.pm + '1.23' => <<'---', # $VERSION using version.pm package Simple; use version; our $VERSION = version->new('1.23'); --- - <<'---', # $VERSION using version.pm and qv() + '1.23' => <<'---', # $VERSION using version.pm and qv() package Simple; use version; our $VERSION = qv('1.230'); --- - <<'---', # Two version assignments, should ignore second one + '1.23' => <<'---', # Two version assignments, should ignore second one $Simple::VERSION = '1.230'; $Simple::VERSION = eval $Simple::VERSION; --- + '1.23' => <<'---', # declared & defined on same line with 'our' +package Simple; +our $VERSION = '1.23_00_00'; +--- + '1.23' => <<'---', # package NAME VERSION + package Simple 1.23; +--- + '1.23_01' => <<'---', # package NAME VERSION + package Simple 1.23_01; +--- + 'v1.2.3' => <<'---', # package NAME VERSION + package Simple v1.2.3; +--- + 'v1.2_3' => <<'---', # package NAME VERSION + package Simple v1.2_3; +--- ); +my %modules = reverse @modules; + +plan tests => 36 + 2 * keys( %modules ); -my( $i, $n ) = ( 1, scalar( @modules ) ); -foreach my $module ( @modules ) { +blib_load('Module::Build::ModuleInfo'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + +######################### + +# class method C<find_module_by_name> +my $module = Module::Build::ModuleInfo->find_module_by_name( + 'Module::Build::ModuleInfo' ); +ok( -e $module, 'find_module_by_name() succeeds' ); + + +# fail on invalid module name +my $pm_info = Module::Build::ModuleInfo->new_from_module( + 'Foo::Bar', inc => [] ); +ok( !defined( $pm_info ), 'fail if can\'t find module by module name' ); + + +# fail on invalid filename +my $file = File::Spec->catfile( 'Foo', 'Bar.pm' ); +$pm_info = Module::Build::ModuleInfo->new_from_file( $file, inc => [] ); +ok( !defined( $pm_info ), 'fail if can\'t find module by file name' ); + + +# construct from module filename +$file = File::Spec->catfile( 'lib', split( /::/, $dist->name ) ) . '.pm'; +$pm_info = Module::Build::ModuleInfo->new_from_file( $file ); +ok( defined( $pm_info ), 'new_from_file() succeeds' ); + +# construct from module name, using custom include path +$pm_info = Module::Build::ModuleInfo->new_from_module( + $dist->name, inc => [ 'lib', @INC ] ); +ok( defined( $pm_info ), 'new_from_module() succeeds' ); + + +foreach my $module ( sort keys %modules ) { + my $expected = $modules{$module}; SKIP: { skip( "No our() support until perl 5.6", 2 ) - if $] < 5.006 && $module =~ /\bour\b/; + if $] < 5.006 && $module =~ /\bour\b/; + skip( "No package NAME VERSION support until perl 5.11.1", 2 ) + if $] < 5.011001 && $module =~ /package\s+[\w\:\']+\s+v?[0-9._]+/; $dist->change_file( 'lib/Simple.pm', $module ); $dist->regen; @@ -191,19 +212,17 @@ foreach my $module ( @modules ) { my $pm_info = Module::Build::ModuleInfo->new_from_file( $file ); # Test::Builder will prematurely numify objects, so use this form - ok( $pm_info->version eq '1.23', - "correct module version ($i of $n)" ); - is( $warnings, '', 'no warnings from parsing' ); - $i++; + my $errs; + ok( $pm_info->version eq $expected, + "correct module version (expected '$expected')" ) + or $errs++; + is( $warnings, '', 'no warnings from parsing' ) or $errs++; + diag "Got: '@{[$pm_info->version]}'\nModule contents:\n$module" if $errs; } } # revert to pristine state -$dist->remove; -$dist = DistGen->new( dir => $tmp ); -$dist->regen; -$dist->chdir_in; - +$dist->regen( clean => 1 ); # Find each package only once $dist->change_file( 'lib/Simple.pm', <<'---' ); @@ -249,19 +268,15 @@ $pm_info = Module::Build::ModuleInfo->new_from_file( $file ); is( $pm_info->version, '1.23_01', 'alpha version reported'); # NOTE the following test has be done this way because Test::Builder is -# too smart for our own good and tries to see if the version object is a +# too smart for our own good and tries to see if the version object is a # dual-var, which breaks with alpha versions: # Argument "1.23_0100" isn't numeric in addition (+) at -# /usr/lib/perl5/5.8.7/Test/Builder.pm line 505. +# /usr/lib/perl5/5.8.7/Test/Builder.pm line 505. ok( $pm_info->version > 1.23, 'alpha version greater than non'); # revert to pristine state -$dist->remove; -$dist = DistGen->new( dir => $tmp ); -$dist->regen; -$dist->chdir_in; - +$dist->regen( clean => 1 ); # parse $VERSION lines scripts for package main my @scripts = ( @@ -313,7 +328,7 @@ $::VERSION = 0.01; --- ); -( $i, $n ) = ( 1, scalar( @scripts ) ); +my ( $i, $n ) = ( 1, scalar( @scripts ) ); foreach my $script ( @scripts ) { $dist->change_file( 'bin/simple.plx', $script ); $dist->regen; @@ -402,7 +417,7 @@ __DATA__ is( $pm_info->name, 'Simple', 'found default package' ); is( $pm_info->version, '0.01', 'version for default package' ); my @packages = $pm_info->packages_inside; - is_deeply(\@packages, ['Simple']); + is_deeply(\@packages, ['Simple'], 'packages inside'); } { @@ -419,10 +434,7 @@ $VERSION = version->new('0.61.' . (qw$Revision: 129 $)[1]); is( $pm_info->name, 'Simple', 'found default package' ); is( $pm_info->version, '0.60.128', 'version for default package' ); my @packages = $pm_info->packages_inside; - is_deeply([sort @packages], ['Simple', 'Simple::Simon']); + is_deeply([sort @packages], ['Simple', 'Simple::Simon'], 'packages inside'); is( $pm_info->version('Simple::Simon'), '0.61.129', 'version for embedded package' ); } - -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/mymeta.t b/cpan/Module-Build/t/mymeta.t new file mode 100644 index 0000000000..c60a5b2420 --- /dev/null +++ b/cpan/Module-Build/t/mymeta.t @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 3; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; +$dist->chdir_in; + +######################### + +# Test MYMETA generation +{ + ok( ! -e "MYMETA.yml", "MYMETA.yml doesn't exist before Build.PL runs" ); + my $output; + $output = stdout_of sub { $dist->run_build_pl }; + like($output, qr/Creating new 'MYMETA.yml' with configuration results/, + "Saw MYMETA.yml creation message" + ); + ok( -e "MYMETA.yml", "MYMETA.yml exists" ); +} + +######################### + diff --git a/cpan/Module-Build/t/new_from_context.t b/cpan/Module-Build/t/new_from_context.t index ee34f07367..f45a1760eb 100644 --- a/cpan/Module-Build/t/new_from_context.t +++ b/cpan/Module-Build/t/new_from_context.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 4; +use MBTest tests => 2; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); use IO::File; my $tmp = MBTest->tmpdir; @@ -25,7 +24,4 @@ my $mb = eval { Module::Build->new_from_context}; ok(! $@, 'dodged the bullet') or die; ok($mb); -# cleanup -$dist->remove; - # vim:ts=2:sw=2:et:sta diff --git a/cpan/Module-Build/t/notes.t b/cpan/Module-Build/t/notes.t index 29f1fc38b1..4568e7c36a 100644 --- a/cpan/Module-Build/t/notes.t +++ b/cpan/Module-Build/t/notes.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 13; +use MBTest tests => 11; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; @@ -65,6 +64,3 @@ $mb = Module::Build->resume; ok $mb; is $mb->notes('foo'), 'bar'; - -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/parents.t b/cpan/Module-Build/t/parents.t index 666fb05601..825f79a787 100644 --- a/cpan/Module-Build/t/parents.t +++ b/cpan/Module-Build/t/parents.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 28; +use MBTest tests => 26; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); ######################### diff --git a/cpan/Module-Build/t/perl_mb_opt.t b/cpan/Module-Build/t/perl_mb_opt.t new file mode 100644 index 0000000000..70089ee6be --- /dev/null +++ b/cpan/Module-Build/t/perl_mb_opt.t @@ -0,0 +1,62 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 8; # or 'no_plan' + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in->regen; + +$dist->add_file('t/subtest/foo.t', <<'END_T'); +use strict; +use Test::More tests => 1; +ok(1, "this is a recursive test"); +END_T + +$dist->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); +ok( ! $mb->recursive_test_files, "set for no recursive testing" ); + +# set for recursive testing using PERL_MB_OPT +{ + local $ENV{PERL_MB_OPT} = "--verbose --recursive_test_files 1"; + + my $out = stdout_stderr_of( sub { + $dist->run_build('test'); + }); + like( $out, qr/this is a recursive test/, + "recursive tests run via PERL_MB_OPT" + ); +} + +# set Build.PL opts using PERL_MB_OPT +{ + local $ENV{PERL_MB_OPT} = "--verbose --recursive_test_files 1"; + my $mb = $dist->new_from_context(); # quiet by default + ok( $mb->recursive_test_files, "PERL_MB_OPT set recusive tests in Build.PL" ); + ok( $mb->verbose, "PERL_MB_OPT set verbose in Build.PL" ); +} + +# verify settings preserved during 'Build test' +{ + ok( !$ENV{PERL_MB_OPT}, "PERL_MB_OPT cleared" ); + my $out = stdout_stderr_of( sub { + $dist->run_build('test'); + }); + like( $out, qr/this is a recursive test/, + "recursive tests run via Build object" + ); +} + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/cpan/Module-Build/t/pod_parser.t b/cpan/Module-Build/t/pod_parser.t index 42a78209e2..64d4c75348 100644 --- a/cpan/Module-Build/t/pod_parser.t +++ b/cpan/Module-Build/t/pod_parser.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 8; +use MBTest tests => 9; -use_ok 'Module::Build::PodParser'; -ensure_blib('Module::Build::PodParser'); +blib_load('Module::Build::PodParser'); ######################### @@ -66,3 +65,26 @@ EOF } +{ + # Try again with mixed-case =head1s. + untie *FH; + tie *FH, 'IO::StringBased', <<'EOF'; +=head1 Name + +Foo::Bar - Perl extension for blah blah blah + +=head1 Author + +C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004. + +Home page: http://example.com/~eh/ + +=cut +EOF + + my $pp = Module::Build::PodParser->new(fh => \*FH); + ok $pp, 'object created'; + + is $pp->get_author->[0], 'C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.', 'author'; + is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract'; +} diff --git a/cpan/Module-Build/t/ppm.t b/cpan/Module-Build/t/ppm.t index 7fb6450648..4d69c9767a 100644 --- a/cpan/Module-Build/t/ppm.t +++ b/cpan/Module-Build/t/ppm.t @@ -3,11 +3,10 @@ use strict; use lib 't/lib'; use MBTest; - -use Module::Build; -use Module::Build::ConfigData; use Config; +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); my $manpage_support = Module::Build::ConfigData->feature('manpage_support'); my $HTML_support = Module::Build::ConfigData->feature('HTML_support'); @@ -26,15 +25,13 @@ my $HTML_support = Module::Build::ConfigData->feature('HTML_support'); } elsif ( $^O eq 'VMS' ) { plan skip_all => "Needs porting work on VMS"; } else { - plan tests => 13; + plan tests => 12; } } -ensure_blib('Module::Build'); my $tmp = MBTest->tmpdir; - use DistGen; my $dist = DistGen->new( dir => $tmp, xs => 1 ); $dist->add_file( 'hello', <<'---' ); @@ -66,7 +63,6 @@ $dist->chdir_in; use File::Spec::Functions qw(catdir); -use Module::Build; my @installstyle = qw(lib perl5); my $mb = Module::Build->new_from_context( verbose => 0, @@ -98,13 +94,10 @@ my $varchname = Module::Build::PPMMaker->_varchname($mb->config); # do a strict string comparison, but absent an XML parser it's the # best we can do. is $ppd, <<"---"; -<SOFTPKG NAME="$dist_filename" VERSION="0,01,0,0"> - <TITLE>@{[$dist->name]}</TITLE> +<SOFTPKG NAME="$dist_filename" VERSION="0.01"> <ABSTRACT>Perl extension for blah blah blah</ABSTRACT> <AUTHOR>A. U. Thor, a.u.thor\@a.galaxy.far.far.away</AUTHOR> <IMPLEMENTATION> - <PERLCORE VERSION="$perl_version" /> - <OS NAME="$^O" /> <ARCHITECTURE NAME="$varchname" /> <CODEBASE HREF="/path/to/codebase-xs" /> </IMPLEMENTATION> @@ -185,9 +178,6 @@ SKIP: { } -$dist->remove; - - ######################################## sub exists_ok { diff --git a/cpan/Module-Build/t/properties/module_name.t b/cpan/Module-Build/t/properties/module_name.t new file mode 100644 index 0000000000..c266b41ba2 --- /dev/null +++ b/cpan/Module-Build/t/properties/module_name.t @@ -0,0 +1,53 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 4; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# enter the directory and generate the skeleton files +my $dist = DistGen->new( name => "Not::So::Simple" )->chdir_in; + +#--------------------------------------------------------------------------# +# try getting module_name from dist directory name +#--------------------------------------------------------------------------# + +$dist->change_build_pl( + dist_name => 'Random-Name', + dist_version => 1, +)->regen; + +my $mb = $dist->new_from_context(); +isa_ok( $mb, "Module::Build" ); +is( $mb->module_name, "Not::So::Simple", + "module_name guessed from directory name" +); + +#--------------------------------------------------------------------------# +# Try getting module_name from dist_version_from +#--------------------------------------------------------------------------# + +$dist->add_file( 'lib/Simple/Name.pm', << 'END_PACKAGE' ); +package Simple::Name; +our $VERSION = 1.23; +1; +END_PACKAGE + +$dist->change_build_pl( + dist_name => 'Random-Name', + dist_version_from => 'lib/Simple/Name.pm', + dist_abstract => "Don't complain about missing abstract", +)->regen( clean => 1 ); + +$mb = $dist->new_from_context(); +isa_ok( $mb, "Module::Build" ); +is( $mb->module_name, "Simple::Name", + "module_name guessed from dist_version_from" +); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/cpan/Module-Build/t/properties/needs_compiler.t b/cpan/Module-Build/t/properties/needs_compiler.t new file mode 100644 index 0000000000..f298e82739 --- /dev/null +++ b/cpan/Module-Build/t/properties/needs_compiler.t @@ -0,0 +1,122 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 19; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +my $dist = DistGen->new->regen->chdir_in; + +# get a Module::Build object and test with it +my $mb; +stderr_of(sub { + ok( $mb = $dist->new_from_context, "Default Build.PL" ); +}); + +ok( ! $mb->needs_compiler, "needs_compiler is false" ); +ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder is not in build_requires" +); + +#--------------------------------------------------------------------------# +# try with c_source +#--------------------------------------------------------------------------# +$dist->change_build_pl({ + module_name => $dist->name, + license => 'perl', + c_source => 'src', +}); +$dist->regen; +stderr_of(sub { + ok( $mb = $dist->new_from_context, + "Build.PL with c_source" + ); +}); +is( $mb->c_source, 'src', "c_source is set" ); +ok( $mb->needs_compiler, "needs_compiler is true" ); +ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder was added to build_requires" +); + +#--------------------------------------------------------------------------# +# try with xs files +#--------------------------------------------------------------------------# +$dist = DistGen->new(dir => 'MBTest', xs => 1); +$dist->regen; +$dist->chdir_in; + +stderr_of(sub { + ok( $mb = $dist->new_from_context, + "Build.PL with xs files" + ); +}); +ok( $mb->needs_compiler, "needs_compiler is true" ); +ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder was added to build_requires" +); + +#--------------------------------------------------------------------------# +# force needs_compiler off, despite xs modules +#--------------------------------------------------------------------------# + +$dist->change_build_pl({ + module_name => $dist->name, + license => 'perl', + needs_compiler => 0, +}); +$dist->regen; + +stderr_of(sub { + ok( $mb = $dist->new_from_context , + "Build.PL with xs files, but needs_compiler => 0" + ); +}); +is( $mb->needs_compiler, 0, "needs_compiler is false" ); +ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder is not in build_requires" +); + +#--------------------------------------------------------------------------# +# don't override specific EU::CBuilder build_requires +#--------------------------------------------------------------------------# + +$dist->change_build_pl({ + module_name => $dist->name, + license => 'perl', + build_requires => { 'ExtUtils::CBuilder' => 0.2 }, +}); +$dist->regen; + +stderr_of(sub { + ok( $mb = $dist->new_from_context , + "Build.PL with xs files, build_requires EU::CB 0.2" + ); +}); +ok( $mb->needs_compiler, "needs_compiler is true" ); +is( $mb->build_requires->{'ExtUtils::CBuilder'}, 0.2, + "build_requires for ExtUtils::CBuilder is correct version" +); + +#--------------------------------------------------------------------------# +# falsify compiler and test error handling +#--------------------------------------------------------------------------# + +my $err = stderr_of( sub { + $mb = $dist->new_from_context( config => { cc => "adfasdfadjdjk" } ) +}); +ok( $mb, "Build.PL while hiding compiler" ); +like( $err, qr/no compiler detected/, + "hidden compiler resulted in warning message during Build.PL" +); +eval { $mb->dispatch('build') }; +like( $@, qr/no compiler detected/, + "hidden compiler resulted in fatal message during Build" +); + + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/cpan/Module-Build/t/properties/share_dir.t b/cpan/Module-Build/t/properties/share_dir.t new file mode 100644 index 0000000000..f781a8a7ce --- /dev/null +++ b/cpan/Module-Build/t/properties/share_dir.t @@ -0,0 +1,228 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +use File::Spec::Functions qw/catdir catfile/; + +#--------------------------------------------------------------------------# +# Begin testing +#--------------------------------------------------------------------------# + +plan tests => 21; + +blib_load('Module::Build'); + +#--------------------------------------------------------------------------# +# Create test distribution +#--------------------------------------------------------------------------# + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp, name => 'Simple::Share' ); +$dist->regen; +$dist->chdir_in; + +#--------------------------------------------------------------------------# +# Test setting 'share_dir' +#--------------------------------------------------------------------------# + +my $mb = $dist->new_from_context; + +# Test without a 'share' dir +ok( $mb, "Created Module::Build object" ); +is( $mb->share_dir, undef, + "default share undef if no 'share' dir exists" +); +ok( ! exists $mb->{properties}{requires}{'File::ShareDir'}, + "File::ShareDir not added to 'requires'" +); + +# Add 'share' dir and an 'other' dir and content +$dist->add_file('share/foo.txt',<< '---'); +This is foo.txt +--- +$dist->add_file('other/share/bar.txt',<< '---'); +This is bar.txt +--- +$dist->regen; +ok( -e catfile(qw/share foo.txt/), "Created 'share' directory" ); +ok( -e catfile(qw/other share bar.txt/), "Created 'other/share' directory" ); + +# Check default when share_dir is not given +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Default share_dir set as dist-type share" +); +is( $mb->{properties}{requires}{'File::ShareDir'}, '1.00', + "File::ShareDir 1.00 added to 'requires'" +); + +# share_dir set to scalar +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => 'share', + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Scalar share_dir set as dist-type share" +); + +# share_dir set to arrayref +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => [ 'share' ], + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Arrayref share_dir set as dist-type share" +); + +# share_dir set to hashref w scalar +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { dist => 'share' }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Hashref share_dir w/ scalar dist set as dist-type share" +); + +# share_dir set to hashref w array +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { dist => [ 'share' ] }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Hashref share_dir w/ arrayref dist set as dist-type share" +); + +# Generate a module sharedir (scalar) +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { + dist => 'share', + module => { $dist->name => 'other/share' }, + }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, + { dist => [ 'share' ], + module => { $dist->name => ['other/share'] }, + }, + "Hashref share_dir w/ both dist and module shares (scalar-form)" +); + +# Generate a module sharedir (array) +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { + dist => [ 'share' ], + module => { $dist->name => ['other/share'] }, + }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, + { dist => [ 'share' ], + module => { $dist->name => ['other/share'] }, + }, + "Hashref share_dir w/ both dist and module shares (array-form)" +); + +#--------------------------------------------------------------------------# +# test constructing to/from mapping +#--------------------------------------------------------------------------# + +is_deeply( $mb->_find_share_dir_files, + { + catfile(qw/share foo.txt/) => catfile(qw/dist Simple-Share foo.txt/), + catfile(qw/other share bar.txt/) => catfile(qw/module Simple-Share bar.txt/), + }, + "share_dir filemap for copying to lib complete" +); + +#--------------------------------------------------------------------------# +# test moving files to blib +#--------------------------------------------------------------------------# + +$mb->dispatch('build'); + +ok( -d 'blib', "Build ran and blib exists" ); +ok( -d 'blib/lib/auto/share', "blib/lib/auto/share exists" ); + +my $share_list = Module::Build->rscan_dir('blib/lib/auto/share', sub {-f}); + +is_deeply( + [ sort @$share_list ], [ + 'blib/lib/auto/share/dist/Simple-Share/foo.txt', + 'blib/lib/auto/share/module/Simple-Share/bar.txt', + ], + "share_dir files copied to blib" +); + +#--------------------------------------------------------------------------# +# test installing +#--------------------------------------------------------------------------# + +my $temp_install = 'temp_install'; +mkdir $temp_install; +ok( -d $temp_install, "temp install dir created" ); + +$mb->install_base($temp_install); +stdout_of( sub { $mb->dispatch('install') } ); + +$share_list = Module::Build->rscan_dir( + "$temp_install/lib/perl5/auto/share", sub {-f} +); + +is_deeply( + [ sort @$share_list ], [ + "$temp_install/lib/perl5/auto/share/dist/Simple-Share/foo.txt", + "$temp_install/lib/perl5/auto/share/module/Simple-Share/bar.txt", + ], + "share_dir files correctly installed" +); + +#--------------------------------------------------------------------------# +# test with File::ShareDir +#--------------------------------------------------------------------------# + +SKIP: { + eval { require File::ShareDir; File::ShareDir->VERSION(1.00) }; + skip "needs File::ShareDir 1.00", 2 if $@; + + unshift @INC, File::Spec->catdir($temp_install, qw/lib perl5/); + require Simple::Share; + + eval {File::ShareDir::dist_file('Simple-Share','foo.txt') }; + is( $@, q{}, "Found shared dist file" ); + + eval {File::ShareDir::module_file('Simple::Share','bar.txt') }; + is( $@, q{}, "Found shared module file" ); +} diff --git a/cpan/Module-Build/t/resume.t b/cpan/Module-Build/t/resume.t new file mode 100644 index 0000000000..add123d3d4 --- /dev/null +++ b/cpan/Module-Build/t/resume.t @@ -0,0 +1,43 @@ +use strict; +use lib 't/lib'; +use MBTest; +plan tests => 3; # or 'no_plan' +use DistGen; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in; +$dist->add_file('mylib/MBUtil.pm', << "---"); +package MBUtil; +sub foo { 42 } +1; +--- + +$dist->add_file('Build.PL', << "---"); +use strict; +use lib 'mylib'; +use MBUtil; +use Module::Build; + +die unless MBUtil::foo() == 42; + +my \$builder = Module::Build->new( +module_name => '$dist->{name}', +license => 'perl', +); + +\$builder->create_build_script(); +--- + +$dist->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); +ok( ( grep { /mylib/ } @INC ), "resume added \@INC addition to \@INC"); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/cpan/Module-Build/t/runthrough.t b/cpan/Module-Build/t/runthrough.t index 21d3d1c113..741755c12c 100644 --- a/cpan/Module-Build/t/runthrough.t +++ b/cpan/Module-Build/t/runthrough.t @@ -2,12 +2,10 @@ use strict; use lib 't/lib'; -use MBTest tests => 32; +use MBTest tests => 30; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); - -use Module::Build::ConfigData; +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); my $have_yaml = Module::Build::ConfigData->feature('YAML_support'); ######################### @@ -24,6 +22,9 @@ $dist->change_build_pl requires => { 'File::Spec' => 0 }, }); +$dist->add_file( 'MANIFEST.SKIP', <<'---' ); +^MYMETA.yml$ +--- $dist->add_file( 'script', <<'---' ); #!perl -w print "Hello, World!\n"; @@ -169,12 +170,11 @@ SKIP: { # do a strict string comparison, but absent an XML parser it's the # best we can do. is $ppd, <<'EOF'; -<SOFTPKG NAME="Simple" VERSION="0,01,0,0"> - <TITLE>Simple</TITLE> +<SOFTPKG NAME="Simple" VERSION="0.01"> <ABSTRACT>Perl extension for blah blah blah</ABSTRACT> <AUTHOR>A. U. Thor, a.u.thor@a.galaxy.far.far.away</AUTHOR> <IMPLEMENTATION> - <DEPENDENCY NAME="File-Spec" VERSION="0,0,0,0" /> + <REQUIRE NAME="File::Spec" VERSION="0" /> <CODEBASE HREF="/path/to/codebase" /> </IMPLEMENTATION> </SOFTPKG> @@ -189,8 +189,6 @@ ok ! -e $mb->build_script; ok ! -e $mb->config_dir; ok ! -e $mb->dist_dir; -$dist->remove; - SKIP: { skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/; @@ -223,8 +221,5 @@ echo Hello, World! my $out = slurp( $script_file ); is $out, $script_data, ' unmodified by pl2bat'; - $dist->remove; } -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/sample.t b/cpan/Module-Build/t/sample.t new file mode 100644 index 0000000000..d83bc56ecc --- /dev/null +++ b/cpan/Module-Build/t/sample.t @@ -0,0 +1,20 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest tests => 2; # or 'no_plan' +use DistGen; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/cpan/Module-Build/t/script_dist.t b/cpan/Module-Build/t/script_dist.t index e6b7fd8832..02faca0132 100644 --- a/cpan/Module-Build/t/script_dist.t +++ b/cpan/Module-Build/t/script_dist.t @@ -8,7 +8,8 @@ use MBTest 'no_plan'; use DistGen qw(undent); -use Module::Build; +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); # XXX DistGen shouldn't be assuming module-ness? my $dist = DistGen->new(dir => MBTest->tmpdir); @@ -69,12 +70,11 @@ is_deeply($mb->dist_author, ['A. U. Thor, a.u.thor@a.galaxy.far.far.away']); ok $mb->dispatch('distmeta'); -use Module::Build::ConfigData; SKIP: { skip( 'YAML_support feature is not enabled', 1 ) unless Module::Build::ConfigData->feature('YAML_support'); - require YAML; - my $yml = YAML::LoadFile('META.yml'); + require YAML::Tiny; + my $yml = YAML::Tiny::LoadFile('META.yml'); is_deeply($yml->{provides}, \%meta_provides); } $dist->chdir_original if $dist->did_chdir; diff --git a/cpan/Module-Build/t/test_file_exts.t b/cpan/Module-Build/t/test_file_exts.t index 9dbf73e290..5bb803c7aa 100644 --- a/cpan/Module-Build/t/test_file_exts.t +++ b/cpan/Module-Build/t/test_file_exts.t @@ -2,11 +2,10 @@ use strict; use lib 't/lib'; -use MBTest tests => 5; +use MBTest tests => 3; use DistGen; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; my $dist = DistGen->new( dir => $tmp ); @@ -39,7 +38,4 @@ my $out = uc(stdout_of( like $out, qr/^OK 1 - FIRST MYTEST[.]S/m, 'Should see first test output'; like $out, qr/^OK 2 - SECOND MYTEST[.]S/m, 'Should see second test output'; -# Cleanup. -$dist->remove; - # vim:ts=4:sw=4:et:sta diff --git a/cpan/Module-Build/t/test_type.t b/cpan/Module-Build/t/test_type.t index 3c6cfb61e4..fe4d599d72 100644 --- a/cpan/Module-Build/t/test_type.t +++ b/cpan/Module-Build/t/test_type.t @@ -9,10 +9,9 @@ BEGIN { use strict; use lib 't/lib'; -use MBTest tests => 9; +use MBTest tests => 7; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; @@ -72,6 +71,4 @@ like($output, qr/\.\. ?OK/); is($::x, 3, "called a third time"); -$dist->remove; - # vim:ts=4:sw=4:et:sta diff --git a/cpan/Module-Build/t/test_types.t b/cpan/Module-Build/t/test_types.t index 5f3f5cff8d..d88e215aa3 100644 --- a/cpan/Module-Build/t/test_types.t +++ b/cpan/Module-Build/t/test_types.t @@ -2,16 +2,13 @@ use strict; use lib 't/lib'; -use MBTest tests => 15 + 12; +use MBTest tests => 25; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); - -my $tmp = MBTest->tmpdir; +blib_load('Module::Build'); use DistGen; -my $dist = DistGen->new(dir => $tmp); +my $dist = DistGen->new()->chdir_in; $dist->add_file('t/special_ext.st', <<'---'); #!perl @@ -34,7 +31,6 @@ die "don't run this non-test file"; --- $dist->regen; -$dist->chdir_in; ######################### my $mb = Module::Build->subclass( @@ -98,10 +94,10 @@ is(scalar(@{[$all_output =~ m/OK 1/mg]}), 3 ); is(scalar(@{[$all_output =~ m/OK/mg]}), 8 ); is(scalar(@{[$all_output =~ m/ALL TESTS SUCCESSFUL\./mg]}), 1); -$dist->remove; - { # once-again +$dist->revert; + $dist->add_file('t/foo/special.st', <<'---'); #!perl use Test::More tests => 2; @@ -114,7 +110,6 @@ use strict; use Simple; ok 1; --- $dist->regen; -$dist->chdir_in; my $mb = Module::Build->subclass( code => q# @@ -174,7 +169,6 @@ like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m); is(scalar(@{[$all_output =~ m/(OK 1)/mg]}), 5 ); is(scalar(@{[$all_output =~ m/(OK)/mg]}), 13 ); -$dist->remove; } # end once-again # vim:ts=4:sw=4:et:sta diff --git a/cpan/Module-Build/t/tilde.t b/cpan/Module-Build/t/tilde.t index 5b39204171..692ade0c8a 100644 --- a/cpan/Module-Build/t/tilde.t +++ b/cpan/Module-Build/t/tilde.t @@ -4,10 +4,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 18; +use MBTest tests => 16; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; @@ -111,6 +110,3 @@ SKIP: { like( run_sample( $p => "~$me/foo")->$p(), qr($expected)i ); } - -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/use_tap_harness.t b/cpan/Module-Build/t/use_tap_harness.t index d14cb052ba..f6e7e5073a 100644 --- a/cpan/Module-Build/t/use_tap_harness.t +++ b/cpan/Module-Build/t/use_tap_harness.t @@ -4,7 +4,7 @@ use strict; use Test::More; use lib 't/lib'; if (eval { require TAP::Harness } && TAP::Harness->VERSION >= 3) { - plan tests => 8; + plan tests => 9; } else { plan skip_all => 'TAP::Harness 3+ not installed' } @@ -12,21 +12,24 @@ if (eval { require TAP::Harness } && TAP::Harness->VERSION >= 3) { use MBTest; use DistGen; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; my $dist = DistGen->new( dir => $tmp ); $dist->regen; - $dist->chdir_in; + ######################### # Make sure that TAP::Harness properly does its thing. -ok my $mb = Module::Build->new( +$dist->change_build_pl( module_name => $dist->name, use_tap_harness => 1, quiet => 1, -), 'Construct build object with test_file_exts parameter'; +); +$dist->regen; + +ok my $mb = $dist->new_from_context, + 'Construct build object with test_file_exts parameter'; $mb->add_to_cleanup('save_out'); # Use uc() so we don't confuse the current test output @@ -40,12 +43,16 @@ like $out, qr/^ALL TESTS SUCCESSFUL/m, 'Should see test success message'; ######################### # Make sure that arguments are passed through to TAP::Harness. -ok $mb = Module::Build->new( +$dist->change_build_pl( module_name => $dist->name, use_tap_harness => 1, tap_harness_args => { verbosity => 0 }, quiet => 1, -), 'Construct build object with test_file_exts parameter'; +); +$dist->regen; + +ok $mb = $dist->new_from_context, + 'Construct build object with test_file_exts parameter'; $mb->add_to_cleanup('save_out'); # Use uc() so we don't confuse the current test output @@ -56,6 +63,32 @@ $out = uc(stdout_of( unlike $out, qr/^OK 1/m, 'Should not see first test output'; like $out, qr/^ALL TESTS SUCCESSFUL/m, 'Should see test success message'; -$dist->remove; +#--------------------------------------------------------------------------# +# test that a failing test dies +#--------------------------------------------------------------------------# + +$dist->change_build_pl( + module_name => $dist->name, + use_tap_harness => 1, + tap_harness_args => { verbosity => 1 }, + quiet => 1, +); +$dist->change_file('t/basic.t',<<"---"); +use Test::More tests => 1; +use strict; + +use $dist->{name}; +ok 0; +--- +$dist->regen; + +ok $mb = $dist->new_from_context, + 'Construct build object after setting tests to fail'; +# Use uc() so we don't confuse the current test output +$out = stdout_stderr_of( sub { $dist->run_build('test')} ); +ok( $?, "'Build test' had non-zero exit code" ); +like( $out, qr{Errors in testing\. Cannot continue\.}, + "Saw emulated Test::Harness die() message" +); # vim:ts=4:sw=4:et:sta diff --git a/cpan/Module-Build/t/versions.t b/cpan/Module-Build/t/versions.t index 7f511e58f6..5eafbac297 100644 --- a/cpan/Module-Build/t/versions.t +++ b/cpan/Module-Build/t/versions.t @@ -2,10 +2,9 @@ use strict; use lib 't/lib'; -use MBTest tests => 4; +use MBTest tests => 2; -use_ok 'Module::Build'; -ensure_blib('Module::Build'); +blib_load('Module::Build'); my $tmp = MBTest->tmpdir; @@ -20,7 +19,3 @@ my $file = File::Spec->catfile( $dist->dirname, 'lib', @mod ) . '.pm'; is( Module::Build->version_from_file( $file ), '0.01', 'version_from_file' ); ok( Module::Build->compare_versions( '1.01_01', '>', '1.01' ), 'compare: 1.0_01 > 1.0' ); - - -# cleanup -$dist->remove; diff --git a/cpan/Module-Build/t/write_default_maniskip.t b/cpan/Module-Build/t/write_default_maniskip.t index 084d81ed3e..40389f20dc 100644 --- a/cpan/Module-Build/t/write_default_maniskip.t +++ b/cpan/Module-Build/t/write_default_maniskip.t @@ -8,14 +8,14 @@ use MBTest 'no_plan'; use DistGen; use Cwd; -use_ok 'Module::Build'; -ensure_blib 'Module::Build'; +blib_load('Module::Build'); { my $cwd = Cwd::cwd; chdir MBTest->tmpdir(); my $build = Module::Build->new( + module_name => "Foo::Bar", dist_name => "Foo-Bar", dist_version => '1.23', ); diff --git a/cpan/Module-Build/t/xs.t b/cpan/Module-Build/t/xs.t index e3f1ed7dd1..6d167c8539 100644 --- a/cpan/Module-Build/t/xs.t +++ b/cpan/Module-Build/t/xs.t @@ -3,11 +3,12 @@ use strict; use lib 't/lib'; use MBTest; -use Module::Build; use Config; my $tmp; +blib_load('Module::Build'); + { my ($have_c_compiler, $C_support_feature, $tmp_exec) = check_compiler(); @@ -20,24 +21,20 @@ my $tmp; } elsif ( !$Config{usedl} ) { plan skip_all => 'Perl not compiled for dynamic loading' } else { - plan tests => 23; + plan tests => 20; } require Cwd; $tmp = MBTest->tmpdir( $tmp_exec ? undef : Cwd::cwd ); } -ensure_blib('Module::Build'); ######################### use DistGen; -my $dist = DistGen->new( dir => $tmp, xs => 1 ); -$dist->regen; - -$dist->chdir_in; -my $mb = Module::Build->new_from_context; +my $dist = DistGen->new( dir => $tmp, xs => 1 )->chdir_in->regen; +my $mb = $dist->new_from_context; eval {$mb->dispatch('clean')}; is $@, ''; @@ -83,7 +80,7 @@ is $@, ''; # We can't be verbose in the sub-test, because Test::Harness will # think that the output is for the top-level test. -eval {$mb->dispatch('test')}; +stdout_stderr_of( sub { eval {$mb->dispatch('test')} }); is $@, ''; eval {$mb->dispatch('clean')}; @@ -106,42 +103,31 @@ is $@, ''; # Make sure blib/ is gone after 'realclean' ok ! -e 'blib'; - -# cleanup -$dist->remove; - - ######################################## # Try a XS distro with a deep namespace -$dist = DistGen->new( name => 'Simple::With::Deep::Name', - dir => $tmp, xs => 1 ); -$dist->regen; -$dist->chdir_in; -$mb = Module::Build->new_from_context; -is $@, ''; +$dist->reset( name => 'Simple::With::Deep::Name', dir => $tmp, xs => 1 ); +$dist->chdir_in->regen; -$mb->dispatch('build'); -is $@, ''; +$mb = $dist->new_from_context; -$mb->dispatch('test'); +eval { $mb->dispatch('build') }; is $@, ''; -$mb->dispatch('realclean'); +stdout_stderr_of( sub { eval { $mb->dispatch('test') } } ); is $@, ''; -# cleanup -$dist->remove; - +eval { $mb->dispatch('realclean') }; +is $@, ''; ######################################## # Try a XS distro using a flat directory structure # and a 'dist_name' instead of a 'module_name' -$dist = DistGen->new( name => 'Dist-Name', dir => $tmp, xs => 1 ); +$dist->reset( name => 'Dist-Name', dir => $tmp, xs => 1 )->chdir_in; $dist->remove_file('lib/Dist-Name.pm'); $dist->remove_file('lib/Dist-Name.xs'); @@ -211,20 +197,15 @@ ok( Simple::okay() eq 'ok' ); --- $dist->regen; -$dist->chdir_in; - -$mb = Module::Build->new_from_context; -is $@, ''; +$mb = $dist->new_from_context; -$mb->dispatch('build'); +eval { $mb->dispatch('build') }; is $@, ''; -$mb->dispatch('test'); +stdout_of( sub { eval { $mb->dispatch('test') } } ); is $@, ''; -$mb->dispatch('realclean'); +eval { $mb->dispatch('realclean') }; is $@, ''; -# cleanup -$dist->remove; |