http://www.perlmonks.org?node_id=914970

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

The 'make test' target in ExtUtils::MakeMaker calls the test suite via
test_harness(0, 'blib/lib', 'blib/arch')
making sure that @INC is set correctly in */*.t scripts called subsequently.

But what if one of these scripts in t/*.t calls another script (e.g. a bin script that's part of the module distro and needs to be tested), how do I make sure that it gets called with the correct -I setting, in order to find my yet-to-be-installed modules? I was thinking

system( $^X, "-Iblib/lib", "path/scriptname" );
but setting -I manually to "blib/lib" breaks encapsulation, Test::Harness should provide a setting for that, but I can't find it. Any pointers?

Replies are listed 'Best First'.
Re: Test::Harness: Calling a script with proper @INC
by chromatic (Archbishop) on Jul 17, 2011 at 17:08 UTC

    You could add use blib; to that test file, or you could extract all of the code from the script into its own module and test that just as you would any other module. I tend to do the latter.

Re: Test::Harness: Calling a script with proper @INC
by sundialsvc4 (Abbot) on Jul 18, 2011 at 03:45 UTC

    What I have begun to do, in large test cases, is to insert logic at the beginning of each test file which sets-up the correct environment for that test file.   In other words, instead of putting the setup responsibility into “the wrapper,” so to speak, I push it down into some bit of common-code that all of the individual test files use or include.   “It just works out better that way,” one very nice feature being that tests can be run individually (they are Perl programs, after all...) or in a given harness, and everything works out the same way regardless.   The test files no longer depend upon “I am being run within this-or-that harness” (and I use the word “harness” loosely here).   They run consistently no matter how they are run.   (And, the necessary changes need only be done in one file or unit which they all reference.)

Re: Test::Harness: Calling a script with proper @INC
by Anonymous Monk on Jul 18, 2011 at 06:22 UTC