Search code examples
perltestingpathperl-prove

How can I easily add the uninstalled Perl modules in my development directory to @INC?


I'm writing Perl t/*.t tests for an existing project. During development, I'd like to use 'prove' to run select tests at arbitrary depths in the module directory hierarchy. I've created some t/ directories at the same depth as the *.pm files I'd like to test. Unfortunately, the lib/ at the base of the project's code is not in @INC.

What's the best way to automatically detect and add the path to @INC? I've looked at the -b option to prove and blib in general but they don't seem to work (they take the pwd and append blib/lib to it and add that to @INC). Ideally, the solution would not require an environment variable or installing the modules and would accommodate a number of working copies of the same code.

Is my approach wrong? Is there something obvious I'm missing? CPAN modules seem to solve this through installation or copied code blocks at the top of *.t files (yuck).

Edit:

Structure looks like:

/home/user/proj/branch\_foo/lib/First/Second/Third.pm
/home/user/proj/branch\_foo/lib/First/Second/t/third.t

This works:

~/proj/branch\_foo/lib/First/Second$ prove -I../..

But I'd like:

~/proj/branch\_foo/lib/First/Second$ prove -r

Or:

~/proj/branch\_foo/lib/First/Second$ prove t/third.t

So I can do:

~/proj/branch\_foo/lib$ prove -r

Instead of:

~/proj/branch\_foo/lib$ prove -I. -r

Maybe I just have to use -I and deal with it.


Solution

  • prove has an -I command line option:

    -I Library paths to include.

    Can you specify the paths using that option?

    Update:

    Thanks for providing the layout. I cannot think of a quick solution right now, but maybe you can use .proverc files in the appropriate directories to cut down on the typing required. I am not sure how multiple .proverc files interact with the -r option but this is something to look into.