Skip to content

Commit

Permalink
Merge pull request #2 from doy/master
Browse files Browse the repository at this point in the history
make dzil test with the appropriate options run xt tests
  • Loading branch information
xdg committed May 11, 2012
2 parents 7f70512 + 2a2ab32 commit 3e67e0e
Show file tree
Hide file tree
Showing 17 changed files with 431 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Changes
Expand Up @@ -2,6 +2,11 @@ Revision history for Dist-Zilla-Plugin-CheckExtraTests

{{$NEXT}}

- run tests on the built dist, so that things like XS will work

- add RunExtraTests plugin, which runs the appropriate xt tests when "dzil
test" is run (but only with the appropriate flags).

0.005 2012-05-03 17:30:08 America/New_York

- add 'xt' as command alias for 'xtest'
Expand Down
6 changes: 6 additions & 0 deletions corpus/RunXT/Changes
@@ -0,0 +1,6 @@
Changes

1.23 2009-11-16 19:15:45 CET
- foo
- bar
- baz
59 changes: 59 additions & 0 deletions corpus/RunXT/Makefile.PL
@@ -0,0 +1,59 @@

use strict;
use warnings;



use ExtUtils::MakeMaker 6.30;

{
my $contents = do {
open my $fh, '<', 'lib/Foo.pm' || die "Couldn't open lib/Foo.pm: $!";
local $/;
<$fh>;
};
$contents =~ s/123/456/;
open my $fh, '>', 'lib/Foo.pm' || die "Couldn't open lib/Foo.pm: $!";
print $fh $contents;
}


my %WriteMakefileArgs = (
"ABSTRACT" => "Test Library",
"AUTHOR" => "foobar",
"BUILD_REQUIRES" => {},
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "6.30"
},
"DISTNAME" => "Foo",
"EXE_FILES" => [],
"LICENSE" => "perl",
"NAME" => "Foo",
"PREREQ_PM" => {},
"VERSION" => "1.23",
"test" => {
"TESTS" => ""
}
);


unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
my $pp = $WriteMakefileArgs{PREREQ_PM};
for my $mod ( keys %$br ) {
if ( exists $pp->{$mod} ) {
$pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod};
}
else {
$pp->{$mod} = $br->{$mod};
}
}
}

delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };

WriteMakefile(%WriteMakefileArgs);



24 changes: 24 additions & 0 deletions corpus/RunXT/dist.ini
@@ -0,0 +1,24 @@
name = Foo
version = 1.23
author = foobar
license = Perl_5
abstract = Test Library
copyright_holder = foobar
copyright_year = 2009

[@Filter]
bundle = @FakeClassic
remove = ExtraTests
remove = PodVersion
remove = PodSyntaxTests
remove = PodCoverageTests
remove = ConfirmRelease
remove = UploadToCPAN
remove = MakeMaker

[MakeMaker::Runner]

[CheckExtraTests]
[RunExtraTests]

[FakeRelease]
1 change: 1 addition & 0 deletions corpus/RunXT/foobar
@@ -0,0 +1 @@
this file is meant for testing...
14 changes: 14 additions & 0 deletions corpus/RunXT/lib/Foo.pm
@@ -0,0 +1,14 @@
package Foo;
use strict;
use warnings;
# ABSTRACT: Foo this thing

sub foo { 123 }

1;

=head1 DESCRIPTION
Foo the foo.
=cut
8 changes: 8 additions & 0 deletions corpus/RunXT/t/foo.t
@@ -0,0 +1,8 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

pass("success");

done_testing;
6 changes: 6 additions & 0 deletions corpus/WithBlib/Changes
@@ -0,0 +1,6 @@
Changes

1.23 2009-11-16 19:15:45 CET
- foo
- bar
- baz
59 changes: 59 additions & 0 deletions corpus/WithBlib/Makefile.PL
@@ -0,0 +1,59 @@

use strict;
use warnings;



use ExtUtils::MakeMaker 6.30;

{
my $contents = do {
open my $fh, '<', 'lib/Foo.pm' || die "Couldn't open lib/Foo.pm: $!";
local $/;
<$fh>;
};
$contents =~ s/123/456/;
open my $fh, '>', 'lib/Foo.pm' || die "Couldn't open lib/Foo.pm: $!";
print $fh $contents;
}


my %WriteMakefileArgs = (
"ABSTRACT" => "Test Library",
"AUTHOR" => "foobar",
"BUILD_REQUIRES" => {},
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "6.30"
},
"DISTNAME" => "Foo",
"EXE_FILES" => [],
"LICENSE" => "perl",
"NAME" => "Foo",
"PREREQ_PM" => {},
"VERSION" => "1.23",
"test" => {
"TESTS" => ""
}
);


unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
my $pp = $WriteMakefileArgs{PREREQ_PM};
for my $mod ( keys %$br ) {
if ( exists $pp->{$mod} ) {
$pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod};
}
else {
$pp->{$mod} = $br->{$mod};
}
}
}

delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };

WriteMakefile(%WriteMakefileArgs);



23 changes: 23 additions & 0 deletions corpus/WithBlib/dist.ini
@@ -0,0 +1,23 @@
name = Foo
version = 1.23
author = foobar
license = Perl_5
abstract = Test Library
copyright_holder = foobar
copyright_year = 2009

[@Filter]
bundle = @FakeClassic
remove = ExtraTests
remove = PodVersion
remove = PodSyntaxTests
remove = PodCoverageTests
remove = ConfirmRelease
remove = UploadToCPAN
remove = MakeMaker

[MakeMaker::Runner]

[CheckExtraTests]

[FakeRelease]
1 change: 1 addition & 0 deletions corpus/WithBlib/foobar
@@ -0,0 +1 @@
this file is meant for testing...
14 changes: 14 additions & 0 deletions corpus/WithBlib/lib/Foo.pm
@@ -0,0 +1,14 @@
package Foo;
use strict;
use warnings;
# ABSTRACT: Foo this thing

sub foo { 123 }

1;

=head1 DESCRIPTION
Foo the foo.
=cut
8 changes: 6 additions & 2 deletions lib/Dist/Zilla/App/Command/xtest.pm
Expand Up @@ -72,22 +72,26 @@ sub execute {

my $wd = File::pushd::pushd( $target );

my @builders = @{ $self->zilla->plugins_with(-BuildRunner) };
die "no BuildRunner plugins specified" unless @builders;
$builders[0]->build;

my $error;

my $app = App::Prove->new;
if ( ref $arg eq 'ARRAY' && @$arg ) {
my $pcr = Path::Class::Rule->new->file->name(@$arg);
my @t = map { "$_" } $pcr->all( 'xt' );
if ( @t ) {
$app->process_args(qw/-r -l/, @t) if @t;
$app->process_args(qw/-r -b/, @t) if @t;
$error = "Failed xt tests" unless $app->run;
}
else {
$self->log("no xt files found matching: @$arg");
}
}
else {
$app->process_args(qw/-r -l xt/);
$app->process_args(qw/-r -b xt/);
$error = "Failed xt tests" unless $app->run;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/Dist/Zilla/Plugin/CheckExtraTests.pm
Expand Up @@ -25,10 +25,15 @@ sub before_release {
# chdir in
my $wd = File::pushd::pushd($self->zilla->built_in);

# make
my @builders = @{ $self->zilla->plugins_with(-BuildRunner) };
die "no BuildRunner plugins specified" unless @builders;
$builders[0]->build;

# prove xt
local $ENV{RELEASE_TESTING} = 1;
my $app = App::Prove->new;
$app->process_args(qw/-r -l xt/);
$app->process_args(qw/-r -b xt/);
$app->run or $self->log_fatal("Fatal errors in xt tests");
return;
}
Expand Down
70 changes: 70 additions & 0 deletions lib/Dist/Zilla/Plugin/RunExtraTests.pm
@@ -0,0 +1,70 @@
use strict;
use warnings;
package Dist::Zilla::Plugin::RunExtraTests;
# ABSTRACT: support running xt tests via dzil test
# VERSION

# Dependencies
use Dist::Zilla 2.100950 (); # XXX really the next release after this date
use App::Prove 3.00 ();
use Moose 0.99;
use namespace::autoclean 0.09;

# extends, roles, attributes, etc.

with 'Dist::Zilla::Role::TestRunner';

# methods

sub test {
my $self = shift;

my @dirs;
push @dirs, 'xt/release' if $ENV{RELEASE_TESTING};
push @dirs, 'xt/author' if $ENV{AUTHOR_TESTING};
push @dirs, 'xt/smoke' if $ENV{AUTOMATED_TESTING};
@dirs = grep { -d } @dirs;
return unless @dirs;

my @builders = @{ $self->zilla->plugins_with(-BuildRunner) };
die "no BuildRunner plugins specified" unless @builders;
$builders[0]->build;

my $app = App::Prove->new;
$app->process_args(qw/-r -b/, @dirs);
$app->run or $self->log_fatal("Fatal errors in xt tests");
return;
}

__PACKAGE__->meta->make_immutable;

1;

__END__
=for Pod::Coverage::TrustPod
test
=begin wikidoc
= SYNOPSIS
In your dist.ini:
[RunExtraTests]
= DESCRIPTION
Runs xt tests when C<dzil test> is run. C<xt/release>, C<xt/author>, and
C<xt/smoke> will be tested based on the values of the appropriate environment
variables (C<RELEASE_TESTING>, C<AUTHOR_TESTING>, and C<AUTOMATED_TESTING>),
which are set by C<dzil test>.
= SEE ALSO
* [Dist::Zilla]
=end wikidoc
=cut

0 comments on commit 3e67e0e

Please sign in to comment.