Permalink
Browse files

Added gitvercheck.t

  Added corpus/gitvercheck.git
  Don't need .git in MANIFEST.SKIP
  Add File::pushd & Test::Fatal to test prereqs
  Need File::Temp 0.19 for newdir
  • Loading branch information...
1 parent 7210390 commit c7046caef38737760cb298df4abf1c02bce82dd8 @madsen committed Nov 9, 2010
Showing with 551 additions and 3 deletions.
  1. +2 −0 MANIFEST
  2. +0 −2 MANIFEST.SKIP
  3. +339 −0 corpus/gitvercheck.git
  4. +5 −1 dist.ini
  5. +205 −0 t/gitvercheck.t
View
2 MANIFEST
@@ -13,6 +13,7 @@ corpus/README
corpus/archives/DZT-Sample-0.01.tar.gz
corpus/archives/DZT-Sample-0.02.tar.gz
corpus/archives/DZT-Sample-0.03.tar.gz
+corpus/gitvercheck.git
lib/Dist/Zilla/Plugin/ArchiveRelease.pm
lib/Dist/Zilla/Plugin/GitVersionCheckCJM.pm
lib/Dist/Zilla/Plugin/ModuleBuild/Custom.pm
@@ -21,6 +22,7 @@ lib/Dist/Zilla/Plugin/VersionFromModule.pm
lib/Dist/Zilla/Role/ModuleInfo.pm
t/00-compile.t
t/arcrel.t
+t/gitvercheck.t
t/mb_custom.t
t/release-pod-coverage.t
t/release-pod-syntax.t
View
2 MANIFEST.SKIP
@@ -1,6 +1,4 @@
\bRCS\b
-.git\b
-.svn\b
~$
\$$
\.cmd$
View
339 corpus/gitvercheck.git
@@ -0,0 +1,339 @@
+blob
+mark :1
+data 468
+{{$dist}} version {{$version}}, released {{$date}}
+
+
+Blah blah blah.
+
+
+
+INSTALLATION
+
+To install these modules, run the following commands:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+
+
+DEPENDENCIES
+
+{{ $t->dependency_list }}
+
+
+
+CHANGES
+ Here's what's new in version {{$version}} of {{$dist}}:
+ (See the file "Changes" for the full revision history.)
+
+{{$changes}}
+
+
+
+COPYRIGHT AND LICENSE
+
+{{ local $_ = $zilla->license->notice; chomp; $_ }}
+
+blob
+mark :2
+data 178
+name = DZT-Sample
+author = E. Xavier Ample <example@example.org>
+license = Perl_5
+copyright_holder = E. Xavier Ample
+
+[GatherDir]
+[VersionFromModule]
+[GitVersionCheckCJM]
+
+blob
+mark :3
+data 98
+package DZT::First;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.01';
+
+blob
+mark :4
+data 456
+package DZT::Sample;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.01';
+# This file is part of {{$dist}} {{$dist_version}} ({{$date}})
+
+=attr bogus
+
+Don't have this.
+
+=method return_arrayref_of_values_passed
+
+blah
+
+=cut
+
+sub return_arrayref_of_values_passed {
+ my $invocant = shift;
+ return \@_;
+}
+
+1;
+
+=head1 DEPENDENCIES
+
+DZT::Sample requires {{$t->dependency_link('Bloofle')}} and
+{{$t->dependency_link('Foo::Bar')}}.
+
+=cut
+
+blob
+mark :5
+data 228
+use strict;
+use warnings;
+
+use Test::More 0.88;
+use DZT::Sample;
+
+is_deeply(
+ DZT::Sample->return_arrayref_of_values_passed(1, [ 2 ], { 3 => 4 }),
+ [ 1, [ 2 ], { 3 => 4 } ],
+ "we do what we say on the tin",
+);
+
+done_testing;
+
+reset refs/tags/0.01
+commit refs/tags/0.01
+mark :6
+author E. Xavier Ample <example@example.org> 1289243198 -0600
+committer E. Xavier Ample <example@example.org> 1289243198 -0600
+data 13
+Version 0.01
+M 100644 :1 README
+M 100644 :2 dist.ini
+M 100644 :3 lib/DZT/First.pm
+M 100644 :4 lib/DZT/Sample.pm
+M 100644 :5 t/basic.t
+
+blob
+mark :7
+data 456
+package DZT::Sample;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.02';
+# This file is part of {{$dist}} {{$dist_version}} ({{$date}})
+
+=attr bogus
+
+Don't have this.
+
+=method return_arrayref_of_values_passed
+
+blah
+
+=cut
+
+sub return_arrayref_of_values_passed {
+ my $invocant = shift;
+ return \@_;
+}
+
+1;
+
+=head1 DEPENDENCIES
+
+DZT::Sample requires {{$t->dependency_link('Bloofle')}} and
+{{$t->dependency_link('Foo::Bar')}}.
+
+=cut
+
+blob
+mark :8
+data 107
+package DZT::Sample::Second;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.02';
+
+commit refs/tags/0.02
+mark :9
+author E. Xavier Ample <example@example.org> 1289243358 -0600
+committer E. Xavier Ample <example@example.org> 1289243358 -0600
+data 13
+Version 0.02
+from :6
+M 100644 :7 lib/DZT/Sample.pm
+M 100644 :8 lib/DZT/Sample/Second.pm
+
+blob
+mark :10
+data 120
+package DZT::First;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.03';
+
+# added in version 3
+
+blob
+mark :11
+data 456
+package DZT::Sample;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.03';
+# This file is part of {{$dist}} {{$dist_version}} ({{$date}})
+
+=attr bogus
+
+Don't have this.
+
+=method return_arrayref_of_values_passed
+
+blah
+
+=cut
+
+sub return_arrayref_of_values_passed {
+ my $invocant = shift;
+ return \@_;
+}
+
+1;
+
+=head1 DEPENDENCIES
+
+DZT::Sample requires {{$t->dependency_link('Bloofle')}} and
+{{$t->dependency_link('Foo::Bar')}}.
+
+=cut
+
+commit refs/tags/0.03
+mark :12
+author E. Xavier Ample <example@example.org> 1289243521 -0600
+committer E. Xavier Ample <example@example.org> 1289243521 -0600
+data 22
+Starting version 0.03
+from :9
+M 100644 :10 lib/DZT/First.pm
+M 100644 :11 lib/DZT/Sample.pm
+
+blob
+mark :13
+data 107
+package DZT::Sample::Second;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.03';
+
+commit refs/tags/0.03
+mark :14
+author E. Xavier Ample <example@example.org> 1289243545 -0600
+committer E. Xavier Ample <example@example.org> 1289243545 -0600
+data 22
+Finished version 0.03
+from :12
+M 100644 :13 lib/DZT/Sample/Second.pm
+
+blob
+mark :15
+data 456
+package DZT::Sample;
+# ABSTRACT: Sample DZ Dist
+
+use strict;
+use warnings;
+
+our $VERSION = '0.04';
+# This file is part of {{$dist}} {{$dist_version}} ({{$date}})
+
+=attr bogus
+
+Don't have this.
+
+=method return_arrayref_of_values_passed
+
+blah
+
+=cut
+
+sub return_arrayref_of_values_passed {
+ my $invocant = shift;
+ return \@_;
+}
+
+1;
+
+=head1 DEPENDENCIES
+
+DZT::Sample requires {{$t->dependency_link('Bloofle')}} and
+{{$t->dependency_link('Foo::Bar')}}.
+
+=cut
+
+commit refs/heads/master
+mark :16
+author E. Xavier Ample <example@example.org> 1289243648 -0600
+committer E. Xavier Ample <example@example.org> 1289243648 -0600
+data 13
+Version 0.04
+from :14
+M 100644 :15 lib/DZT/Sample.pm
+
+reset refs/heads/master
+from :16
+
+reset refs/tags/0.04
+from :16
+
+tag 0.04
+from :16
+tagger E. Xavier Ample <example@example.org> 1289243653 -0600
+data 14
+Tagging v0.04
+
+tag 0.03
+from :14
+tagger E. Xavier Ample <example@example.org> 1289243598 -0600
+data 14
+Tagging v0.03
+
+tag 0.02
+from :9
+tagger E. Xavier Ample <example@example.org> 1289243370 -0600
+data 14
+Tagging v0.02
+
+tag 0.01
+from :6
+tagger E. Xavier Ample <example@example.org> 1289243224 -0600
+data 14
+Tagging v0.01
+
View
6 dist.ini
@@ -21,7 +21,7 @@ CPAN::Meta::Converter = 2.101550 ; improved downconversion
Dist::Zilla = 3 ; META 2 changes
File::Copy = 0
File::HomeDir = 0.81
-File::Temp = 0
+File::Temp = 0.19 ; newdir
List::Util = 0
Module::Build::ModuleInfo = 0.28
Moose = 0.65 ; attr fulfills requires
@@ -33,3 +33,7 @@ version = 0.77 ; new API
[Prereqs / TestRequires]
Test::More = 0.88 ; done_testing
+File::pushd = 0
+
+[Prereqs / TestRecommends]
+Test::Fatal = 0
View
205 t/gitvercheck.t
@@ -0,0 +1,205 @@
+#! /usr/bin/perl
+#---------------------------------------------------------------------
+
+use strict;
+use warnings;
+use autodie ':io';
+
+use Test::More;
+
+BEGIN {
+ eval "use Git::Wrapper; 1"
+ or plan skip_all => "Git::Wrapper required for testing GitVersionCheckCJM";
+
+ eval "use Test::Fatal; 1"
+ or plan skip_all => "Test::Fatal required for testing GitVersionCheckCJM";
+}
+
+plan tests => 18;
+
+use Dist::Zilla::Tester 'Builder';
+use File::pushd 'pushd';
+use File::Temp ();
+use Path::Class qw(dir file);
+
+my $stoppedRE = qr/Stopped because of errors/;
+
+#---------------------------------------------------------------------
+# Initialise Git working copy:
+
+my $tempdir = File::Temp->newdir;
+my $gitRoot = dir("$tempdir")->absolute;
+my $gitHistory = file("corpus/gitvercheck.git")->absolute;
+
+{
+ my $wd = pushd($gitRoot);
+ system "git init --quiet" and die "Couldn't init";
+ system "git fast-import --quiet <\"$gitHistory\"" and die "Couldn't import";
+}
+
+my $git = Git::Wrapper->new("$gitRoot");
+
+$git->config('user.email', 'example@example.org');
+$git->config('user.name', 'E. Xavier Ample');
+$git->checkout(qw(--force --quiet master));
+
+#---------------------------------------------------------------------
+sub edit
+{
+ my ($file, $edit) = @_;
+
+ my $fn = $gitRoot->subdir("lib/DZT")->file("$file.pm");
+
+ local $_ = do {
+ local $/;
+ open my $fh, '<:raw', $fn;
+ <$fh>;
+ };
+
+ $edit->();
+
+ open my $fh, '>:raw', $fn;
+ print $fh $_;
+ close $fh;
+} # end edit
+
+#---------------------------------------------------------------------
+sub set_version
+{
+ my $version = shift;
+
+ foreach my $file (@_) {
+ edit($file, sub { s/(\$VERSION\s*=)\s*'[^']*'/$1 '$version'/ or die });
+ }
+} # end set_version
+
+#---------------------------------------------------------------------
+sub new_tzil
+{
+ my $tzil = Builder->from_config(
+ { dist_root => $gitRoot },
+ );
+
+ # Something about the copy dzil makes seems to confuse git into
+ # thinking files are modified when they aren't.
+ # Run "git status" in the source directory to unconfuse it:
+ Git::Wrapper->new( $tzil->tempdir->subdir("source") )->status;
+
+ $tzil;
+} # end new_tzil
+
+#------------------------------------------------------n---------------
+# Extract the errors reported by GitVersionCheckCJM:
+
+sub errors
+{
+ my ($tzil) = @_;
+
+ my @messages = grep { s/^.*GitVersionCheckCJM.*ERROR:\s*// }
+ @{ $tzil->log_messages };
+ my %error;
+
+ for (@messages) {
+ s!\s*lib/DZT/(\S+)\.pm\b:?\s*!! or die "Can't find filename in $_";
+ $error{$1} = $_;
+ }
+
+ #use YAML::XS; print Dump $tzil->log_events;
+
+ return \%error;
+} # end errors
+
+#---------------------------------------------------------------------
+{
+ my $tzil = new_tzil;
+ is(exception { $tzil->build }, undef, "build 0.04");
+ is_deeply(errors($tzil), {}, "no errors in 0.04");
+# print "$_\n" for @{ $tzil->log_messages };
+# print $tzil->tempdir,"\n"; my $wait = <STDIN>;
+}
+
+{
+ set_version('0.04', 'Sample/Second');
+
+ my $tzil = new_tzil;
+ like(exception { $tzil->build }, $stoppedRE, "can't build modified 0.04");
+
+ is_deeply(errors($tzil),
+ { 'Sample/Second' => 'dist version 0.04 needs to be updated' },
+ "errors in modified 0.04");
+}
+
+{
+ set_version('0.05', 'Sample');
+
+ my $tzil = new_tzil;
+ like(exception { $tzil->build }, $stoppedRE, "can't build 0.05 yet");
+
+ is_deeply(errors($tzil),
+ { 'Sample/Second' => '0.04 needs to be updated' },
+ "errors in 0.05");
+}
+
+{
+ set_version('0.05', 'Sample/Second');
+
+ my $tzil = new_tzil;
+ is(exception { $tzil->build }, undef, "can build 0.05 now");
+ is_deeply(errors($tzil), {}, "no errors in 0.05 now");
+}
+
+#---------------------------------------------------------------------
+$git->reset(qw(--hard --quiet)); # Restore to checked-in state
+
+{
+ set_version('0.045', 'First');
+
+ my $tzil = new_tzil;
+ like(exception { $tzil->build }, $stoppedRE, "can't build with 0.045");
+ is_deeply(errors($tzil), { First => '0.045 exceeds dist version 0.04' },
+ "errors with 0.045");
+}
+
+{
+ set_version('0.05', 'Sample');
+
+ my $tzil = new_tzil;
+ like(exception { $tzil->build }, $stoppedRE, "can't build 0.05 with 0.045");
+ is_deeply(errors($tzil), {
+ First => '0.045 needs to be updated',
+ }, "errors in 0.05 with 0.045");
+}
+
+{
+ $git->add('lib/DZT/First.pm');
+ $git->commit(-m => 'checking in DZT::First 0.045');
+
+ my $tzil = new_tzil;
+ like(exception { $tzil->build }, $stoppedRE,
+ "can't build 0.05 with 0.045 committed");
+ is_deeply(errors($tzil), {
+ First => '0.045 does not seem to have been released, but is not current',
+ }, "errors in 0.05 with 0.045 committed");
+}
+
+{
+ set_version('0.05', 'First');
+
+ my $tzil = new_tzil;
+ is(exception { $tzil->build }, undef, "can build with First 0.05");
+ is_deeply(errors($tzil), {}, "no errors with First 0.05");
+}
+
+{
+ edit('First', sub { s/^.*VERSION.*\n//m or die });
+
+ my $tzil = new_tzil;
+ like(exception { $tzil->build }, qr/ERROR: Can't find version/,
+ "can't build with First unversioned");
+ is_deeply(errors($tzil), { First => "Can't find version in" },
+ "errors with First unversioned");
+}
+
+undef $tempdir; # Clean up temporary directory
+
+done_testing;

0 comments on commit c7046ca

Please sign in to comment.