Created
August 31, 2014 19:53
-
-
Save karenetheridge/9ff91bd4774239dc9680 to your computer and use it in GitHub Desktop.
got a (reproducable) error doing 'git hub pull-request' in my Dist-Zilla-Plugin-Conflicts repo...
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
delay file generation until prereqs are available: restores -also section | |
Also, TESTS! :D | |
# New GitHub Pull Request | |
# | |
# Requesting that... | |
# repo: karenetheridge/Dist-Zilla-Plugin-Conflicts | |
# branch: topic/file_fromcode | |
# ...be pulled into... | |
# repo: autarch/Dist-Zilla-Plugin-Conflicts | |
# branch: master | |
# | |
# Enter your pull request info at the top like this: | |
# | |
# First line is the pull request subject | |
# | |
# The pull request body comes here, after a blank line separating it from | |
# the subject. | |
# | |
# The body can be as many lines as needed, and is optional. Only the pull | |
# request subject is required. | |
# | |
#------------------------------------------------------------------------------ | |
$ git diff upstream/master..topic/file_fromcode | |
diff --git a/Changes b/Changes | |
index 012575e..8efee9f 100644 | |
--- a/Changes | |
+++ b/Changes | |
@@ -1,5 +1,10 @@ | |
{{$NEXT}} | |
+- generate Conflicts module as a FromCode file, so its content is not | |
+ calculated until prereqs are available: restores the -also section lost | |
+ in version 0.09 (Karen Etheridge) | |
+ | |
+ | |
0.14 2014-04-06 | |
- Same as 0.13001 | |
diff --git a/lib/Dist/Zilla/Plugin/Conflicts.pm b/lib/Dist/Zilla/Plugin/Conflicts.pm | |
index f9af0f8..f345594 100644 | |
--- a/lib/Dist/Zilla/Plugin/Conflicts.pm | |
+++ b/lib/Dist/Zilla/Plugin/Conflicts.pm | |
@@ -7,6 +7,7 @@ use namespace::autoclean; | |
use Dist::CheckConflicts 0.02 (); | |
use Dist::Zilla 4.0 (); | |
use Dist::Zilla::File::InMemory; | |
+use Dist::Zilla::File::FromCode; | |
use Moose::Autobox 0.09; | |
use Moose; | |
@@ -97,9 +98,9 @@ sub gather_files { | |
my $self = shift; | |
$self->add_file( | |
- Dist::Zilla::File::InMemory->new( | |
+ Dist::Zilla::File::FromCode->new( | |
name => $self->_conflicts_module_path(), | |
- content => $self->_generate_conflicts_module(), | |
+ code => sub { $self->_generate_conflicts_module }, | |
) | |
); | |
diff --git a/t/01-basic.t b/t/01-basic.t | |
new file mode 100644 | |
index 0000000..c3f70e2 | |
--- /dev/null | |
+++ b/t/01-basic.t | |
@@ -0,0 +1,139 @@ | |
+use strict; | |
+use warnings FATAL => 'all'; | |
+ | |
+use Test::More; | |
+use if $ENV{AUTHOR_TESTING}, 'Test::Warnings'; | |
+use Test::Deep; | |
+use Test::DZil; | |
+use Test::Fatal; | |
+use Path::Tiny; | |
+use File::pushd 'pushd'; | |
+ | |
+my $tzil = Builder->from_config( | |
+ { dist_root => 't/does-not-exist' }, | |
+ { | |
+ add_files => { | |
+ path(qw(source dist.ini)) => simple_ini( | |
+ [ GatherDir => ], | |
+ [ MakeMaker => ], | |
+ [ ExecDir => ], | |
+ [ Prereqs => { 'Foo' => '0' } ], | |
+ [ 'Conflicts' => { -script => 'script/dzt-conflicts', 'Module::X' => '0.02' } ], | |
+ ), | |
+ path(qw(source lib DZT Sample.pm)) => "package DZT::Sample;\n1;\n", | |
+ }, | |
+ }, | |
+); | |
+ | |
+$tzil->chrome->logger->set_debug(1); | |
+is( | |
+ exception { $tzil->build }, | |
+ undef, | |
+ 'build proceeds normally', | |
+); | |
+ | |
+cmp_deeply( | |
+ $tzil->distmeta, | |
+ superhashof({ | |
+ prereqs => { | |
+ configure => { | |
+ requires => { | |
+ 'Dist::CheckConflicts' => '0.02', | |
+ 'ExtUtils::MakeMaker' => ignore, # added by [MakeMaker] | |
+ } | |
+ }, | |
+ runtime => { | |
+ requires => { | |
+ 'Dist::CheckConflicts' => '0.02', | |
+ 'Foo' => '0', | |
+ }, | |
+ }, | |
+ }, | |
+ }), | |
+ 'prereqs are injected', | |
+) or diag 'got distmeta: ', explain $tzil->distmeta; | |
+ | |
+my $build_dir = path($tzil->tempdir)->child('build'); | |
+ | |
+my $module_filename = $build_dir->child(qw(lib DZT Sample Conflicts.pm)); | |
+ok(-e $module_filename, 'conflicts module created'); | |
+ | |
+my $module_content = $module_filename->slurp_utf8; | |
+unlike($module_content, qr/[^\S\n]\n/m, 'no trailing whitespace in generated module'); | |
+ | |
+my $expected_module_content = <<'MODULE_CONTENT'; | |
+package # hide from PAUSE | |
+ DZT::Sample::Conflicts; | |
+ | |
+use strict; | |
+use warnings; | |
+ | |
+use Dist::CheckConflicts | |
+ -dist => 'DZT::Sample', | |
+ -conflicts => { | |
+ 'Module::X' => '0.02', | |
+ }, | |
+ -also => [ qw( | |
+ Dist::CheckConflicts | |
+ Foo | |
+ ) ], | |
+ | |
+; | |
+ | |
+1; | |
+ | |
+# ABSTRACT: Provide information on conflicts for DZT::Sample | |
+MODULE_CONTENT | |
+ | |
+is( | |
+ index($module_content, $expected_module_content), | |
+ 0, | |
+ 'module content looks good', | |
+) or diag 'got module content:', "\n", $module_content; | |
+ | |
+ | |
+my $script_filename = $build_dir->child(qw(script dzt-conflicts)); | |
+ok(-e $script_filename, 'conflicts script created'); | |
+ | |
+my $script_content = $script_filename->slurp_utf8; | |
+unlike($script_content, qr/[^\S\n]\n/m, 'no trailing whitespace in generated script'); | |
+ | |
+my $expected_script_content = <<'SCRIPT_CONTENT'; | |
+#!/usr/bin/perl | |
+ | |
+use strict; | |
+use warnings; | |
+# PODNAME: dzt-conflicts | |
+ | |
+use Getopt::Long; | |
+use DZT::Sample::Conflicts; | |
+ | |
+my $verbose; | |
+GetOptions( 'verbose|v' => \$verbose ); | |
+ | |
+if ($verbose) { | |
+ DZT::Sample::Conflicts->check_conflicts; | |
+} | |
+else { | |
+ my @conflicts = DZT::Sample::Conflicts->calculate_conflicts; | |
+ print "$_\n" for map { $_->{package} } @conflicts; | |
+ exit @conflicts; | |
+} | |
+SCRIPT_CONTENT | |
+ | |
+is( | |
+ index($script_content, $expected_script_content), | |
+ 0, | |
+ 'script content looks good', | |
+) or diag 'got script content:', "\n", $script_content; | |
+ | |
+ | |
+{ | |
+ my $wd = pushd $build_dir; | |
+ | |
+ push @ARGV, '--verbose'; # avoid the exit code path | |
+ do $script_filename; | |
+ ok(!$@, 'ran script successfully') or diag $@; | |
+} | |
+ | |
+done_testing; | |
#------------------------------------------------------------------------------ | |
$ git log upstream/master..topic/file_fromcode | |
commit 75a25974a2e9d03326eaf68273bf1e643d6f7544 | |
Author: Karen Etheridge <ether@cpan.org> | |
Date: Sun Aug 31 12:45:25 2014 -0700 | |
delay file generation until prereqs are available: restores -also section | |
(and closes RT#76496) | |
commit c7d7965d5af75da3cc8e5e25e20cd6261cd2d484 | |
Author: Karen Etheridge <ether@cpan.org> | |
Date: Sun Aug 31 12:36:48 2014 -0700 | |
test the contents of the generated module and script | |
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
: [ether@tequila git/Dist-Zilla-Plugin-Conflicts].9$; git hub pull-request | |
Error: malformed message in '.git/GIT_HUB_EDIT_MSG' | |
Usage: git hub pull-request [<issue-id-number>] [<options>] | |
Create a new pull request for a repository based on the current branch. If | |
an issue ID number is given, this command will attach the pull request to the | |
issue instead of creating a new one. | |
If the default remote is a fork, the pull request will target the default | |
branch of the parent repository. Otherwise the pull request will target the | |
default branch of the default remote itself. Use `--remote`, `--branch`, | |
`--parent`, and `--base` options to change the default source remote, source | |
branch, target remote and target branch (respectively). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment