On Jul 18, 2006, at 1:59 PM, Paul LeoNerd Evans wrote:

I have a question on a testing strategy for a CPAN module test
script.... I've got two competing ideas on how to do it; I wonder if
anyone can suggest one or the other..

The function under test sends some data down a socket, then awaits a
response. Do I A: pre-send a response and get the kernel to buffer it,
call it, and check the sent value on return, or B: pipe() and fork() a
child, and have the checking/sending done in there?

Could you hijack the internal functions that read & write data on the socket? I.e. if call_function() uses _send() and _receive() internally, do:

{
  my ($sent)
  local *_send = sub {$sent = shift};
  local *_receive = sub {return "The response you read\n"};

  $result = call_function( "args" );
  is( $result, "foo", "return value" );
  is( $sent, "bar", "sent data" );
}

 -Ken

Reply via email to