David Golden wrote:
> On Sun, Jul 5, 2009 at 9:40 PM, Buddy Burden<barefootco...@gmail.com> wrote:
>> Let's say I have some common functions that I want available to all my
>> .t files.  So I've created a module that all the .t files can include.
>>  But where do I put it?  I don't want to put it in lib/ because I
>> don't want it to get installed, right?  But when I put it in t/, make
>> test can't seem to find it.
> 
> I tend to see three variations.

They're all fine.  Here's my opinions.


> (1) put it in t/lib/MyTest.pm and "use lib 't/lib'" at the start of
> your test files

This is my preferred way of doing things.  Using lib::abs avoids any problems
if your test code has to chdir().


> (2) put it in t/MyTest.pm and "use lib 't'" at the start of your test files

I don't like this because it clutters up the test directory.  We have
subdirectories for a reason.


> (3) either of the above but "use t::MyTest" rather than changing @INC
> with "use lib..."

Has all the problems of #2, plus it wields your testing module to the t/
directory.  If you want to move it or package it into its own dist you have to
change the package name.  If its a class you're writing "t::MyTest->...".

If for some reason your code has to chdir() before loading the module there's
no way to compensate for that.


> I don't think any one is much better than the others.  I tend to like
> the "t::MyTest" approach from a readability standpoint because it's
> clear within the *.t file that this is a test library and it's clear
> where to locate it.



-- 
A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?

Reply via email to