Skip to content

Commit

Permalink
revise testing framework; allow requirements toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Aug 8, 2012
1 parent 15918a1 commit 29ba7c2
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 128 deletions.
File renamed without changes.
27 changes: 0 additions & 27 deletions corpus/DZ_allMeta/dist.ini

This file was deleted.

27 changes: 0 additions & 27 deletions corpus/DZ_noHome/dist.ini

This file was deleted.

12 changes: 0 additions & 12 deletions corpus/DZ_noHome/lib/Foo.pm

This file was deleted.

20 changes: 0 additions & 20 deletions corpus/DZ_noMeta/dist.ini

This file was deleted.

12 changes: 0 additions & 12 deletions corpus/DZ_noMeta/lib/Foo.pm

This file was deleted.

23 changes: 19 additions & 4 deletions lib/Dist/Zilla/Plugin/CheckMetaResources.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings; use warnings;


package Dist::Zilla::Plugin::CheckMetaResources; package Dist::Zilla::Plugin::CheckMetaResources;
# ABSTRACT: No abstract given for Dist::Zilla::Plugin::CheckMetaResources # ABSTRACT: Ensure META includes resources
# VERSION # VERSION


# Dependencies # Dependencies
Expand All @@ -16,21 +16,36 @@ use namespace::autoclean 0.09;


# extends, roles, attributes, etc. # 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'; with 'Dist::Zilla::Role::BeforeRelease';


# methods # methods


sub before_release { sub before_release {
my $self = shift; my $self = shift;
my $distmeta = $self->zilla->distmeta; my $dm = $self->zilla->distmeta;


$self->log("Checking META resources"); $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"); $self->log("META resources OK");
} }
else { else {
$self->log_fatal("META resources not specified"); $self->log_fatal("META resources not specified: @errors");
} }


return; return;
Expand Down
129 changes: 103 additions & 26 deletions t/checkmetaresources.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,52 +6,73 @@ use warnings;
use Capture::Tiny qw/capture/; use Capture::Tiny qw/capture/;
use Dist::Zilla::Tester; use Dist::Zilla::Tester;
use Test::More 0.88; use Test::More 0.88;
use Path::Class 0.26;
use Try::Tiny; use Try::Tiny;


my $no_meta = 'corpus/DZ_noMeta'; my $corpus = 'corpus/DZ';
my $no_home = 'corpus/DZ_noHome';
my $all_meta = 'corpus/DZ_allMeta';


## Tests start here ## Tests start here


#--------------------------------------------------------------------------# dzil_not_released("defaults: no resources");
# default attributes
#--------------------------------------------------------------------------#


{ dzil_released(
my $label = "default attributes"; "all resources provided; defaults required",
dzil_not_released( $no_meta, $label ); {
dzil_released( $all_meta, $label ); with => { map { $_ => 1 } qw/repository bugtracker homepage/ },
dzil_released( $no_home, $label ); }
} );

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 # fixture subs
#--------------------------------------------------------------------------# #--------------------------------------------------------------------------#


sub dzil_released { _dzil_test(1, @_) } sub dzil_released { _dzil_test( 1, @_ ) }
sub dzil_not_released { _dzil_test(0, @_) } sub dzil_not_released { _dzil_test( 0, @_ ) }


sub _dzil_test { sub _dzil_test {
my ($should_release, $corpus, $label, $filter_sub) = @_; my ( $should_release, $label, $args ) = @_;


subtest "$label: $corpus" => sub { subtest $label => sub {
my $tzil; my $tzil;
try { try {
$tzil = Dist::Zilla::Tester->from_config( $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 };

$tzil->release;
capture { $tzil->release }; }
} finally { finally {
my $err = shift || ''; my $err = shift || '';
if ( $should_release ) { if ($should_release) {
is ( $err, "", "did not see missing resources warning" ); is( $err, "", "did not see missing resources warning" );
ok( ok(
grep({ /fake release happen/i } @{ $tzil->log_messages }), grep( {/fake release happen/i} @{ $tzil->log_messages } ),
"FakeRelease happened", "FakeRelease happened",
); );
} }
Expand All @@ -62,12 +83,68 @@ sub _dzil_test {
"saw missing resources warning", "saw missing resources warning",
); );
ok( ok(
! grep({ /fake release happen/i } @{ $tzil->log_messages }), !grep( {/fake release happen/i} @{ $tzil->log_messages } ),
"FakeRelease did not happen", "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; done_testing;

0 comments on commit 29ba7c2

Please sign in to comment.