Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to retain a CPAN module's unit tests and run them later.

by chrestomanci (Priest)
on Dec 10, 2011 at 21:41 UTC ( #942873=perlquestion: print w/ replies, xml ) Need Help??
chrestomanci has asked for the wisdom of the Perl Monks concerning the following question:

Greeting fellow scholars in the noble art of perl.

This is mostly a hypothetical question, rather than a problem I am facing now: When you install a perl module from CPAN the normal install process involves running a series of unit tests to make sure that the module is correct, and that it works correctly in your environment. If your environment lacks features needed for the module to run, then the tests should fail and CPAN will refuse to install it without force.

The problem is that those tests are only valid on the day they are run. People change their environment all the time. They upgrade their Linux distros, they add and remove hardware, they change their system software and libraries, they even upgrade perl, and then point it at libraries installed under an older version. CPAN module tests that ran OK in the past might not run any more.

Given this, is there a way to re-run the tests for modules that are already installed, to check against the possibility that some change since the install has broken them?

It would be nice if there was some configuration variable you could give CPAN to tell it to retain and install all the .t files that came with a module, and a command you could run to tell it to run all those tests. Is there such an option?

Comment on How to retain a CPAN module's unit tests and run them later.
Re: How to retain a CPAN module's unit tests and run them later.
by JavaFan (Canon) on Dec 10, 2011 at 22:04 UTC
    The "keep_source_where" configuration parameter mentioned in the manual isn't working for you?

    In that case, you could try setting "build_size" to a very high number -- but that will keep all intermediate build files.

Re: How to retain a CPAN module's unit tests and run them later.
by tobyink (Abbot) on Dec 11, 2011 at 00:01 UTC

    This does the trick. Usage notes at end.

    use 5.010; use autodie; use common::sense; use MooseX::Declare; BEGIN { $CPAN::Retest::AUTHORITY = 'cpan:TOBYINK'; $CPAN::Retest::VERSION = '0.001'; } class CPAN::Retest { use App::Prove qw//; use File::Basename qw/fileparse/; use File::pushd qw/pushd/; use File::Path qw/make_path/; use File::Spec qw//; use File::Temp qw//; use LWP::Simple qw/get/; use Module::Manifest qw//; use Object::AUTHORITY qw/AUTHORITY/; has author => (is => 'ro', isa => 'Str', required => 1); has release => (is => 'ro', isa => 'Str', required => 1); has manifest => (is => 'rw', isa => 'ArrayRef[Str]', lazy => 1, b +uilder => '_build_manifest'); has testdir => (is => 'ro', isa => 'File::Temp::Dir', lazy => 1, + builder => '_build_testdir'); has verbose => (is => 'ro'); method url_for ($file) { sprintf( 'http://api.metacpan.org/source/%s/%s/%s', uc $self->author, $self->release, $file ); } method test_files { grep { m{^t/} } @{ $self->manifest }; } method _build_manifest { my $fh = File::Temp->new; binmode( $fh, ":utf8"); print $fh get($self->url_for('MANIFEST')); close $fh; my $manifest = Module::Manifest->new; $manifest->open(manifest => $fh->filename); return [ $manifest->files ]; } method _build_testdir { my $testdir = File::Temp->newdir; foreach my $file ($self->test_files) { my $dest = File::Spec->catfile($testdir->dirname, $file); my (undef, $d, undef) = fileparse($dest); make_path($d); open my $fh, '>', $dest; print $fh get($self->url_for($file)); close $fh; } return $testdir; } method run { my $chdir = pushd($self->testdir->dirname); my $app = App::Prove->new; $app->process_args('t'); $app->verbose(1) if $self->verbose; $app->run; } }

    Usage:

    my $test = CPAN::Retest->new( author => 'TOBYINK', release => 'Object-AUTHORITY-0.003', verbose => 1, ); $test->run;

    Update:

    This is now available on CPAN: App-Reprove-0.001.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://942873]
Approved by keszler
Front-paged by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-08-22 10:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (153 votes), past polls