Author: Peter MakholmPeter Makholm Date: Mar 27, 2008 00:06
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.
|