in reply to How to specify tests dependencies with Makefile.PL?

The snippet you showed from your Makefile.PL suggests you're using ExtUtils::MakeMaker. EU::MM provides several hooks that enable you to specify module dependencies for different stages in your module's life.

If you have a dependency that has to be installed before Makefile.PL can run on the target system, you specify it as a CONFIGURE_REQUIRES option. An example of such a need is Math::Prime::FastSieve, where Inline::MakeMaker has to be installed on the target system, as well as a relatively recent version of EU::MM before the target system runs Makefile.PL.

By listing those types of dependencies in a CONFIGURE_REQUIRES parameter, the module author, upon building the distribution tells EU::MM to place a configure_requires section in META.yml and META.json. META.yml is used by the cpan shell (as well as the other common install tools) to determine the dependencies. The cpan shell will see that the CONFIGURE_REQUIRES dependency is there, and will install it before invoking Makefile.PL. CONFIGURE_REQUIRES doesn't affect the makefile, it affects what modules are available to Makefile.PL.

Ok, that's CONFIGURE_REQUIRES. That's not the stage you need to affect. I just mention it as an example. You need to have a dependency in place before the tests are run. There is no TEST_REQUIRES parameter. But there is a BUILD_REQUIRES, which will get the dependency installed in time for the build process. Technically your module is already built before it's tested, but that detail isn't as important.

Of course PREREQ_PM is the final opportunity to list dependencies, but that isn't what you need here, as that parameter is intended to get a module dependency installed, not a testing/building dependency.

My own experience in this area is partially documented in the thread that someone else already identified here: Clean smoke-test install for Inline based modules using Inline::MakeMaker

Just keep in mind the following:

  1. perl Makefile.PL: If you need something installed before this stage, and it's not needed by the module itself, use CONFIG_REQUIRES. This depends on a fairly recent version of EU::MM, so may want to also specify a minimum EU::MM version in your CONFIG_REQUIRES (else target systems will get some non-fatal warnings when the old EU::MM doesn't know what to do with this param -- not important but maybe confusing to users).
  2. make and make test: If you need something installed before this stage, but again it's not needed by the module itself, use BUILD_REQUIRES This also requires a fairly recent version of EU::MM, so if you use BUILD_REQUIRES, you may want to list a minimum version of EU::MM in a CONFIG_REQUIRES section (else the target user will get some non-fatal warnings upon running perl Makefile.PL -- again, not important but maybe confusing to users).
  3. make install: If you need something installed for the module itself to function properly, use PREREQ_PM This option has been around quite awhile, so you don't really need to worry about minimum EU::MM version numbers.

As usual, I'm sure if I've misstated something or left something out another helpful individual here will fill in those blanks. :)


Dave

Replies are listed 'Best First'.
Re^2: How to specify tests dependencies with Makefile.PL?
by OlegG (Monk) on Jan 03, 2012 at 12:39 UTC
    Thank you for such detailed answer. I will try it now.
    But can you explain, will cpan shell install dependencies listed in BUILD_REQUIRES if user typed "notest install XX::YY"?

      It certainly should. As I mentioned in my post above, BUILD_REQUIRES isn't specifically for the testing phase. It's for the build phase, which is actually earlier than the test phase. It's the place to list build dependencies, but happens to also be a good place for listing test dependencies. The reason I say it's a good place is this: It's my opinion (and only my opinion) that PREREQ_PM should be reserved for your module's actual dependencies. CONFIGURE_REQUIRES should be reserved for Makefile.PL's dependencies. BUILD_REQUIRES should be used for anything that is essential to the 'make' process or the make test process, but that is not essential for the target module itself once it's installed.

      These aren't the only hooks either. There are additional hooks for installing executables, and other paraphernalia. But when it comes to dependencies that are themselves actually modules, these are the three points of interest.


      Dave

        Hmm, in this case test dependencies becomes hard dependencies for end user. So, for this user there is no difference between PREREQ_PM and BUILD_REQUIRES, he should install both (if he used cpan shell).
        It seems all that I can is to ask user:
        ExtUtils::MakeMaker::prompt("Do you want testing support for this module?\nThis requires additional modules to be installed: XX::YY, YY::ZZ", "yes");
        However it will be strange question when notest pragma specified in the cpan shell. But it seems I can't determine from Makefile.PL is it specified, I didn't found how.