Permalink
Browse files

revise testing framework; allow requirements toggling

  • Loading branch information...
1 parent 15918a1 commit 29ba7c21f25bce14447f8920161deb93e6fb4bbb @xdg xdg committed Aug 8, 2012
View
0 corpus/DZ_noMeta/lib/Foo.pm → corpus/DZ/lib/Foo.pm
File renamed without changes.
View
27 corpus/DZ_allMeta/dist.ini
@@ -1,27 +0,0 @@
-name = Foo
-version = 1.23
-author = foobar
-license = Perl_5
-abstract = Test Library
-copyright_holder = foobar
-copyright_year = 2009
-
-[@Filter]
-bundle = @Basic
-remove = ExtraTests
-remove = TestRelease
-remove = ConfirmRelease
-remove = UploadToCPAN
-
-[MetaResources]
-bugtracker.web = https://rt.cpan.org/Public/Dist/Display.html?Name=Foo
-repository.url = git://github.com/zzz/p5-foo.git
-repository.web = http://github.com/zzz/p5-foo
-repository.type = git
-homepage = http://foo.example.com
-
-[CheckMetaResources]
-; XXXREPLACEXXX
-
-[FakeRelease]
-
View
12 corpus/DZ_allMeta/lib/Foo.pm
@@ -1,12 +0,0 @@
-package Foo;
-use strict;
-use warnings;
-# ABSTRACT: Foo this thing
-
-1;
-
-=head1 DESCRIPTION
-
-Foo the foo.
-
-=cut
View
27 corpus/DZ_noHome/dist.ini
@@ -1,27 +0,0 @@
-name = Foo
-version = 1.23
-author = foobar
-license = Perl_5
-abstract = Test Library
-copyright_holder = foobar
-copyright_year = 2009
-
-[@Filter]
-bundle = @Basic
-remove = ExtraTests
-remove = TestRelease
-remove = ConfirmRelease
-remove = UploadToCPAN
-
-[MetaResources]
-bugtracker.web = https://rt.cpan.org/Public/Dist/Display.html?Name=Foo
-repository.url = git://github.com/zzz/p5-foo.git
-repository.web = http://github.com/zzz/p5-foo
-repository.type = git
-homepage = http://foo.example.com
-
-[CheckMetaResources]
-; XXXREPLACEXXX
-
-[FakeRelease]
-
View
12 corpus/DZ_noHome/lib/Foo.pm
@@ -1,12 +0,0 @@
-package Foo;
-use strict;
-use warnings;
-# ABSTRACT: Foo this thing
-
-1;
-
-=head1 DESCRIPTION
-
-Foo the foo.
-
-=cut
View
20 corpus/DZ_noMeta/dist.ini
@@ -1,20 +0,0 @@
-name = Foo
-version = 1.23
-author = foobar
-license = Perl_5
-abstract = Test Library
-copyright_holder = foobar
-copyright_year = 2009
-
-[@Filter]
-bundle = @Basic
-remove = ExtraTests
-remove = TestRelease
-remove = ConfirmRelease
-remove = UploadToCPAN
-
-[CheckMetaResources]
-; XXXREPLACEXXX
-
-[FakeRelease]
-
View
23 lib/Dist/Zilla/Plugin/CheckMetaResources.pm
@@ -3,7 +3,7 @@ use strict;
use warnings;
package Dist::Zilla::Plugin::CheckMetaResources;
-# ABSTRACT: No abstract given for Dist::Zilla::Plugin::CheckMetaResources
+# ABSTRACT: Ensure META includes resources
# VERSION
# Dependencies
@@ -16,21 +16,36 @@ use namespace::autoclean 0.09;
# extends, roles, attributes, etc.
+has [qw/repository bugtracker/] => (
+ is => 'ro',
+ isa => 'Bool',
+ default => 1,
+);
+
+has homepage => (
+ is => 'ro',
+ isa => 'Bool',
+ default => 0,
+);
+
with 'Dist::Zilla::Role::BeforeRelease';
# methods
sub before_release {
my $self = shift;
- my $distmeta = $self->zilla->distmeta;
+ my $dm = $self->zilla->distmeta;
$self->log("Checking META resources");
- if ( ref $distmeta->{resources} eq 'HASH' ) {
+ my @keys = qw/repository bugtracker homepage/;
+ my @errors = grep { $self->$_ && ! exists $dm->{resources}{$_} } @keys;
+
+ if ( ! @errors ) {
$self->log("META resources OK");
}
else {
- $self->log_fatal("META resources not specified");
+ $self->log_fatal("META resources not specified: @errors");
}
return;
View
129 t/checkmetaresources.t
@@ -6,52 +6,73 @@ use warnings;
use Capture::Tiny qw/capture/;
use Dist::Zilla::Tester;
use Test::More 0.88;
+use Path::Class 0.26;
use Try::Tiny;
-my $no_meta = 'corpus/DZ_noMeta';
-my $no_home = 'corpus/DZ_noHome';
-my $all_meta = 'corpus/DZ_allMeta';
+my $corpus = 'corpus/DZ';
## Tests start here
-#--------------------------------------------------------------------------#
-# default attributes
-#--------------------------------------------------------------------------#
+dzil_not_released("defaults: no resources");
-{
- my $label = "default attributes";
- dzil_not_released( $no_meta, $label );
- dzil_released( $all_meta, $label );
- dzil_released( $no_home, $label );
-}
+dzil_released(
+ "all resources provided; defaults required",
+ {
+ with => { map { $_ => 1 } qw/repository bugtracker homepage/ },
+ }
+);
+
+dzil_released(
+ "only repository and bugtracker provided; defaults required",
+ {
+ with => { map { $_ => 1 } qw/repository bugtracker/ },
+ }
+);
+
+dzil_not_released(
+ "only repository and bugtracker provided; homepage required",
+ {
+ with => { map { $_ => 1 } qw/repository bugtracker/ },
+ check => { homepage => 1 },
+ }
+);
+
+dzil_released(
+ "only repository provided; bugtracker not required",
+ {
+ with => { repository => 1 },
+ check => { bugtracker => 0 },
+ }
+);
#--------------------------------------------------------------------------#
# fixture subs
#--------------------------------------------------------------------------#
-sub dzil_released { _dzil_test(1, @_) }
-sub dzil_not_released { _dzil_test(0, @_) }
+sub dzil_released { _dzil_test( 1, @_ ) }
+sub dzil_not_released { _dzil_test( 0, @_ ) }
sub _dzil_test {
- my ($should_release, $corpus, $label, $filter_sub) = @_;
+ my ( $should_release, $label, $args ) = @_;
- subtest "$label: $corpus" => sub {
+ subtest $label => sub {
my $tzil;
try {
$tzil = Dist::Zilla::Tester->from_config(
- { dist_root => $corpus},
+ { dist_root => $corpus },
+ { add_files => { 'source/dist.ini' => gen_dist_ini($args) } },
);
- ok( $tzil, "created test dist from $corpus" );
+ ok( $tzil, "created test dist" );
- $filter_sub->() if $filter_sub;
-
- capture { $tzil->release };
- } finally {
+## capture { $tzil->release };
+ $tzil->release;
+ }
+ finally {
my $err = shift || '';
- if ( $should_release ) {
- is ( $err, "", "did not see missing resources warning" );
+ if ($should_release) {
+ is( $err, "", "did not see missing resources warning" );
ok(
- grep({ /fake release happen/i } @{ $tzil->log_messages }),
+ grep( {/fake release happen/i} @{ $tzil->log_messages } ),
"FakeRelease happened",
);
}
@@ -62,12 +83,68 @@ sub _dzil_test {
"saw missing resources warning",
);
ok(
- ! grep({ /fake release happen/i } @{ $tzil->log_messages }),
+ !grep( {/fake release happen/i} @{ $tzil->log_messages } ),
"FakeRelease did not happen",
);
}
}
+ }
+}
+
+sub gen_dist_ini {
+ my ($args) = @_;
+ $args->{with} ||= {};
+ $args->{check} ||= {};
+
+ my $meta = {
+ bugtracker => <<'HERE',
+bugtracker.web = https://rt.cpan.org/Public/Dist/Display.html?Name=Foo
+HERE
+ repository => <<'HERE',
+repository.url = git://github.com/zzz/p5-foo.git
+repository.web = http://github.com/zzz/p5-foo
+repository.type = git
+HERE
+ homepage => <<'HERE',
+homepage = http://foo.example.com
+HERE
+ };
+
+ my $dist_ini = <<'HERE';
+name = Foo
+version = 1.23
+author = foobar
+license = Perl_5
+abstract = Test Library
+copyright_holder = foobar
+copyright_year = 2009
+
+[@Filter]
+bundle = @Basic
+remove = ExtraTests
+remove = TestRelease
+remove = ConfirmRelease
+remove = UploadToCPAN
+
+[FakeRelease]
+
+[CheckMetaResources]
+HERE
+
+ for my $k ( keys %{ $args->{check} } ) {
+ $dist_ini .= "$k = $args->{check}{$k}\n";
+ }
+
+ $dist_ini .= "\n";
+
+ if ( keys %{ $args->{with} } ) {
+ $dist_ini .= "[MetaResources]\n";
+ for my $k ( keys %{ $args->{with} } ) {
+ $dist_ini .= "$meta->{$k}";
+ }
}
+
+ return $dist_ini;
}
done_testing;

0 comments on commit 29ba7c2

Please sign in to comment.