Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How do you test end-user scripts?

by Anonymous Monk
on Sep 06, 2010 at 00:53 UTC ( [id://858958]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've been using Test::Simple, Test::More, and the 'prove' command for writing/running test cases for my modules. But what is the Best Practice for testing end-user facing scripts? Should I write test cases which calls foo.pl via system()/open()/etc, feed it input, and see what comes out with regular expressions? Assume for the sake of argument that foo.pl operates in a unix-y way (ie, not interactive, takes in some input from stdin, does magic, and writes output to stdout).

Replies are listed 'Best First'.
Re: How do you test end-user scripts?
by eyepopslikeamosquito (Archbishop) on Sep 06, 2010 at 08:28 UTC

    I endorse chromatic's comment. When writing scripts, I typically abstract the work they do into CPAN-like modules and unit test each module using Test::More and the prove command. I strive to keep my script mainlines as short as is practicable. There are many examples of this approach on the CPAN; see, for example, the perltidy command, part of the Perl-Tidy distribution and the perlcritic command, part of the Perl-Critic distribution.

    See also: Effective Perl Programming, 2nd edition: Item 91, "Write programs as modulinos for easy testing"

      I claim that isn't enough.

      If you bring in your car in, would you be satisfied if they just tested the battery, the steering, the transmission, etc, but never actually tried to drive the car and see if it runs? All individual components of you car may work according to the spec, but if they aren't connected correctly, you will still have to walk.

      Heck, for complete products, I'd say testing the final product is way more important than any unit testing.

Re: How do you test end-user scripts?
by GrandFather (Saint) on Sep 06, 2010 at 01:32 UTC

    That would amount to black box testing, which is fine if that is what you want. The white box technique is to require scripts so you can access individual subs that you want to test.

    True laziness is hard work
Re: How do you test end-user scripts?
by snoopy (Curate) on Sep 06, 2010 at 02:42 UTC
    >>Assume for the sake of argument that foo.pl operates in a unix-y way (ie, not interactive, takes in some input from stdin, does magic, and writes output to stdout)

    If you do decide to run your scripts, you might want to look at Test::Script::Run.

    I'm using it to write tests that run on various Unixes.

    I've also experimentally tried it on Windows; seems to work there as well.

Re: How do you test end-user scripts?
by chromatic (Archbishop) on Sep 06, 2010 at 06:46 UTC

    You may not want to go to this much work, but I've had good experiences extracting modules from scripts and testing those modules directly.

Re: How do you test end-user scripts?
by Khen1950fx (Canon) on Sep 06, 2010 at 07:07 UTC
    I wrote this test to see if my script would compile and run. I used Test::Script. Run it with Devel::SmallProf like this
    perl -d:SmallProf test.pl
    When its done, look in the Cwd for smallprof.out.
    #!/usr/bin/perl use strict; use warnings; use Test::Script; use Test::More tests => 2; script_compiles( 'blib/script/test.pl', 'Main script compiles' ); script_runs( 'blib/script/test.pl', 'Main script runs' );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found