koo has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w # file somescript.pl use strict; use warnings; sub SubThatNeedsToBeTested { # do some stuff if ($error ) { print "error occurred\n"; exit 2; } if ($othererror) { print "another error occurred\n"; exit 3; } } sub NoNeedToTestThis { # ... } ## main program &SubThatNeedsToBeTested (); &NoNeedToTestThis (); exit 0;
I would like to write tests only for some functions, for example for SubThatNeedsToBeTested but not for NoNeedToTestThis.
Could this be achieved without restructuring the scripts ie moving functions like SubThatNeedsToBeTested to a separate module? Can I somehow load subs into my test script namespace without executing the main program part?
Some methods call exit $errorcode. Is there a way to trap this? I was thinking about eval, but it only traps die.
How would you test this without restructuring the scripts too much?
Thank you for your answers
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing parts of perl scripts
by ELISHEVA (Prior) on Feb 19, 2009 at 03:16 UTC | |
|
Re: Testing parts of perl scripts
by Tanktalus (Canon) on Feb 18, 2009 at 23:01 UTC | |
|
Re: Testing parts of perl scripts
by locked_user sundialsvc4 (Abbot) on Feb 19, 2009 at 03:44 UTC |