I just noticed Test::Cmd on CPAN. It looks ludicrously powerful. Possibly overkill for most people, but you could probably wrap it.

There's also some work I did for the Good Folks at Mitel Network Server Solutions (if that's a mouthful, just say "E-Smith") which is fortunately GPL'd. If you can get a copy of their e-smith-test.srpm you'll find the esmith::TestUtils library with a little thing called simulate_perl_program(). It will "run" a perl script but not as a seperate process.

This is for the case where you have a perl script you wish to test but have to change something about it in order to make it testable. For example, maybe it uses a database, you want it to use a test database but there's no easy way to change where it connects to. You can wrap DBI::connect() to alter the database connection, then call simulate_perl_program(). The program's code calls DBI->connect, it hits your wrapper, swaps out the hardcoded name with the name of the test database and passes it through to the real DBI test.

Something like:

use DBI; { my $real_connect = DBI->can('connect'); no warnings 'redefine'; local *DBI::connect = sub { my($self, $ds, $user, $pass, $attr) = @_; $ds =~ s/yourdb/testdb/; $self->$real_connect($ds, $user, $pass, $attr); }; my $exit = simulate_perl_program('yourprogram.plx', @args); }

Additionally, if you're using Test::Inline, $_STDOUT_ and $_STDERR_ from simulate_perl_program() are simply trapped like always.

If someone has the tuits, it would be nice to see this taken out of e-smith-test and put on CPAN. I've temporarily mirrored ESmith::TestUtils


In reply to Re: Test module to assist sytem() by Anonymous Monk
in thread Test module to assist sytem() by axelrose

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.