Skip to content
Browse files

Merge pull request #2 from doy/master

make dzil test with the appropriate options run xt tests
  • Loading branch information...
2 parents 7f70512 + 2a2ab32 commit 3e67e0e7e4498275f12a42c968bfb1038c3c5b8f @xdg xdg committed May 10, 2012
View
5 Changes
@@ -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'
View
6 corpus/RunXT/Changes
@@ -0,0 +1,6 @@
+Changes
+
+1.23 2009-11-16 19:15:45 CET
+ - foo
+ - bar
+ - baz
View
59 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);
+
+
+
View
24 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]
View
1 corpus/RunXT/foobar
@@ -0,0 +1 @@
+this file is meant for testing...
View
14 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
View
8 corpus/RunXT/t/foo.t
@@ -0,0 +1,8 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+pass("success");
+
+done_testing;
View
6 corpus/WithBlib/Changes
@@ -0,0 +1,6 @@
+Changes
+
+1.23 2009-11-16 19:15:45 CET
+ - foo
+ - bar
+ - baz
View
59 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);
+
+
+
View
23 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]
View
1 corpus/WithBlib/foobar
@@ -0,0 +1 @@
+this file is meant for testing...
View
14 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
View
8 lib/Dist/Zilla/App/Command/xtest.pm
@@ -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;
}
View
7 lib/Dist/Zilla/Plugin/CheckExtraTests.pm
@@ -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;
}
View
70 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
+
View
82 t/runxt.t
@@ -0,0 +1,82 @@
+#!perl
+
+use strict;
+use warnings;
+use lib 't/lib';
+
+use Capture::Tiny qw/capture/;
+use Test::More 0.88;
+use Try::Tiny;
+
+use Test::Requires { 'Dist::Zilla::Tester' => 4.300017 };
+
+## XT FILE GUTS
+my $xt_fail = << 'HERE';
+use Test::More tests => 1;
+fail("doomed to fail");
+HERE
+
+local $ENV{RELEASE_TESTING};
+local $ENV{AUTHOR_TESTING};
+local $ENV{AUTOMATED_TESTING};
+
+{
+ my $tzil = Dist::Zilla::Tester->from_config(
+ { dist_root => 'corpus/RunXT' },
+ {
+ add_files => {
+ 'source/xt/author/checkme.t' => $xt_fail,
+ },
+ },
+ );
+ ok( $tzil, "created test dist");
+
+ capture { $tzil->test };
+
+ ok(
+ grep({ /all's well/i } @{ $tzil->log_messages }),
+ "xt tests aren't run without explicitly asking for them",
+ );
+}
+
+{
+ my $tzil = Dist::Zilla::Tester->from_config(
+ { dist_root => 'corpus/RunXT' },
+ {
+ add_files => {
+ 'source/xt/author/checkme.t' => $xt_fail,
+ },
+ },
+ );
+ ok( $tzil, "created test dist");
+
+ local $ENV{AUTHOR_TESTING} = 1;
+ try {
+ capture { $tzil->test };
+ }
+ catch {
+ my $err = $_;
+ like(
+ $err,
+ qr/Fatal errors in xt/i,
+ "RunExtraTests caught xt test failure",
+ );
+ }
+}
+
+{
+ my $tzil = Dist::Zilla::Tester->from_config(
+ { dist_root => 'corpus/RunXT' },
+ );
+ ok( $tzil, "created test dist");
+
+ local $ENV{AUTHOR_TESTING} = 1;
+ capture { $tzil->test };
+
+ ok(
+ grep({ /all's well/i } @{ $tzil->log_messages }),
+ "handles nonexistent test dirs",
+ );
+}
+
+done_testing;
View
47 t/withblib.t
@@ -0,0 +1,47 @@
+#!perl
+
+use strict;
+use warnings;
+use lib 't/lib';
+
+use Capture::Tiny qw/capture/;
+use Dist::Zilla::App::Tester;
+use Test::DZil;
+use Test::More 0.88;
+use Try::Tiny;
+
+## XT FILE GUTS
+my $xt_file = << 'HERE';
+use Test::More tests => 1;
+use Foo;
+is(Foo::foo(), 456);
+HERE
+
+## Tests start here
+
+{
+ my $tzil = Dist::Zilla::Tester->from_config(
+ { dist_root => 'corpus/WithBlib' },
+ {
+ add_files => {
+ 'source/xt/checkme.t' => $xt_file,
+ },
+ },
+ );
+ ok( $tzil, "created test dist that depends on the 'make' step");
+
+ capture { $tzil->release };
+
+ ok(
+ ! grep({ /Fatal errors in xt/i } @{ $tzil->log_messages }),
+ "No xt errors logged",
+ );
+ ok(
+ grep({ /fake release happen/i } @{ $tzil->log_messages }),
+ "FakeRelease executed",
+ );
+
+}
+
+done_testing;
+

0 comments on commit 3e67e0e

Please sign in to comment.
Something went wrong with that request. Please try again.