Am I right in thinking that the only way to test each individual sub would be to create a module eventhough if the code is not re-usable by any other scripts
No. There are as many other ways to test as your imagination can dream up.
You could for example, use a command line switch that when supplied causes a different main-like sub to be invoked in place of main.
...
if( $DEBUG ) {
debug_main()
}
else{
main();
}
## The rest of the code
And run the tests using perl -s TheScript.pl -DEBUG
Or using Smart::Comments something like:
...
### debug_main()
### exit;
main()
# the rest of the code
...
Now you run your tests using perl -MSmart::Comments TheScript.pl
And within debug_main() you can use any testing tools that you want. You could, for example, use the traditional ok(..) and not_ok( ... ), and then use the test harnesss or prove commands with an appropriate command line switch to perform white box testing.
You could even combine the two. Rather than having to structure your application to suit the test tools, you can structure your application in whatever way best suites its requirements, and use whichever combination of test methodologies best suit your needs.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|