开发者

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 som开发者_如何学Goe thing like "make test all" it runs all the tests under the "t" dir? Thanks.


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";


Executing tests directly through perl works. The prove command was designed to simplify the process, save keystrokes, and shorten the test-debug-test cycle.

prove was designed to work on multiple tests at a time, which you can't do invoking via perl. For instance, you can do:

prove t/*.t
prove t/     # Same as t/*.t
prove t/dev/ # Run only tests in t/dev/
prove -r t/  # Runs all .t files in t/ and any directories below.

The modern prove also has many features for handling suites of tests and modifying how the TAP output from the tests is displayed.

prove --help will show you all prove's options, and prove --man will show you the manual page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜