Recently, I've taken the habit (not in my CPAN modules, though) to add the following snippet at the beginning of all my test scripts:
BEGIN { eval { require Test::More; }; # and other Test:: modules print "1..0 # Skip Test::More missing\n", exit if $@; }
This is because I do not expect the people who install those modules/scripts to run the test suite, and I don't want the installation process to whine about Test::More missing (if it's in the Makefile.PL) and stop and sulk.
I think that the Test:: modules should not be part of the prerequisites for using a module. Am I right?
PREREQ_PM
despite the ubiquity of Test::More
- there is a large difference between the test environment and the code itself, and making it impossible to build and install a module when test environment dependencies are missing just seems wrong.BEGIN
block in each test file is to override the test
target in the Makefile
by creating your own MY::test
subroutine in Makefile.PL
. something similar to this (but for Test::More
, of course). while it doesn't protect against people running the test files by themselves, it give an appropriate response for people just following perl Makefile.PL && make && make test
...
If you can't run the tests, then how do you know that your users can actually use the module?
Re:Using the module
schwern on 2004-10-11T19:11:04
Like he said, he doesn't do this for modules. That's a different world with different expectations.Re:Using the module
BooK on 2004-10-11T21:03:32
In fact, the conclusion came to me after posting that entry:
It would be nice to separate the test prerequisites and the usage prerequisites.I've just been told (hi Maddingue!) that Module::Build allows this (well build_requires is not quite the same as a test_requires, but probably close enough).
build_requires
in Build.PL but for the tests only: tests_requires
.I think Test::Simple should be marked as a dependency. It really is needed to run the basic tests to confirm the module works. If you need other more esoteric Test::* modules then test scripts which degrade gracefully may be a good idea. Unfortunately, that would not allow you to take the fullest advantage of the the service provided by the wonderful CPAN-Testers team.
On a related note, many CPAN modules are also repackaged in RPM,
Re:I say make it a dependency
BooK on 2004-10-12T16:07:07
Unfortunately, that would not allow you to take the fullest advantage of the the service provided by the wonderful CPAN-Testers team.Well, I take for granted the fact that all CPAN testers have at least all the Test::* modules installed.
Re:I say make it a dependency
grantm on 2004-10-12T18:01:49
I take for granted the fact that all CPAN testers have at least all the Test::* modules installedYes, but surely that's largely as a result of those modules being listed as prerequisites in the distributions being tested.