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

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

I've got a very large internal project (many hundreds of packages) I'm trying to come up with a nice method of grouping tests together to allow a "group" of tests to be run, rather than all the tests.

I was thinking something like, laying out the tests as

t/001_first_global_test.t
t/001_second_global_test.t
t/group1/001_first_group1_test.t
t/group2/001_first_group2_test.t
t/group2/002_second_group2_test.t

then being able to do

make test group1

and just have t/group1/001_first_group1_test.t run or

make test all

and running every test

Is there a standard way for doing this? Currently how we handle it is the project is broken up into hundreds of separate (h2xs created) modules.. which is quite a pain to manage, I'd really like to bring them all together as 1 module with all the packages in it.

Replies are listed 'Best First'.
Re: Grouping tests
by Prof Vince (Friar) on Sep 18, 2007 at 08:39 UTC
    As far as make is concerned, make foo bar will run the two targets foo and bar. It can't bind a special meaning for bar depending on foo. The best you could achieve would be make test-group1, make test-group2... with a rule like:
    test-%: perl -MTest::Harness -e 'runtests @ARGV' t/$$*/*.t
    You could also put Makefiles in all the t subdirectories and run the tests with make -C t/group1 test.

    As for doing this with EUMM or MB, I have no idea.
Re: Grouping tests
by lima1 (Curate) on Sep 18, 2007 at 09:59 UTC
    or when you use Build.PL:
    ./Build test --test_files "t/group1/*"
Re: Grouping tests
by djp (Hermit) on Sep 19, 2007 at 03:57 UTC
    This is where Test-Harness's 'prove' command-line tool shines, you can specify exactly which tests you want to run. From the doco:
    * prove is granular prove lets your run against only the files you want to check. Running "prove t/live/ t/master.t" checks every *.t in t/live, plus t/master.t.
    Check out the -r option as well.
      Thanks Prove looks very close to what I want,
      I played around a bit with Build.PL and setting up custom ACTION_test subclasses, but that seemed very clunky (they do say its alpha) and difficult to maintain.