Dog and Pony has asked for the wisdom of the Perl Monks concerning the following question:

Already at my last work, me and some others were looking at doing things the XP way, we read Fowler's refactoring, and studied stuff on the web, trying to put some of that in practice. I've also read chromatic's excellent article on testing at perl.com, and now recently Ovid's meditation, The Joy of Test. I'm still not always a good boy with this testing, but I am gonna get there. Promise.

My questions came up when I was wondering if I should use the standard module Test or if I should use the more powerful Test::More. I'd really like to use the latter, but it isn't included in the standard distribution.

So, if I actually someday create something good enough to distribute, should my test.pl be using Test::More, potentially giving people errors during 'make test' and have them install this module, or should I try to go with the standard Test to avoid this?

Question number two is about the module CPAN, and if I actually make something that great it could be uploaded there - I know that it follows prerequisites somehow (via Makefile.PL?) during install (if you ask it to); is this done before the test script, so I could name Test::More as a must-have module and CPAN.pm will take care of this?

To sum it up: should I usually use standard modules, even if there is a better alternative readily available, and how do I make sure a user can install my stuff including modules it needs with as little trouble as possible?

Personally, I would simply install Test::More or whatever and try again if this happened to me, but I wonder what is customary, how you do it, and what you recommend. :) I'd rather a user be scared by my module than by the install *grin*

Thank you.


You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.
  • Comment on Use a standard module or a "better" one, and how to make installing it troublefree.

Replies are listed 'Best First'.
Re: Use a standard module or a "better" one, and how to make installing it troublefree.
by stephen (Priest) on Apr 14, 2002 at 16:08 UTC

    First question is, do you use Test::More's improvements? I find that the standard Test module covers basic tests pretty well. No sense using Test::More unless you need it.

    If you decide that you truly need Test::More's added flexibility, you can add a PREREQ_PM attribute to your WriteMakefile() call in Makefile.PL. It's a hashref, with the names being the module names and the values being the version number required for your script to run. Version number '0' means 'Any version'. Here's what it would be for a module called 'Devel::Refactorizer':

    WriteMakefile( 'NAME' => 'Devel::Refactorizer', 'VERSION_FROM' => 'Refactorizer.pm', # finds $VERSION 'PREREQ_PM' => { 'Test::More' => 0}, # e.g., Module::Name +=> 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'Refactorizer.pm', # retrieve abstract from mo +dule AUTHOR => 'A. U. Thor <a.u.thor@a.galaxy.far.far.away>') : +()), );

    Truth in advertising: much of what I'm saying here is stuff I'm reading from the documentation right now for the first time. :)

    If you were to install this module using CPAN, it would first attempt to do a 'make' on the distribution. This attempt would fail, since the Makefile will complain about lacking the Test::More module. Then, the CPAN module would download Test::More, build it, and then re-run 'make' on the Refactorizer. CPAN runs 'make test' after 'make', so Test::More would be in place for the tests.

    Another approach: some folks bundle Test::More along with their module distributions. I personally think that this method clutters CPAN; observe what happens when you search for Test::More with search.cpan.org. However, it's a fairly small module, and some pretty bright people take this approach, so YMMV.

    stephen

      Thank you! This sounds like exactly what I wanted to know. If I really need Test::More or not is a very valid question, but now I feel safer with taking that desicion if I feel I do need it. :)

      I guess that is the same question that I did ask, should I use a standard module or not - one of the criteria should definetely be "do I really need this?". Good point indeed.

      You mention that you read the documentation, could you please tell me where it is also? I looked through all the - what i thought - normal places for this, and couldn't find it. It is possible I have a small Sunday brain damage, so I'd appreciate it. :)

      I don't think I'll bundle it anyways, which means that one possibly still have a problem with non-CPAN installs, but heck, people will just have to read the README for once then. They should anyways. :)

      Again, thank you for the reply!


      You have moved into a dark place.
      It is pitch black. You are likely to be eaten by a grue.

        I searched for 'PREREQ_PM' in both the CPAN module documentation and the ExtUtils::MakeMaker docs. I always enjoy questions like this because, well, now I know too. :)

        stephen

Re: Use a standard module or a "better" one, and how to make installing it troublefree.
by tachyon (Chancellor) on Apr 14, 2002 at 17:33 UTC

    I find Test is quite adequate. If you want you can bundle a copy of Test::More or even Test::Lincoln::Stein in your distro to avoid this problem. Asking permission for Test::More would be politic. See the CGI distribution to see Lincoln Stein roll his own test suite and include it. If you want complex tests you can have them just using Test:

    use Test; BEGIN { plan tests => 42 } use Widget; ok(1) # module loaded OK my $w = new Widget; $reply = $w->method; @reply = $w->method; ok( $reply ); ok( @reply ); ok( $reply =~ m/something/ ); ok( $reply eq 'some string' ); ok( scalar @reply == 42 ); ok( join '', @reply eq 'some list of stuff' );

    When you make a disto start like this:

    $ h2xs -X Foo::Bar

    This will write module stubs for you automatically. You will get:

    Foo/Bar/Makefile.PL Foo/Bar/Bar.pm Foo/Bar/Changes Foo/Bar/test.pl Foo/Bar/MANIFEST Foo/Bar/README

    You should then rename the Bar direcory Foo-Bar-0.01 if you want to follow the norms. You throw away the Foo dir :-) This writes you the stubs of your code which you can then just edit! Note if you just h2xs -X Bar then you will avoid generating the extra directory but you will need to edit your Makefile.PL it will have:

    'NAME' => 'Bar' # but you need 'NAME' => 'Foo::Bar'

    Package like this:

    $ tar -cf Foo-Bar-0.01.tar Foo-Bar-0.01 $ gzip Foo-Bar-0.01.tar

    Test like this:

    $ tar -xzvf Foo-Bar-0.01.tar.gz $ perl Makefile.PL $ make $ make test $ make install

    You will find that when you are playing with your distro you will repeat a number of steps over and over. I have a little script called make_manifest.pl which does a whole lot of things like:

    • clean out blib/ and all the other Makefile and make crap
    • remove any temp files like .bak files (or any other extensions like .pbp ~ etc)
    • cleans Win32 line endings to *nix standard (otherwise you will have install nightmares)
    • writes HTML files into html/ for all the pod (with CSS support) using Pod::HTML
    • writes a current MANIFEST
    You can get a copy of the script from the CGI::Simple distro (it expects to be in the misc/ dir which is where you will find it. Don't forget the CSS if you use this script.

    Finally use Carp; see Carp for why and use the carp() and croak methods instead of warn() and die() which will put these messages in the perspective of the caller rather than the module.

    Good luck.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      First off, I do know that I can accomplish the same things with Test, even though I like the richer interface of Test::More better, and it makes the tests easier to read. A matter of taste, and "do I need it", and probably other things too. :)

      That said, I am impressed by the richness of your response, and I see that there are lots of gold here for when modules should start hitting the world. Thanks! Lots of it is not new, but it is a good summary, in good context.

      I guess I could bundle whatever module I need like that, but I think I would rather have it as a prerequisite, or use one that the installer is sure to have.

      And I will take a look at that script - no use in reinventing the wheel on that one. :)

      Again, thank you. I will have use for this. :)


      You have moved into a dark place.
      It is pitch black. You are likely to be eaten by a grue.
Re: Use a standard module or a "better" one, and how to make installing it troublefree.
by Molt (Chaplain) on Apr 15, 2002 at 09:56 UTC

    Like you I'm beginning to look into using an XP-like unit-test framework in Perl, so the timing of your question here was good for me.

    I think if you are personally going to see advantages from Test::More then you should use it. It may help you get that release out there, and asking people to install it before your module isn't overly unreasonable. It does look to be a generally useful module, you're not going to be the only one now looking down that way, and the user gets the advantage of potentially more stable code if you like your test tool.