http://www.perlmonks.org?node_id=701540

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: