1

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

toolic
  • 57,801
  • 17
  • 75
  • 117
Woo Zhan Wei
  • 15
  • 1
  • 4

2 Answers2

1

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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Diab Jerius
  • 2,310
  • 13
  • 18
1

From the synopsis: https://metacpan.org/pod/Devel::Cover#SYNOPSIS

$ perl -I. -MDevel::Cover main.pl
$ cover

You'll also need to change your code a bit. You'll need "use" instead of "import" and "Halo->add" instead of "Halo.add". (These changes are nothing to do with Devel::Cover.)

pjcj
  • 421
  • 2
  • 3