Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Devel::Cover for myfile.pl with different command-line input arguments

by tito80 (Novice)
on Aug 22, 2016 at 19:08 UTC ( [id://1170195]=perlquestion: print w/replies, xml ) Need Help??

tito80 has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks,

I am a newbie and pardon my ignorance. I am trying to use Devel::Cover (DC) to get an idea of the code coverage of my my_file.pl ran with arg1 arg2, etc. as command-line input arguments. I am using Perl 5.8.9 with 1.23 DC. The steps I executed successfully to generate the html file are:

1) perl -MDevel::Cover my_file.pl -arg1 <arg1_value> -arg2 <arg2_value>

2) Devel-Cover-1.23/bin/cover cover_db --report=html

Now, I do not have packages/modules to test directly. But I have the my_file.pl file which invokes several packages.

And I need to test my_file.pl with several different combinations of command line i/p arguments (i.e. <arg1_different_value1>, <arg2_different_value_2>, etc.). All these test combinations are a part of my regression suite (you can think of the options written in a test.txt file sequentially) and I am trying to see if Devel::Cover can assure that I have 100% code coverage with these tests.

While I can run the above in a for-loop, each time with different arguments, I am not sure if that is the best way since I will end up with 100's of html/report files that need to be merged for any meaningful purpose.

Could you kindly provide some pointers?

Thanks, Tito

Replies are listed 'Best First'.
Re: Devel::Cover for myfile.pl with different command-line input arguments
by Mr. Muskrat (Canon) on Aug 22, 2016 at 22:03 UTC

    You could go the route you described and call your script from another script (bash/batch/perl/whatever) that loops through the different parameters but also passes a unique value for the coverage db (based on the arguments, pid, or whatever).

    The invocation of Devel::Cover would be slightly different: perl -MDevel::Cover=-db,cover_db-<unique value> my_file.pl -arg1 <arg1_value> -arg2 <arg2_value>.

    When all of the calls to your script are done, you'd simply call the cover script passing a wildcard for the coverage database like cover -report=html cover_db-*

      Mr. Muskrat, thanks. This definitely helped.

      But I am not very sure on the coverage by Devel::Cover itself. I have legacy code. For e.g., we use a certain Perl custom-developed package which is basically a wrapper around Perl GetOpt. When I pass an option arg1 = "abc" 1st time, and then arg1="xyz" the 2nd time, and I have code like: if ($run eq "abc") {do_this} else {do_that}.

      I expected devel_cover to show me the if-loop covered 1st time. Else-loop uncovered. While vice versa in the 2nd run.

      It did not. I hope I am not missing anything.

        If you test coverage with the first condition and then generate a report it should show the if was covered. If you test coverage with the second condition and then generate a report it should show that the else was covered. If you test coverage of both conditions and then generate the report (as I described in my previous reply) then it should show both the if and the else have been covered.

Re: Devel::Cover for myfile.pl with different command-line input arguments
by TomDLux (Vicar) on Aug 23, 2016 at 15:48 UTC

    The common usage of Devel::Cover is to determine whether the tests cover all the code. So why not run your code from a set of tests, with each using different combinations of command line options? That way, you can run the tests again any time you make a major change.

    It's one thing to say, 'we used the --verbose options, therefore line 67 was invoked'; how does the --verbose option modify data structures? Is there some side effect you can verify in test?

    Rather than running the whole program, is it possible to treat it as a module, and just invoke one subroutine at a time? That makes testing a lot simpler.

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1170195]
Approved by Perlbotics
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found