Test::Verbose

Matts on 2005-01-12T13:20:02

Following on from chromatic's journal entry about quieter tests I thought I'd make a full journal post about Test::Verbose.

If you test, you need Test::Verbose.

The simple "tv" command line it installs will run all your tests, some of your tests, or an individual test. Unlike "prove" it is an interface to "make test" rather than a separate script for running tests, so if you make changes you don't need a separate "make" phase to get things into blib.

More importantly though is you can run tv with the -q option to make it only display errors, -qq to make it only display the final results table, or -qqq to make it display nothing at all (but exit with a relevant return code). This last option makes it perfect from cron job smoke tests.

Try it out today. You won't go back.


make test

jplindstrom on 2005-01-12T15:43:30

It does require a makefile, no?

I don't have that for my applications. A typical directory structure looks like this:
/project
  /bin
  /lib
    /My
      Module.pm
    /The
      /Other
         Mod.pm
  /t
    My-Module.t
    The-Other-Mod.t
The .t files contain a 'use lib "lib", "../lib";' to point to the module directory.

Like chromatic I usually just type perl t/FILENAME to run a certain test file, but I also enter the t directory and run prove to test them all.

If I have a huge amount of modules in my lib dir, what kind of makefile setup would I have? One for each? One for them all? Where would it go?

Re:make test

Matts on 2005-01-12T17:48:37

You would have one Makefile.PL with a very simple contents:
use ExtUtils::MakeMaker;
WriteMakefile(
    NAME => 'projectname',
    AUTHOR => 'me',
    VERSION => '1.0',
    ABSTRACT => 'this is my project',
);
You can change a few of those to extract better info, but you don't really need it.

ExtUtils::MakeMaker will find all your .pm files under a lib/ directory.

Use prove

petdance on 2005-01-12T17:47:18

prove is now standard with Test::Harness and Perl itself. I'd rather that people start/keep using it.

Re:Use prove

Matts on 2005-01-12T20:33:35

But prove doesn't do the same thing. It doesn't call "make test", and since it has been designed not to call "make test", it very likely won't every be changed to do so by default, right?

Re:Use prove

jplindstrom on 2005-01-12T20:56:36

I'm ignorant: why is that better?

Re:Use prove

Matts on 2005-01-12T21:10:59

Because with prove my t files have to contain "use lib 'lib';" in order to see changes in my lib directory, and that could cause odd errors if you're not very careful (overriding a blib directory that you don't expect it to do).

Re:Use prove

petdance on 2005-01-13T02:22:57

See http://use.perl.org/comments.pl?sid=24468&cid=37425 for the handling of this.

And, if it doesn't do what you want, ask. :-)

Re:Use prove

Matts on 2005-01-13T13:29:42

It doesn't do what I want. I want something that runs "make test".

What if my files aren't just in lib/, but are in completely separately named directories, each with their own Makefile.PL - MakeMaker picks this up and gets everything into blib, but prove won't see them.

See XML::Parser for an example of this.

Re:Use prove

petdance on 2005-01-13T15:35:13

OK, that's not going to work then. :-)

The #1 reason to have prove is so that you don't have to have a Makefile or run make test at all. So in this case, it would defeat the purpose of running prove.

Is there anything we can/should add to Test::Harness to make it more useful to you?

Re:Use prove

chromatic on 2005-01-21T01:31:56

A way to print only summaries and failures with diagnostics would be nice.

Re:Use prove

hide on 2005-01-12T21:28:44

Andy updated prove a while back at the request of David Wheeler and myself with an option to include the local lib directory.
-l, --lib       Add lib to the path for your tests.
So
MyModule$> prove -lv t/.*t
will run all test files in t/ with lib/ included in @INC.