[Israel.pm] Testing problem

Shlomi Fish shlomif at iglu.org.il
Tue Jan 6 03:30:46 PST 2004


On Tuesday 06 January 2004 10:41, Mikhael Goikhman wrote:
> On 06 Jan 2004 09:44:05 +0200, Shlomi Fish wrote:
> > On Tuesday 06 January 2004 06:43, Ran Eilam wrote:
> > > Could be a problem if your test does several open(), but you only want
> > > to mock one. Probably rare.
> >
> > Which is one reason I think why my solution is better.
>
> There is no doubt the OO way rules, but I am not sure whether you
>
> suggested any usable solution. You wrote:
> > What I would do is this:
> >
> > sub myopen
> > {
> >         my ($self, at param) = @_;
> >         $pid = open $fh, "-|", "command @param";
> >         return ($pid, $fh);
> > }
> >
> > sub method
> > {
> >         my ($self, at param) = @_;
> >         ($pid, $fh) = $self->myopen(@param);
> >         # Rest of method
> > }
> >
> > And then in the test override myopen with a mock function.
>
> It is not clear from this, how exactly can you "override myopen with a
> mock function" so that it still returns a valid pid and a file handler.
>

So I guess you need to mock things all the way. Pass around a tied filehandle, 
and also use some wrappers (or mocked built-in functions) for the PID.

Regards,

	Shlomi Fish

> I think that the Ran solution with mocking open() has the same problem,
> how to return the valid file handler and the subprocess pid without
> actually running some real process, like "cat expected_output_file".
>
> Regards,
> Mikhael.

-- 

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage: http://t2.technion.ac.il/~shlomif/

I don't believe in fairies. Oops! A fairy died.
I don't believe in fairies. Oops! Another fairy died.




More information about the Perl mailing list