Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Embedded test

by gam3 (Curate)
on Mar 10, 2007 at 02:50 UTC ( [id://604097]=note: print w/replies, xml ) Need Help??


in reply to Embedded test

The perl test framework is very flexable and you can do almost anything you want in it.
# here is a valid test file print "1..2\n"; print "ok 1\n"; print "ok 2\n";
So you can have as many (or as few) test files as you want, and you can test anything in those files.
Test::More is a very good test modules with lots of different funtions to test output. There might be a Test module that is designed to test scripts.
I can see 2 ways to do this. You can either use Open3 to run the script and test the output, or tie PRINT and do the script. The first is likely easier, but the second would give you some more control.
Good luck and have fun.
Update Test::Script might have some good ideas on how to test scripts.
-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re^2: Embedded test
by Sixtease (Friar) on Mar 10, 2007 at 17:02 UTC

    Thank you for the answers.

    I've had a look at Test::Inline and I have some things unclear. I started with this module (For_test.pm):

    package For_test; use strict; sub two { return 2; } sub three { return 4; } =begin testing ok(two() == 2); ok(three() == 3); =end testing =cut 1

    I created inline2test.conf:

    input=. output=t verbose=1

    The I run perl t/for_test.t which tells me it can't find &main::two. It only helps if I manually add use For_test; to the test script and qualify the testing commands to look like

    ok(For_test::two() == 2); ok(For_test::three() == 3);

    This must surely be wrong - I don't think I should touch the generated test scripts. Also, if I got to where I actually wanted -- to testing *.pl files, not modules, I'd have a hard time supplying the needed use statement.

    What caught my eye was the Open3 module. It looks like it could do what I want but I thought I'd try to find an existing solution before writing my own testing suite. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://604097]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found