Test harness for scripts?

B

bwooster47

When creating Perl modules, there is Test::More and similar tools
available to automate the testing.

Are there general guidelines for writing test scripts that work with
the Test::Harness framework?

I noticed Test::Script - it offers one function -
"script_compiles_ok()"

But if I need more - what are some good practices for testing the full
script:

1) run script with --arg1 --arg2, check that STDOUT has a line with
"text line 1"
2) run script with --arg3 file, check that file was created (and then
clean up - remove it)
3) run script with --arg4, check that Unknown Arg error is thrown

One option is just to write the perl code to execute the above
commands, and do the checks. But how to run the command - "make test"
puts the script in blib/script, the script itself is in bin/, and
there may be a system installed old script version, so need to make
sure that the test is running the script from the development folder.

Any suggestions?
 
S

Sisyphus

When creating Perl modules, there is Test::More and similar tools
available to automate the testing.

Are there general guidelines for writing test scripts that work with
the Test::Harness framework?

Any file with a '.t' extension that's placed in the './t' folder will be
automatically run by 'make test'.
There are other options, too, but that's how most people create their test
scripts.

..
..
But how to run the command - "make test"
puts the script in blib/script, the script itself is in bin/, and
there may be a system installed old script version, so need to make
sure that the test is running the script from the development folder.

I don't think this is a consideration at all.
The test scripts themselves (ie the '.t' scripts in the './t' folder) don't
get put into blib - they stay where they are.
Also, 'make test' will find (and use) the files in blib *before* it goes
looking for files (in @INC) that have been installed into perl as a result
of an earlier build. (That is, if the file exists in blib, then that's the
one that 'make test' is going to use.)

Cheers,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top