Hello wanna_code_perl,

First I second what haukex said. If you have a library, a perl module, test what this module exports. The cli is just an interface.

Second: your example is not a modulino. A modulino is a perl module .pm file that can be invoked as a program via a trick. A modulino should end with the famous 1; or cannot be loaded.

If your is a modulino you can use it in your testing program and play with their subs, testing them as you wish.

In both cases, modulino or standalone script, you can test it somehow, using Capture::Tiny (without embarking yourself in a fight with Run3 modules.. ;). you can also launch the script and inspect the exit values.

Few example I have in some test on github something you can adapt:

use strict; use warnings; use Test::More; use Test::Exception; use Capture::Tiny qw(capture); ... # expected death my ($out, $err, @res) = capture { dies_ok { a_sub_that_dies() } 'expected to die without argumen +ts'; }; # verbosity check ($out, $err, @res) = capture { $obj->method( verbose => 2 ); }; ok ((split "\n", $out) > 30 , "30+ lines expected with verbosity = 2") +; # checking exit status (you can check 'perl your_modulino_or_script ar +g1 arg2..' ) my $exit = system "$program /? >nul 2>&1"; ok ( 16 == ($exit>>8), "[$program /? >nul 2>&1] returned the expected +value");

See also testing in my bibliotheca and Test::Script from CPAN.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Portably unit testing scripts by Discipulus
in thread Portably unit testing scripts by wanna_code_perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.