We've started doing test-driven development at my office, and that means writing lots of unit tests.

My current task involves taking a bunch of pre-existing, scattered code and turning it into a module.

There are a lot of built-in calls in the code, and I'm not sure how to tackle them in the unit tests.

For example, for a call like this:

unlink( $filename );

I would like to be able to have that call fail on a file that should be there, but isn't...as if someone had deleted the file while the program was running. Or perhaps it exists, but can't be deleted.

I am familiar with Test::MockModule and Test::MockObject and was hoping that there was a module that mocked built-in calls so that I could manipulate them in the same way. So far, my search-fu has failed me and I can not find such a module.

Likely, I am missing an obvious solution. Would someone care to enlighten me?


In reply to Unit testing built-in functions by aijin

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.