Mea Culpa - it wasn't a very clear description.
OK, so perhaps you have a script like this:
###myscript.pl###
doStuff();
doOtherStuff();
sub doStuff{
# things that need testing
}
sub doOtherStuff{
# things you don't want to run
}
__END__
and you don't have the option of wrapping the top level scope
('doStuff();doOtherStuff()') in 'if caller(){}' - maybe it's legacy
code that is running fine in production, and you don't want to modify
it.
The idea is your test script looks like this:
use Test::Import::DontRun qw(myscript.pl);
my $res = doStuff();
cmp_ok($res,"eq","Some or other value");
It works very simply, by wrapping the source of 'myscript.pl' in
"{last; <code> }'. There's some complex and potentially slightly
fragile stuff to handle @EXPORT if you want to, but the basic case
works pretty well.
I hope that's clearer. Feel free to say 'what a stupid idea' or 'that
won't work because' incidentally - but so far I've found it pretty
useful.
thanks,
Charles.
On 7 October 2010 09:02, nadim khemir <[email protected]> wrote:
> I must admit that I didn't get what you mean. Care to enlighten me with a
> piece of code, some flow, anything that doesn't make me feel stupid.
>
> Nadim.
>