The script runs a handful of root-owned commands and parses the output to gather information into a reporting system.

For my own sake I'd like to add some basic automated tests which make it simple to run this and other scripts as a non-root user, both for development purposes, and to have some regression tests in place.

It's code I currently control, so refactoring is an option, but I'd rather avoid refactoring something which works into something that imposes what may be perceived as pointless complexity on future custodians.

So, I was hoping for was a module someone had already written, or a simple trick, which could do this fairly transparently and effortlessly.

By the way, thanks for the suggestions so far, it's always educational to ask for help. I quite like the PATH idea, and overriding readpipe is in fact doable in the same way as it is for system, but a quick experiment suggests that it's not that easy to change the behaviour of backticks:

$ perl -le 'BEGIN { *CORE::GLOBAL::readpipe = sub { print "hello $_[0 +]" } } readpipe "foo"; `bar` ' hello foo

In reply to Re^2: mocking or trapping system calls by wu-lee
in thread mocking or trapping system calls by wu-lee

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.