Test::Prereq(3pm)

πŸ“¦
version 2.005 Β· 6 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Test::Prereq β€” the "bestie, is your Makefile.PL lying to you?" check πŸ’–

okay so this is a Perl module page, Test::Prereq(3pm), and it's about one very specific flavor of chaos: making sure the pre-requisites in your Makefile.PL are actually, you know, correct. ✨


✨ NAME ✨

Test::Prereq β€” check if Makefile.PL has the right pre-requisites. that's it. that's the whole job. πŸ’…


🌸 SYNOPSIS 🌸

if you're a Makefile.PL girlie:

# if you use Makefile.PL
use Test::More;
eval "use Test::Prereq";
plan skip_all => "Test::Prereq required to test dependencies" if $@;
prereq_ok();

if you're a Module::Build girlie instead:

# if you use Module::Build
use Test::More;
eval "use Test::Prereq::Build";
plan skip_all => "Test::Prereq::Build required to test dependencies" if $@;
prereq_ok();

or, like, straight from the command line for a one-off vibe check:

# or from the command line for a one-off check
perl -MTest::Prereq -eprereq_ok
🫢 real talk: the prerequisites test takes quite some time, so this next construct is what's recommended for non-author testers:
#The prerequisites test take quite some time so the following construct is
#recommended for non-author testers
use Test::More;
eval "use Test::Prereq::Build";

my $msg;
if ($@) {
    $msg = 'Test::Prereq::Build required to test dependencies';
} elsif (not $ENV{TEST_AUTHOR}) {
    $msg = 'Author test.  Set $ENV{TEST_AUTHOR} to a true value to run.';
}
plan skip_all => $msg if $msg;
prereq_ok();

πŸ¦‹ DESCRIPTION πŸ¦‹

so the prereq_ok() function goes snooping through the modules it finds in blib/lib/, blib/script, and the test files it finds in t/ (plus test.pl). then it works out which modules those actually use and compares that whole list against the ones sitting in the "PREREQ_PM" section of Makefile.PL. it's giving detective energy πŸ”

if you're on "Module::Build" instead, go look at Test::Prereq::Build instead. different girl, same mission. πŸ’–

⚠️ Warning about redefining ExtUtils::MakeMaker::WriteMakefile ⚠️

"Test::Prereq" has its own version of "ExtUtils::MakeMaker::WriteMakefile", and the reason is so it can actually run the Makefile.PL and grab the argument list of that function. so yeah β€” you may see warnings about this. not a bug, just the price of knowing things. πŸ’€


πŸ”₯ FUNCTIONS πŸ”₯

  • prereq_ok( [ NAME [, SKIP_ARRAY] ] ) β€” tests Makefile.PL to make sure all the non-core module dependencies are in "PREREQ_PM". and if you haven't set a testing plan already, prereq_ok() makes one for you β€” a plan of one test. cute, efficient, slay.

the valid versions come from "Module::CoreList" (which uses $]):

#!/usr/bin/perl
use Module::CoreList;
print map "$_\n", sort keys %Module::CoreList::version;

"prereq_ok" also tries to remove modules it found in lib/ and libraries it found in t/ from the reported prerequisites. because duh, those aren't real prereqs. πŸ™ˆ

the optional third argument is an array reference β€” a list of names that "prereq_ok" should ignore. you'd want this if your tests do funny things with "require". and yeah, "funny things" is doing a lot of work in that sentence, we all know.

ok so history lesson: versions prior to 1.038 would use CPAN.pm to virtually include prerequisites in distributions that you declared explicitly. and ngl, that isn't really a good idea. some modules have moved to different distributions, so you should just specify all the modules that you use instead of relying on a particular distribution to provide them. not only that β€” expanding distributions with CPAN.pm takes forever. like, forever forever. 😭

if you genuinely want that old behavior back, set the "TEST_PREREQ_EXPAND_WITH_CPAN" environment variable to a true value. you do you bestie 🫢


πŸŽ€ TO DO πŸŽ€

  • set up a couple fake module distributions to test
  • warn about things that show up in "PREREQ_PM" unnecessarily

(the audacity of unnecessary PREREQ_PM entries, honestly. not on our watch. πŸ’…)


πŸ‘‘ SOURCE AVAILABILITY πŸ‘‘

the source lives in Github:

http://github.com/briandfoy/test-prereq

🌈 CONTRIBUTORS 🌈

many thanks to:

Andy Lester, Slavin Rezić, Randal Schwartz, Iain Truskett, Dylan Martin

icons, all of them. πŸ‘‘


πŸ’œ AUTHOR πŸ’œ

brian d foy, "<briandfoy@pobox.com>"


Copyright Β© 2002-2025, brian d foy <briandfoy@pobox.com>. All rights reserved. This software is available under the Artistic License 2.


and that's the whole page bestie β€” this one's from perl v5.40.0, dated 2025-01-11, and it's Test::Prereq(3pm). go forth and make your PREREQ_PM honest βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from