Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

First, you might want to look at How a script becomes a module. The general idea is to convert most of the functionality of a script into a module, and test that as you would a module.

In general, for testing scripts, you need to write a test file that you can run with prove. In testing scripts, I've found IPC::Run3 to be helpful for driving inputs and outputs in a platform independent way. E.g.

# file: use strict; use warnings; exit;
# file: dummy.t use strict; use warnings; use Test::More tests => 1; use IPC::Run3; my @cmd = qw( perl ); ok( run3( \@cmd ), "Running @cmd" );

prove -v dummy.t produces:

dummy....1..1 ok 1 - Running perl ok All tests successful. Files=1, Tests=1, 0 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 C +PU)

There you go -- a basic script test. All you need to do is keep adding to the test script (or create new ones), run it with prove, and then add code until it works, and you're doing TDD for scripts.

For helpers to test specific behavior or to help you write your own tests of specific behaviors, you might want to look at:

  • For file properties: Test::File (Actually, search CPAN for modules like "Test::File" and you'll see a variety of possibly useful test helpers for files.)
  • Creating temporary file and directories: File::Temp (You might find my own File::pushd useful in that regard, too.)
  • Driving interactive programs: Test::Expect

You may need to write new test helpers for things like process killing, or user changes, but you can either build that up with Test::More (or even write new Test:: modules with Test::Builder and release them to CPAN for all to use.)


Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

In reply to Re: Test driven development and glue code by xdg
in thread Test driven development and glue code by Eimi Metamorphoumai

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (7)
    As of 2021-03-04 19:32 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (107 votes). Check out past polls.