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.

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.

Comment on Looking for help for unit tests and code coverage on an existing perl script

Given that you're really just testing output from your script, Test::Output seems like a good choice; however, although you've loaded that module, you haven't used any of its functionality.

When I read "return $heredoc;", I wondered what this was for (it seemed pointless).
I do see that you've questioned this yourself: "I had to add a return() to the usage function to get that test to pass ...".
If your tests identify logic errors (or similar) in the code you're testing, then do fix the code;
however, don't add questionable code just to make the tests pass.

I was able to spit out some code coverage numbers. I am going to try spend some time on this path and see I can get it to fly on my test script. But I need to dig in a little more and see if Test::Output aligns with Devel::Cover like I hope it does.

I would extract a module from your script and unit test the module
directly via Test::More and the prove command.
I like to keep my script mainlines as short as is practicable,
with all the heavy lifting done in (unit-tested) module/s.
There are many examples of this general approach on the CPAN;
see, for example, the perltidy command,
part of the Perl-Tidy distribution
and the perlcritic command, part of the Perl-Critic distribution.

As an alternative, and perhaps a bit less work, you could
re-structure your script as a "modulino", that is, a script
that can masquerade as a module for ease of testing.
This approach is described at:

That processes pumps out a cover.html file that kinda aligns more with what I was hoping to see. The changes to the original code are not significant, but they are changes, more than what I was hoping to make, perhaps digging in harder on Test::Output would help.