"My question is what is the directory where the test scripts are run?"

Well, look at it this way... when your module is popped open by the CPAN Testers, they base their operations (executions) of your tests from the top-level root directory of your module, so when tests are run, they typically see lib, t etc. underneath.

Your unit tests should always be under the t/ directory, and inside of a test file, you should always specify special locations from the location the test is being run *from*... that is, if you have Module/t/01-my_test.t, wanting to grab a baseline file from Module/t/data/baseline.conf, you'd reference it as t/data/baseline.conf.

It's really that simple. Write your tests from the perspective that they'll be run out of the parent directory of t/, and you'll be fine.

this is an example test file where I open a baseline comparison file from within t/orig. I do perform unlink in that test file... I could create tempfiles in t/data, lib/MyModule or wherever... just reference them as you're sitting in your module root dir (really, really avoid absolute paths... that's not portable at all).

To create, then unlink within a unit test, ensure you have any directory eg: t/data dir, then, after you've done your work (eg: open my $wfh, '>', 't/data/scrap.crap' or die $!;) at the end of your unit test (or at the end of the test file) do something like:

eval { unlink 't/data/scrap.crap' or die; }; is ($@, '', "unlink of scrap.crap ok");

Again... tests are run from your module root directory. When specifying a directory from within your test, act like you're in the directory above it. When running your unit tests, be in your module root dir, and do: perl t/01-mytest.t or make test. If your directories are off, you'll find out quickly.


In reply to Re: CPAN test scripts, "run" directory, and test data files by stevieb
in thread CPAN test scripts, "run" directory, and test data files by dallen16

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.