[Israel.pm] Alternative for catching return value

Omer Zak omerz at actcom.co.il
Mon Nov 14 04:35:45 PST 2005


The problem calls for a macro with roughly the following signature
(I do not know if or how to write it in legal Perl 5 or whether a module
is needed to rewrite code):

$ret = eval_gravely_ill({function call to be evaluated},
                      (list of return values which do NOT cause death),
                      "error message for die");

The overall effect will be return values, which are errors, will cause
the script to die.  However, return values, which are not errors, will
be returned in $ret.

It may be desirable to find a way to extend eval_gravely_ill to
accommodate a list of return values which cause death (complement of the
above) or call a function (predicate) to check if the actual return
value should cause the script to die.

On Mon, 2005-11-14 at 14:24 +0200, David Baird wrote:
> > eval {$sysUnderTest->someAction($foo, $bar, foo, bar)};
> > die $@ if $@
> >
> > Will work if $sysUnderTest->someAction() trys to die if it fails.
> > This should be the same as throwing a C++ exception
> 
> Since the methods call return their error codes in their return value,
> this approach will not work. The module for the $sysUnderTest object
> is already written, and the convention for returning errors already
> established. I am seeking a simpler way of catching them in the test
> scripts, which less than optimally skilled people will write and
> maintain.
                                       --- Omer
-- 
Sent from a PC running a top secret test version of Windows 97.
My own blog is at http://www.livejournal.com/users/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html




More information about the Perl mailing list