How can I tell Makemaker to run tests in parallel?

118 views Asked by At

I have a module with a MakeMaker generated Makefile and I want to run my unit tests (make test) in parallel. Test::Harness accepts e.g., HARNESS_OPTIONS=j4 to use 4 threads. But I don't see how MakeMaker's test target can be adjusted to set this variable.

Now I could just export HARNESS_OPTIONS=j4 in my ~/.bashrc but it seems odd to force that on every test run that uses Test::Harness. What if I have tests that shouldn't run in parallel in another project?

With make -j4 test I don't see any improvement. make test runs

PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/*/*.t

so I guess that even if make would use multiple threads, Test::Harness may not support this, or make may not pass this information to Test::Harness.

Currently this just to speed up my testing. My module is an internal module and I'm not too worried about forcing this option on any user of the module. However, if I can define this option in e.g., a config file that I don't ship, that would work, too.

Speaking of config files: I can run prove -j4 t/ and run tests in parallel. So an option could be to tell MakeMaker to run tests with prove, but I don't see a way to configure that either.

How can I tell MakeMaker to run this project's tests in parallel?

1

There are 1 answers

0
LordAro On

Having looked through MakeMaker's code, there doesn't seem to be a way of telling MakeMaker explicitly to (always) run tests in parallel. It just outputs the line mentioned in the question to the makefile, with the only configurable things being verbose, and the test file(s) to run.

However, if you're just wanting to set an environment variable for a single test run, then HARNESS_OPTIONS works fine for this purpose, just set it in your terminal before running

export HARNESS_OPTIONS=j4
make test

which will make the option persist for that terminal session, or for just a single command, make HARNESS_OPTIONS=j4 test will work as a oneliner.

(I originally found this question while looking for the same thing myself, but overlooked HARNESS_OPTIONS in the question, so I'll leave this here as a reference to others: https://perldoc.perl.org/Test::Harness#HARNESS_OPTIONS )