Re: [Module::Build] proposed patch for "testauthor" action
Status: Beta
Brought to you by:
kwilliams
|
From: Chris D. <ch...@cl...> - 2006-02-05 03:30:49
|
I'm very happy with this patch. I believe that someone (Ken?) raised
the objection that envvars were troublesome on some platforms. I'm
curious to learn more about that objection. Nonetheless, I posit
that author tests are a fringe feature and, at the risk of being
platformist, I think it's OK if it doesn't work absolutely
everywhere. And given that other test actions have set a precedent,
I think we're OK with this approach.
Chris
On Feb 4, 2006, at 4:06 PM, David Golden wrote:
> Following the notion that actions speak louder than words, I offer
> the attached patch against the current CVS head. (Including test
> file and documentation.)
>
> It provides a "testauthor" action that sets $ENV{AUTHOR_TESTING} to
> 1 before running the "test" action.
>
> The name of the action follows the pattern set by "testdb",
> "testpod", "testcover", etc. The environment variable follows the
> pattern of "AUTOMATED_TESTING" used by the CPAN smoke tests.
>
> The functionality itself took less than 60 seconds to write. The
> longest part was figuring out how to write a test for it. (0.29
> wishlist: more test refactoring.)
>
> Regards,
> David
> === t/testauthor.t
> ==================================================================
> --- t/testauthor.t (revision 3287)
> +++ t/testauthor.t (patch author_testing level 1)
> @@ -0,0 +1,67 @@
> +#!/usr/bin/perl -w
> +
> +use strict;
> +use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
> +use MBTest tests => 7;
> +
> +use Cwd ();
> +my $cwd = Cwd::cwd;
> +my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' );
> +
> +use DistGen;
> +
> +#########################
> +
> +use DistGen;
> +my $dist = DistGen->new( dir => $tmp );
> +$dist->change_file( 't/basic.t', <<'---');
> +use Test::More;
> +plan tests => 1;
> +is( $ENV{AUTHOR_TESTING}, '1', '$ENV{AUTHOR_TESTING} set');
> +---
> +
> +$dist->regen;
> +
> +chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist-
> >dirname]}': $!";
> +
> +#########################
> +
> +use Module::Build;
> +ok(1);
> +
> +SKIP: {
> + skip "no blib in core", 1 if $ENV{PERL_CORE};
> + like $INC{'Module/Build.pm'}, qr/\bblib\b/, "Make sure version
> from blib/ is loaded";
> +}
> +
> +#########################
> +
> +my $mb = Module::Build->new_from_context;
> +ok $mb;
> +
> +eval {$mb->create_build_script};
> +is $@, '';
> +ok -e $mb->build_script;
> +
> +{
> + # Make sure verbose=>1 works
> + my $all_ok = 1;
> + my $output = eval {
> + stdout_of( sub { $mb->dispatch('testauthor', verbose => 1) } )
> + };
> + $all_ok &&= is($@, '');
> + $all_ok &&= like($output, qr/all tests successful/i);
> +
> + unless ($all_ok) {
> + # We use diag() so Test::Harness doesn't get confused.
> + diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output
> vvvvvvvvvvvvvvvvvvvvv");
> + diag($output);
> + diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output
> ^^^^^^^^^^^^^^^^^^^^^");
> + }
> +}
> +
> +# cleanup
> +$dist->remove;
> +
> +use File::Path;
> +rmtree( $tmp );
>
> === lib/Module/Build/Base.pm
> ==================================================================
> --- lib/Module/Build/Base.pm (revision 3287)
> +++ lib/Module/Build/Base.pm (patch author_testing level 1)
> @@ -1882,6 +1882,14 @@
> $self->depends_on('test');
> }
>
> +sub ACTION_testauthor {
> + my ($self) = @_;
> +
> + local $ENV{AUTHOR_TESTING} = 1;
> +
> + $self->depends_on('test');
> +}
> +
> sub ACTION_testcover {
> my ($self) = @_;
>
> === lib/Module/Build.pm
> ==================================================================
> --- lib/Module/Build.pm (revision 3287)
> +++ lib/Module/Build.pm (patch author_testing level 1)
> @@ -490,6 +490,19 @@
>
> ./Build test --test_files 't/01-*.t'
>
> +=item testauthor
> +
> +This is a synonym for the C<test> action with the environment
> variable
> +C<AUTHOR_TESTING> set to 1. Test files that are only of interest
> to module
> +authors during development choose to skip running if the
> environment variable
> +is not set. E.g.
> +
> + use Test::More;
> + plan skip_all "Author test" if not $ENV{AUTHOR_TESTING};
> +
> + plan tests => 42;
> + # test file continues
> +
> =item testcover
>
> Runs the C<test> action using C<Devel::Cover>, generating a
--
Chris Dolan, Software Developer, Clotho Advanced Media Inc.
608-294-7900, fax 294-7025, 1435 E Main St, Madison WI 53703
vCard: http://www.chrisdolan.net/ChrisDolan.vcf
Clotho Advanced Media, Inc. - Creators of MediaLandscape Software
(http://www.media-landscape.com/) and partners in the revolutionary
Croquet project (http://www.opencroquet.org/)
|