ryantate has asked for the wisdom of the Perl Monks concerning the following question:

I am building a module disribution, but a test in t/ that tries use_ok can't find the modules in lib/. I am wondering how to make that test work.

I used Module::Starter to get my collection of modules off the ground. This is where I get the "module distribution" I'm talking about -- it's a directory with my modules inside lib/, some tests in t/, a Makefile.PL, Changes, README, MANIFEST and bin/.

While I've done plenty of modules in the past, this is the first time I've done any automated tests. That's a confession. I *have* read Test::Tutorial and the docs for Test::More and Test::Simple, FWIW.

The sole test created by Module::Starter is one that calls use_ok against each module in my distribution. When I run this test by typing perl -wT 00_load.t, each test fails with "Can't locate My/Module/Path/Here.pm in @INC" etc.

I have the whole lib/ directory of my module distribution softlinked into the directory specified in my PERL5LIB environmental variable. Not sure why this doesn't work

Since I'm new to testing I'm wondering if I'm going about this all wrong. How am I *supposed* to run my tests? Am I supposed to just copy the whole module distribution into /tmp (or checkout via svn) and then do perl Makefile.PL && make test? Am I supposed to do what I'm doing -- just perl -wT ##-name.t each file inside t/??

Very lost. Thanks for any help.

  • Comment on Test::More::use_ok can't find the module

Replies are listed 'Best First'.
Re: Test::More::use_ok can't find the module
by xdg (Monsignor) on Feb 26, 2006 at 05:48 UTC
    Am I supposed to just copy the whole module distribution into /tmp (or checkout via svn) and then do perl Makefile.PL && make test

    Almost, but you don't have to worry about copying or checking out somewhere else. Generally, from within your development directory, you can do this:

    $ perl Makefile.PL $ make $ make test

    To cleanup afterwards, run make clean or make realclean. See ExtUtils::MakeMaker for details.

    For example, to run verbosely (showing all tests), do this:

    $ make test TEST_VERBOSE=1

    prove is another option, but you still generally want to run make to have your modules copied to the blib directory before you run prove with the -b option.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Test::More::use_ok can't find the module
by rhesa (Vicar) on Feb 26, 2006 at 01:27 UTC
    cd to the root of your distribution, then use perl -I lib t/foo.t, or preferably prove -I lib t/. The prove utility is very very neat.

    An alternative of course, is to use make, and have that run your tests. That is, just do make disttest :)

Re: Test::More::use_ok can't find the module
by ryantate (Friar) on Feb 27, 2006 at 22:43 UTC
    Both of these comments are quite helpful, thank you very much. For now I'm using make && make test && make clean, which seems to work fine. I am also looking into how I can use prove in the future. Thanks!