Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

tod222's scratchpad

by tod222 (Pilgrim)
on Jul 31, 2008 at 21:53 UTC ( #701540=scratchpad: print w/ replies, xml ) Need Help??

Mini-tip: Use a private extension to Module::Install to make tests_recursive follow symlinks

Module::Install's Module::Install::Makefile implements a nifty function called tests_recursive which you can put in your Makefile.PL to run all the tests in subdirectories under t.

While it uses File::Find's find function, tests_recursive doesn't allow you to set the follow option to have symbolic links be followed.

This can be accomplished with a private extension. The pod for Module::Install is a little unclear, so here's an example.

First, create the private extension file, in this case under 'ext'.

Contents of ext/Module/Install/PRIVATE.pm (this is basically a cut and paste from Module/Install/Makefile.pm with a trivial change):

package Module::Install::PRIVATE; use strict 'vars'; use Module::Install::Makefile; use vars qw{@ISA}; BEGIN { @ISA = qw{Module::Install::Makefile}; } my %test_dir = (); sub _wanted_t { /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1; } sub tests_recursive_follow_symlinks { my $self = shift; if ( $self->tests ) { die "tests_recursive will not work if tests are already define +d"; } my $dir = shift || 't'; unless ( -d $dir ) { die "tests_recursive dir '$dir' does not exist"; } require File::Find; %test_dir = (); # call to find modified to use 'follow' File::Find::find( { wanted => \&_wanted_t, follow => 1 }, $dir ); $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir ); } 1;

Second, edit Makefile.PL to add 'ext' to the @INC path so Module::Install finds it and to call the new function.

Contents of Makefile.PL (changes/additions commented):

use strict; use warnings; use lib 'ext'; # needed before using M::I use inc::Module::Install; name('MyMod'); all_from('lib/MyMod.pm'); build_requires('Test::More'); tests_recursive_follow_symlinks(); # change/add this line WriteAll();
Finally, add 'inc/Module/Install/PRIVATE.pm' to MANIFEST and you're good to go!

Caveat: Symlinks won't work across platforms! This modification is only useful for developer and other special tests that aren't going to run automatically when the package is installed. The files in the symlinked directories under t aren't listed in MANIFEST. For user's reference, they can be shipped in another location outside the t directory, thus the need for symlinks.

Some examples:

  • A test that precompiles a grammar for Parse::RecDescent.
  • Testing example scripts that require large data files and external programs that users are unlikely to have installed.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-08-20 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (108 votes), past polls