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

How do I tell Test::More that it shouldn't attempt to do any tests? In Regexp::Approx - Use fuzzy regular expressions the module forks during INIT and when I try to run tests I find that Test::More is attempting to control both the parent and the child. I think I need to tell it to not run tests in the child but I don't know how to do that. I tried skipping the tests but that just sends the ok / skipped message for the same test for each process. The following snippet is a reduction of the general case in the Regexp::Approx node.

use Test::More tests => 1; INIT { $child = fork } ok( 1 );
make test t/02init.....ok 2/1Don't know which tests failed: got 2 ok, expected 1

Replies are listed 'Best First'.
Re: Getting Test::More to ignore forked children
by adrianh (Chancellor) on Nov 13, 2003 at 23:20 UTC

    You're forking, and running a test in both parent and child, hence the extra test. If you really want two tests you'll need to:

    • make a plan with two tests (or set it to no_plan)
    • switch test numbering off (since you can't guarantee whether the parent or child will run their test first)

    If you don't want to run tests in parent and child then... erm... don't execute the test statements. Stick if ($child_pid) { ... } round the tests.

    Or am I completely missing the point? :-)

      You're missing the point. In the following code sample the child immediately exits without running any tests. In my real tests the child is an artifact of the module code and isn't meant to be tested directly (there's some IPC going on). I should be able to kill off Test::More in the child so it can get on with taking care of its parent without being expected to run tests as well.

      use Test::More 'no_plan'; exit unless fork; ok( 1 ); __DATA__ ok 1 # No tests run! 1..1

        What version of Test::Builder are you running? This sounds like an issue that was fixed in the Test::Simple 0.47 release. From the Changes file:

        - Peter Scott made the ending logic not fire on child processes when forking.

        I don't see the behaviour you're getting in my version. If you can't update Test::Builder, then calling Test::More->builder->no_ending in the child process should stop the error.