in reply to How can I write Test::Finished?

You can do the test in a child process. Then you will have SIGCHLD to tell you when the child goes away. Since you may need a pipe to return the result of the test code, you can also have SIGPIPE to play with. If you set a timeout with alarm, you can check that the child is still running with kill 0, $cpid.

That ought to make a pretty flexible bag of tricks for testing really suspect code. Mostly useful on POSIX systems.

I'm not sure how useful the system exit status will be, but it can be collected by the signal handlers. Somebody who would exit from a module method is likely as not to exit(0).

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: How can I write Test::Finished?
by samtregar (Abbot) on Jun 21, 2004 at 19:11 UTC
    Ok, so that will tell me when the child exited and what its return code was, but how does that help me distinguish between a rogue exit(0) and complete test run?

    -sam

      untested code:
      if (open CHILD, "-|") { while (<CHILD>) { if (/^SUPERSECRETSTRING\n/) { exit 0; } print; } close CHILD; # to update $? exit $? >> 8; # oops, child exits, so we do too } ... rest of tests here ... print "SUPERSECRETSTRING\n"; # probably as an END block or DESTROY met +hod

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Also, since you control both parent and child, you could generate a random 'secret' string.

        # probably as an END block or DESTROY method

        The point is to not put that in an END block or DESTROY method so that it only gets printed when the tests run to completion.

        - tye        

        ++. Sneaky.

      The child can send, say, SIGUSR1 to the parent just before a normal exit. Or if you have a pipe, print "Done" over it. Sadly, there is little you can do that a really malicious rogue can't imitate.

      After Compline,
      Zaxo