Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Dealing with exit in a Modulino
Hello,

I am writing tests for a CPAN module, which contains a script.
I found it convenient to make this script a Modulino, so that
I could 'use' it from my test.pl (thus being sure I use the same
perl, the same context etc.)
Now, this script does call exit in different places, which is not
suitable for my purpose.
The solution I used so far strikes me as inelegant:

- pass a $noexit when calling from make test
- replace everywhere:
exit $rc
with
($noexit ? return $rc : exit $rc)

There is even a signal handler...

Marc

Report this thread to moderator Post Follow-up to this message
Old Post
Marc Girod
03-27-08 12:10 AM


Re: Dealing with exit in a Modulino
Marc Girod <marc.girod@gmail.com> writes:

> I am writing tests for a CPAN module, which contains a script.
> I found it convenient to make this script a Modulino, so that
> I could 'use' it from my test.pl (thus being sure I use the same
> perl, the same context etc.)
> Now, this script does call exit in different places, which is not
> suitable for my purpose.

For testing purposes you can override the exit function to do
something else. I would probaly do something like:

sub My::Module::exit {
die "exit called with return code $_[0]\n";
}

My::Module::somefunction();

is($@, "exit called with return code 1",
"somefunction exited as expected");

For an even better test you could have your overridden exit function
note where it was called from. If you need to override exit globally,
and not just within you My::Module, you can use CORE::GLOBAL::exit
instead of My::Module::exit.

You are using Test::More or another Test::Harness module to du you
testing, right?

> The solution I used so far strikes me as inelegant:
>
> - pass a $noexit when calling from make test
> - replace everywhere:
>     exit $rc
>   with
>     ($noexit ? return $rc : exit $rc)

This wouldn't work well if you code actually expects to exit when it
calls exit().

//Makholm

Report this thread to moderator Post Follow-up to this message
Old Post
Peter Makholm
03-28-08 12:12 AM


Re: Dealing with exit in a Modulino
On Mar 27, 7:06 am, Peter Makholm <pe...@makholm.net> wrote:

> For testing purposes you can override the exit function to do
> something else. I would probaly do something like:
...

Thanks. That's exactly the kind of answer I was hoping for.

> You are using Test::More or another Test::Harness module to du you
> testing, right?

Right. Test::More for now.

Marc

Report this thread to moderator Post Follow-up to this message
Old Post
Marc Girod
03-29-08 12:03 AM


Re: Dealing with exit in a Modulino
On Mar 28, 4:38 pm, Marc Girod <marc.gi...@gmail.com> wrote:

> Thanks. That's exactly the kind of answer I was hoping for.

Sorry, I had left my critical spirit home.
The problem is then: how to return to the caller context
(when there is one, i.e. when I do not choose to exit),
instead of to the caller of my exit subroutine?

Some kind of exception mechanism.

Thanks,
Marc

Report this thread to moderator Post Follow-up to this message
Old Post
Marc Girod
03-30-08 12:11 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Language Moderated group archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:46 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.