Created
March 28, 2013 09:05
-
-
Save miyagawa/5261788 to your computer and use it in GitHub Desktop.
Patch to turn M::I's test_requires() to MakeMaker's TEST_REQUIRES if supported. It is incomplete and 2 tests are failing with this change. Not sure if it is worth fixing :/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: t/27_build_requires_and_include.t | |
=================================================================== | |
--- t/27_build_requires_and_include.t (revision 15742) | |
+++ t/27_build_requires_and_include.t (working copy) | |
@@ -31,7 +31,7 @@ | |
ok(-f $meta_yml, 'has META.yml'); | |
my $meta = YAML::Tiny::LoadFile($meta_yml); | |
- ok $meta->{build_requires}{'Test::More'}, 'Test::More is listed in build_requires'; | |
+ ok $meta->{build_requires}{'Test::More'}, 'Test::More is listed in build_requires'; | |
my $makefile = makefile(); | |
ok(-f $makefile, 'has Makefile'); | |
Index: lib/Module/Install/Admin/Metadata.pm | |
=================================================================== | |
--- lib/Module/Install/Admin/Metadata.pm (revision 15742) | |
+++ lib/Module/Install/Admin/Metadata.pm (working copy) | |
@@ -57,6 +57,10 @@ | |
my $ver = $self->_top->VERSION; | |
my $val = $self->Meta->{values}; | |
+ # At this point test_requires have been sent to MakeMaker | |
+ # Merge it to build_requires | |
+ $val->{build_requires} = [ @{$val->{build_requires}}, @{(delete $val->{test_requires}) || []} ]; | |
+ | |
delete $val->{sign}; | |
# Dependencies MUST be assumed to be dynamic unless indicated | |
Index: lib/Module/Install/Makefile.pm | |
=================================================================== | |
--- lib/Module/Install/Makefile.pm (revision 15742) | |
+++ lib/Module/Install/Makefile.pm (working copy) | |
@@ -198,6 +198,20 @@ | |
$self->tests( join ' ', sort keys %tests ); | |
} | |
+sub _flatten_prereqs { | |
+ my($self, $args, $args_key, @requires) = @_; | |
+ | |
+ my $prereq = ($args->{$args_key} ||= {}); | |
+ %$prereq = ( %$prereq, | |
+ map { @$_ } # flatten [module => version] | |
+ map { @$_ } | |
+ grep $_, | |
+ @requires | |
+ ); | |
+ | |
+ $prereq; | |
+} | |
+ | |
sub write { | |
my $self = shift; | |
die "&Makefile->write() takes no arguments\n" if @_; | |
@@ -287,17 +301,24 @@ | |
# Remove any reference to perl, PREREQ_PM doesn't support it | |
delete $args->{PREREQ_PM}->{perl}; | |
- # Merge both kinds of requires into BUILD_REQUIRES | |
- my $build_prereq = ($args->{BUILD_REQUIRES} ||= {}); | |
- %$build_prereq = ( %$build_prereq, | |
- map { @$_ } # flatten [module => version] | |
- map { @$_ } | |
- grep $_, | |
- ($self->configure_requires, $self->build_requires) | |
- ); | |
+ my($build_prereq, $test_prereq); | |
+ if ($self->makemaker(6.63_03)) { | |
+ $build_prereq = $self->_flatten_prereqs( | |
+ $args, 'BUILD_REQUIRES', ($self->configure_requires, $self->build_requires), | |
+ ); | |
+ $test_prereq = $self->_flatten_prereqs( | |
+ $args, 'TEST_REQUIRES', $self->test_requires, | |
+ ); | |
+ } else { | |
+ # Merge both kinds of requires into BUILD_REQUIRES | |
+ $build_prereq = $self->_flatten_prereqs( | |
+ $args, 'BUILD_REQUIRES', ($self->configure_requires, $self->build_requires, $self->test_requires), | |
+ ); | |
+ } | |
# Remove any reference to perl, BUILD_REQUIRES doesn't support it | |
delete $args->{BUILD_REQUIRES}->{perl}; | |
+ delete $args->{TEST_REQUIRES}->{perl} if exists $args->{TEST_REQUIRES}; | |
# Delete bundled dists from prereq_pm, add it to Makefile DIR | |
my $subdirs = ($args->{DIR} || []); | |
@@ -319,7 +340,7 @@ | |
} | |
unless ( $self->makemaker('6.55_03') ) { | |
- %$prereq = (%$prereq,%$build_prereq); | |
+ %$prereq = (%$prereq,%$build_prereq,%$test_prereq); | |
delete $args->{BUILD_REQUIRES}; | |
} | |
Index: lib/Module/Install/API.pod | |
=================================================================== | |
--- lib/Module/Install/API.pod (revision 15742) | |
+++ lib/Module/Install/API.pod (working copy) | |
@@ -189,11 +189,9 @@ | |
install everything for future reuse (unless you are too lazy to test | |
distributions). | |
-As of this writing, C<test_requires> is just an alias for | |
-C<build_requires>, but this may change in the future. | |
- | |
-The values set by B<build_requires> and B<test_requires> are passed | |
-to L<ExtUtils::MakeMaker> as a C<BUILD_REQUIRES> attribute, which may | |
+The values set by B<build_requires> and B<test_requires> are passed to | |
+L<ExtUtils::MakeMaker> as a C<BUILD_REQUIRES> and C<TEST_REQUIRES> (if | |
+it is newer than version 6.63_03) attribute respectively, which may | |
fall back to C<PREREQ_PM> if your L<ExtUtils::MakeMaker> is not new | |
enough. | |
Index: lib/Module/Install/Metadata.pm | |
=================================================================== | |
--- lib/Module/Install/Metadata.pm (revision 15742) | |
+++ lib/Module/Install/Metadata.pm (working copy) | |
@@ -27,6 +27,7 @@ | |
my @tuple_keys = qw{ | |
configure_requires | |
build_requires | |
+ test_requires | |
requires | |
recommends | |
bundles | |
@@ -140,7 +141,6 @@ | |
# Aliases for build_requires that will have alternative | |
# meanings in some future version of META.yml. | |
-sub test_requires { shift->build_requires(@_) } | |
sub install_requires { shift->build_requires(@_) } | |
# Aliases for installdirs options |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment