diff --git a/Changes b/Changes index ebdc5dd..58b04d0 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Revision history for Perl extension {{$dist->name}} {{$NEXT}} + - Add max_target_perl to control the maximum perl we're + okay with requiring explicitly [GH#1 - xdg++] 2.000002 2012-06-16 - Declare Dist::Zilla dependency diff --git a/lib/Dist/Zilla/Plugin/Test/MinimumVersion.pm b/lib/Dist/Zilla/Plugin/Test/MinimumVersion.pm index 0dbb919..b9d908b 100644 --- a/lib/Dist/Zilla/Plugin/Test/MinimumVersion.pm +++ b/lib/Dist/Zilla/Plugin/Test/MinimumVersion.pm @@ -5,8 +5,29 @@ use warnings; package Dist::Zilla::Plugin::Test::MinimumVersion; # ABSTRACT: Release tests for minimum required versions # VERSION + use Moose; extends 'Dist::Zilla::Plugin::InlineFiles'; +with 'Dist::Zilla::Role::TextTemplate'; + +has max_target_perl => ( + is => 'ro', + isa => 'Str', + predicate => 'has_max_target_perl', +); + +around add_file => sub { + my ($orig, $self, $file) = @_; + $self->$orig( + Dist::Zilla::File::InMemory->new({ + name => $file->name, + content => $self->fill_in_string( + $file->content, + { (version => $self->max_target_perl)x!!$self->has_max_target_perl } + ), + }) + ); +}; __PACKAGE__->meta->make_immutable; no Moose; @@ -17,6 +38,7 @@ no Moose; In C: [Test::MinimumVersion] + max_target_perl = 5.10.1 =for test_synopsis 1; @@ -24,11 +46,16 @@ __END__ =head1 DESCRIPTION -This is an extension of L, providing the -following file: +This is an extension of L, providing a +L test: xt/release/minimum-version.t - a standard Test::MinimumVersion test +You should provide the highest perl version you want to require as +C. If you accidentally use perl features that are newer +than that version number, then the test will fail, and you can go change +whatever bumped up the minimum perl version required. + =cut __DATA__ @@ -40,4 +67,7 @@ use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; -all_minimum_version_from_metayml_ok(); +{{ $version + ? "all_minimum_version_ok( qq{$version} );" + : "all_minimum_version_from_metayml_ok();" +}} diff --git a/t/everything.t b/t/everything.t index 5a6e10b..dfd6232 100644 --- a/t/everything.t +++ b/t/everything.t @@ -1,29 +1,58 @@ use strict; use warnings; -use Test::More 0.96 tests => 1; +use Test::More 0.96 tests => 2; use autodie; use Test::DZil; use Moose::Autobox; -my $tzil = Builder->from_config( - { dist_root => 'corpus/DZ1' }, - { - add_files => { - 'source/dist.ini' => simple_ini( - ('GatherDir', 'Test::MinimumVersion') - ), +subtest 'explicit version' => sub { + plan tests => 2; + + my $tzil = Builder->from_config( + { dist_root => 'corpus/DZ1' }, + { + add_files => { + 'source/dist.ini' => simple_ini( + ('GatherDir', ['Test::MinimumVersion' => { max_target_perl => '5.10.1' }]) + ), + }, + }, + ); + $tzil->build; + END { # Remove (empty) dir created by building the dists + require File::Path; + File::Path::rmtree('tmp') if -d 'tmp'; + } + + my ($test) = map { $_->name eq 'xt/release/minimum-version.t' ? $_ : () } $tzil->files->flatten; + ok $test, 'minimum-version.t exists' + or diag explain [ map { $_->name } $tzil->files->flatten ]; + + like $test->content => qr{\Q5.10.1\E}, 'max_target_perl used in test'; +}; + +subtest 'version from metayml' => sub { + plan tests => 2; + + my $tzil = Builder->from_config( + { dist_root => 'corpus/DZ1' }, + { + add_files => { + 'source/dist.ini' => simple_ini( + ('GatherDir', 'Test::MinimumVersion') + ), + }, }, - }, -); -$tzil->build; - -my @xtests = map $_->name =~ m{^xt/} ? $_->name : (), $tzil->files->flatten; -ok( - (grep { $_ eq 'xt/release/minimum-version.t' } @xtests), - 'minimum-version.t exists' -) or diag explain \@xtests; - -END { # Remove (empty) dir created by building the dists - require File::Path; - File::Path::rmtree('tmp'); -} + ); + $tzil->build; + END { # Remove (empty) dir created by building the dists + require File::Path; + File::Path::rmtree('tmp') if -d 'tmp'; + } + + my ($test) = map { $_->name eq 'xt/release/minimum-version.t' ? $_ : () } $tzil->files->flatten; + ok $test, 'minimum-version.t exists' + or diag explain [ map { $_->name } $tzil->files->flatten ]; + + like $test->content => qr{metayml}, 'metayml used in test'; +}; \ No newline at end of file