Your script is a front-end to the module you've written. You could move argument parsing into the module so that the binary (ie. script) *only* ever makes function/method calls to the module; the script does only its own basic logic. Then, the binary is irrelevant and you need not worry about testing it at all, less some compile checks.

pod2usage and other 'system' calls have their own tests written upon install, so you can almost certainly skip these. If you're that concerned, run a test to dump this output somewhere, then have a different, later test run POD and layout checks against the output of that sample file.

Anything that calls exit() can be caught with, like jcb said, a mock, or other forms of trickery (such as having a test file dump the output of a system call to an in-memory file, then check that). Note that you can run a script under system() and get actual return values.

Again, unless your script is a core part of your distribution (sounds like it isn't), make it as simple as possible. I might want to write my own because yours is too simple. Then, I can either use your publicized options() function/method, write my own for my own script, or utilize both yours append my own.

In the end, you don't really want to test the script anyways (where possible). You want to test what the script represents. The more you incorporate into the module(s), the less worry you have about testing the front-end script(s).


In reply to Re: Portably unit testing scripts by stevieb
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.