Checking for Test::More

BooK on 2004-10-11T09:31:02

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?


Test::More - don't leave home without it

jplindstrom on 2004-10-11T12:39:09

Isn't Test::More one of those modules that every Perl installation should have? So the sooner someone is "forced" to install it the better, IMHO.

As dependencies go, isn't Test::More pure Perl, so it should install everywhere without problem?

module prerequisites

geoff on 2004-10-11T13:59:16

while I'm a guity as anyone for having done this in the past, I've not come to support the position that test modules should not be prerequisites a la 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.



but another solution to using a 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...

Using the module

petdance on 2004-10-11T18:07:25

I think that the Test:: modules should not be part of the prerequisites for using a module. Am I right?

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).

Test scripts prereqs

Maddingue on 2004-10-11T20:54:42

In fact, I think what you want is something similar to the build_requires in Build.PL but for the tests only: tests_requires.

Maybe you could ask Ken Williams to add this for the next release of Module::Build?

I say make it a dependency

grantm on 2004-10-12T09:53:11

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, .deb and related formats. These files are easier for Joe Public to install and they generally don't list the Test modules as prerequisites if they're only required at build time.

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 installed

Yes, but surely that's largely as a result of those modules being listed as prerequisites in the distributions being tested.