Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run only a specific test in a Perl distribution?

This question is related to this question I asked before. I have multiple test files (A.t, B.t, C.t etc) created to test their respective module A, B, C & so on. But when I do a make test, it runs all the tests. But, when I'm working on a specific module say B, I'd like to run unit tests for that module. After I'm done with my changes, I'll run the whole suite.

So is there any way to do like make test B, which will run only the tests using B.t? And when I say some thing like "make test all" it runs all the tests under the "t" dir? Thanks.

like image 229
John Avatar asked Feb 04 '10 23:02

John


1 Answers

I just run the test that I want to run:

 % make; perl -Mblib t/B.t

You can do the same thing with prove, too.


That -Mblib loads the module blib which merely adds blib/lib (and various special directories under it) to @INC for you. It comes with Perl. prove should do the same thing with the -b switch.

My command is really two parts: the make (or ./Build for Module::Build). This builds the source and moves Perl modules and other files into the "build library", or blib, as an intermediate step in the full installation. Normally make test works against the versions in blib and refreshes that for me. Since I'm testing on my own, I ensure that I refresh blib myself and include it in Perl's module search path.

Despite the fact that I know all this, you might be surprised that I often forget to do one of those steps and end up testing against the wrong version of things, whether the fully installed old version (forgot -Mblib) or the old development sources (forgot make). This leads me to debugging statements such as:

print "No really, this is the Foo version. kthnxbye\n";
like image 134
brian d foy Avatar answered Oct 23 '22 09:10

brian d foy