Adam Kennedy wrote:


Randy W. Sims wrote:
Adam Kennedy wrote:

This works:


---test.pl---
use Test::More tests => 1;

my $Test = Test::More->builder;
my $counter = $Test->current_test;

print qx!perl t/response.pl!;

$Test->current_test($counter + 1);

But why 1? Why not 5? or 10?

It has to be set to the number of tests run in the other process. I don't know if there is a way to do something like no_plan for the sub process... I don't think so... Every time pass(), ok(), etc is called it updates the counter. In the sub process there is no way to pass back the internal counter, so you have to update the counter manually.

Well, that would be why you allow the sub-process's plan code to run as normal. When you get the fragment back, you can update it from the header or the foot, but not print the actual header/footer.

You mean capture the output from the child process? Then allow the parent to generate the test output from the captured & parsed output of the child? That would mean for any lengthy child process there would be a pause until the child completed; only then would the parent output the results from the child. Otherwise, I guess you could Tee the output from the child.

Is that what you mean by getting the fragment back?

It also means you get the numbers in order in the main tests too, because of the reprocessing.

The counter gets out of order in the snippet I sent if any tests are added before the child process. That can be fixed with the code below (Alt: use an $ENV variable to pass $counter), but you still need to know how many tests are running in the child ahead of time. I guess you could write out the counter to a file in the child & read it back in the parent, or any other normal means of IPC. All of this would presumably be wrapped in a Test::* module to hide the ugly.

---plan.t---
use Test::More tests => 3;

pass('Parent: Begin');

my $Test = Test::More->builder;
my $counter = $Test->current_test;
print qx!perl t/response.pl $counter!;
$Test->current_test($counter + 1);

pass('Parent: End');

__END__

---response.t---
use Test::More no_plan => 1;

my $Test = Test::More->builder;
$Test->no_header(1);

my $counter = shift;
$Test->current_test($counter);

pass('Child');

__END__

Reply via email to