[Israel.pm] Testing problem
Thomas Maier
Thomas.Maier at monosphere.com
Mon Jan 5 06:29:18 PST 2004
Thanks, it's very nice, but IMO I can make it shorter by
passing straight forward some faked 'command' instead of new
subroutine
sub method
{
my ($self, $fake_command, @param) = @_;
$pid = open $fh,"-|","$fake_command @param";
$x = do something with $fh;
return $x;
}
But since it's only for testing purpose, I would like to avoid from
passing additional parameters to this method. Any idea ?
> -----Original Message-----
> From: Jason Elbaum [mailto:Jason.Elbaum at motorola.com]
> Sent: ב 05 ינואר 2004 15:46
> To: Perl in Israel
> Subject: Re: [Israel.pm] Testing problem
>
> Thomas Maier wrote:
>
> > sub method
> > {
> > my ($self, at param) = @_;
> > $pid = open $fh,"-|","command @param";
> > $x = do something with $fh;
> > return $x;
> > }
> >
> > I would like to test this method but without
> > actually running the 'command'.
>
> I haven't thought this through to the end, but here are some preliminary
> ideas.
>
>
> First, you need to separate the running of the command from the method.
> One way to do this:
>
>
> sub method
> {
> my ($self, $commandSubRef, @param) = @_;
>
> # Execute command, creating a pid and a file handle
> ($pid, $fh) = $commandSubRef->(@param);
>
> $x = do something with $fh;
> return $x;
> }
>
> Then your production code can call the method like this:
>
> sub command
> {
> my @param = @_;
> $pid = open $fh,"-|","command @param";
> return ($pid, $fh);
> }
>
> $self->method(command, @param);
>
>
> Your test code can provide an alternative implementation of command
> which, for example, reads a predefined file. For example:
>
> sub commandTester
> {
> my @param = @_;
>
> $pid = open $fh,"-|","cat testfile";
> return ($pid, $fh);
> }
>
>
> Is this helpful?
>
>
> Jason Elbaum
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/mailman/listinfo/perl
>
> YAPC::Israel::2004
> http://www.perl.org.il/YAPC/2004/
More information about the Perl
mailing list