Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

"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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-16 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found