Don't ask to ask, just ask | |
PerlMonks |
Re: Needing help on testingby davido (Cardinal) |
on Oct 30, 2018 at 00:25 UTC ( [id://1224895]=note: print w/replies, xml ) | Need Help?? |
It doesn't take a tremendous amount of work to convert a script into a modulino. And by so doing, if there are any subroutines within those scripts, they would become testable more in isolation. I wouldn't put the level of work into the category of rewrite, more in the category of refactor, and often it's a pretty simple refactor. Consider the following script:
In its current form you would have to invoke the script, and this can be done from within a test, capturing the output and even providing input. But it's not ideal. Let's convert it to a modulino.
Now you can test it more easily:
The testing code is untested. ;) Now you've tested at least minimally each of the main components except for main() itself, and if you wanted to, you could do that too. And all it required was adding the main() unless caller();, wrapping the top level code in a main subroutine, and putting a 1; at the end of the modulino. It really adds about four or five lines of code, and some indenting. You could almost write a script to apply it to all your scripts, and then to do a compile-check to verify they still compile. Keep backups of the original, unaltered scripts, though. ;) Dave
In Section
Seekers of Perl Wisdom
|
|