Welcome to the Monastery | |
PerlMonks |
Looking for help for unit tests and code coverage on an existing perl scriptby tizatron (Novice) |
on Jan 31, 2014 at 22:40 UTC ( [id://1072921]=perlquestion: print w/replies, xml ) | Need Help?? |
tizatron has asked for the wisdom of the Perl Monks concerning the following question:
Greetings,
Someone passed me a perl script to look at and I quickly realized that I needed to get a test around it. I had never used the Test::More module and I wanted to get some feedback, any tips and some comments. I watered down the script greatly. Essentially: The script accepts a hostname and spits out a list of classes. Here's the code:
So, now I want to wrap some cover and tests around this script. I wrote a little test.pl script as a first attempt.
Seems to run ok (no pun intended)
However, now I start to get the feeling that I am doing something wrong. I had to add a return() to the usage function to get that test to pass. Not sure if there is a better way to do that. I tried the run the code coverage ---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ sample.pl 100.0 n/a n/a 100.0 n/a 3.1 100.0 test.pl 100.0 n/a n/a 100.0 n/a 96.9 100.0 Total 100.0 n/a n/a 100.0 n/a 100.0 100.0 ---------------------------- ------ ------ ------ ------ ------ ------ ------ Ok - that really looks wrong. How can I have 100 percent code coverage? This is where I decided to take a break and do some research and study and make sure I driving in the right direction. So a couple of questions: 1. Quick review so far - what am missing? Is this the right setup? I understand that a lot of testing in perl works around modules. I just have a script to work with. My goal is to wrap some testing around what I have, and attempt to drive it to something more modular 2. How do I start testing the implied main? Any thoughts or comments welcomed.
Back to
Seekers of Perl Wisdom
|
|