tall_man has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a project at work that involves a large C++ program which calls embedded perl and uses many perl modules in other directories. The boss required that the project be testable with a ExtUtils::MakeMaker "make test". He also required that I start with files generated by h2xs.

I have created a dummy module 'Xyz.pm' in the working directory, and forced MakeMaker to ignore everything else, like this:

use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Xyz', 'VERSION_FROM' => 'Xyz.pm', # finds $VERSION 'PREREQ_FATAL' => 1, # force prereq checks 'PREREQ_PM' => { 'DateTime' => '0', # X ? # # more prerequisites here, generated with /scandeps.pl }, # e.g., Module::Name => 1.1 'PREFIX' => '~/xyz_dummy', # shanghai install for now ); package MY; # Drastic fix for pulling the world into blib: eliminate all but Xyz.p +m sub libscan { my $self = shift; my $file = shift; return $file !~ /Xyz\.pm/ ? 0 : $self->SUPER::libscan($file); }
I put several test scripts (using Test::More) down into a "t/" directory, and now I can use the regular "perl Makefile.PL; make; make test" to do testing without disturbing the rest of the project.

Does anyone have suggestions on how I could improve this testing environment? Thanks.

Replies are listed 'Best First'.
Re: MakeMaker for testing only
by Courage (Parson) on Apr 16, 2003 at 09:52 UTC
    Looks like you achieved what you're planned to achieve and all is working.

    You probably need to throw away your "drastic fix" and just place files in "t" directory and probably "test.pl" script as "perldoc ExtUtils::MakeMaker" says:

    ..... make test MakeMaker checks for the existence of a file named test.pl in the current directory and if it exists it execute the script with the +proper set of perl "-I" options. MakeMaker also checks for any files matching glob("t/*.t"). It wil +l execute all matching files in alphabetical order via the Test::Har +ness module with the "-I" switches set correctly. If you'd like to see the raw output of your tests, set the "TEST_VERBOSE" variable to true. make test TEST_VERBOSE=1 ......
    Those files in "t" directory should just use your module and check for corectness of output.

    Also look at any CPAN module to see how they do this.

    Courage, the Cowardly Dog

Re: MakeMaker for testing only
by rinceWind (Monsignor) on Apr 16, 2003 at 11:17 UTC
    As Courage says, you can dispense with the libscan sub. In your release kit, you need to distinguish between the following uses of a .pm module:

    • Modules that must be there for your module to work. These are pre-requisites, and should be listed (with minimum version numbers if required) in PREREQ_PM, but not included in the kit.

    • Additional modules that work alongside the main .pm you are delivering, and you want to be installed with the module. Place these in an appropriate subdirectory of the lib directory (you may need to create a lib directory).

      For example, if we have a module My::Foo, which is the main module, but we also want to distribute My::Bar, you need the following paths

      Foo.pm lib/My/Bar.pm
    • Modules only needed for testing or installation, that are 'thrown away'. Put these in the top level directory as all tests are run with this as current working directory.

    Hope this helps

    rinceWind

    By the way, for a glimpse of the future, you might like to look at Module::Build, which Schwern and others are pushing for new modules, and I believe is going into the 5.10 core.

      I don't understand how I could dispense with the libscan sub. If I placed scripts, modules, cc files, and so on in the top-level directory (or in any subdirectory for that matter), won't they all be scanned by MakeMaker and get copied into blib when I do a make?

      I tried echoing out the file names that are passed to my fake libscan, and all the *.cc, *.h, *.pm files are included. Before I filtered out the ones I didn't want, they appeared in the sections C_FILES, H_FILES, PM_TO_BLIB, etc. of my Makefile.

      As I mentioned, this is a C++ main program with embedded perl, so I am not trying to install it like a perl module. I have my own installation scripts already. But perhaps there are ways to adapt the MakeMaker installation process to my needs. I'll look into it further.