How to specify test prerequisites in the ExtUtils::MakeMaker Makefile.PL
Asked Answered
R

3

5

PREREQ_PM specifies the runtime prerequisites, but how to specify which modules are required to run the test cases?

Should I use BUILD_REQUIRES for this?

Rhondarhondda answered 29/8, 2012 at 6:54 Comment(0)
S
4

As of ExtUtils::MakeMaker 6.64, there is a TEST_REQUIRES parameter.

use ExtUtils::MakeMaker 6.64;

WriteMakefile(
    ...,
    TEST_REQUIRES => {
        Test::More => 0.95,
        },
    ...,
    );
Spier answered 3/1, 2014 at 15:41 Comment(0)
S
3

The CPAN::Meta::Spec defines how modules communicate their prerequisites to the toolchain. The version 2 spec revised the way prerequisites are listed. The test phase now has its own list of prerequisites.

But MakeMaker hasn't been updated for the v2 spec, and likely never will be. The only fully-compliant v2 distribution tool I know of is Dist::Zilla (and I recommend it for more reasons than that).

When CPAN::Meta::Converter converts from the v2 spec to v1.4, it merges the test requirements into build_requires.

So yes, if you stick with MakeMaker, any modules that are required to run the tests should be listed in BUILD_REQUIRES. PREREQ_PM should contain only modules that are still required after the module is installed.

Sleeper answered 29/8, 2012 at 17:26 Comment(3)
Excellent explanation. (And finally a good rationale for how I've been doing it all along. ;)Gladis
@smonff, this answer is out of date. MakeMaker actually did get TEST_REQUIRES support just a few months after I wrote it. I'll update it when I get a chance.Sleeper
@Sleeper I appreciate you mention it :D !Escaut
M
1

If the tests fail without a module, then I list it in PREREQ_PM regardless of whether it's needed for testing or for running the module.

If I need modules for some tests, but they are not needed to run the module, I detect those when the tests are run, and I skip the tests (with a PASS) if I can't find them.

I don't think there is any field in ExtUtils::MakeMaker for what you want.

Moorish answered 29/8, 2012 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.