Search code examples
perldevel-cover

Is there a need or how to write a test on main.pl which is not module and run it using Perl Devel cover


There are lots of material talking about writing coverage on module but how if I want to write a test for command runnable perl script (main.pl)?

Is there a need to write test for main.pl or I just need to write test for module will do?

Let's say I have these two scripts.

command runnable script

main.pl

import Halo;
&main;
sub main() {
    my $a = 2;
    my $b = 3;
    my $c = Halo.add($a, $b);
    print "a + b = $c\n";
}

==============================================

Perl module

Halo.pm

package Halo;
sub add() {
    my ($class, $a, $b) = @_;
    return $a + $b;
}
1;

==============================================

Run in command line:
perl main.pl


Solution

  • I suggest you research "unit" and "end-to-end" testing to understand the benefits of each. I would recommend that you do both. Testing your main script is easily done with "modulinos", allowing you to fairly painlessly tie into the existing Perl testing ecosystem.