Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

BooK (2612)

  {book} {at} {}
Yahoo! ID: philippe_bruhat (Add User, Send Message)

Obfuscation []. Pink []. HTTP::Proxy []. YEF []. Fishnet []. Kapow []. Cog's [] bitch []. Invitation []. White [] Camel []. Nuff' said.

Journal of BooK (2612)

Tuesday March 22, 2005
07:22 PM

Use cases

[ #23801 ]

I discovered a nice testing technique while coding my ever useless module (Acme::MetaSyntactic). I had trouble defining the API, so I finally wrote down 5 or 6 sample scripts. They all did the same thing, using the API in a different way.

What's nice is that it's quite easy to test that all the use cases behave in the same way:

use Test::More;
use File::Spec::Functions;

my @cases = glob catfile qw( t cases case* );

plan tests 2 * @cases;

for my $case (@cases) {
    # you can add more command-line options
    my $result = `$^X -Mblib -Mstrict -w $case`;
    is( $? >> 8, 0, "$_ ran successfully" );
    # and the tests for $result can be fancier
    is( $result, "whatever's expected", "result" );

As a bonus, there is no need to update the tests when adding a new testcase!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • my $result = `$^X -Mblib -Mstrict -w $case`;

    To be 100% portable, that's...

            my $result = `$^X "-Mblib" "-Mstrict" -w $case`;

    Why? VMS downcases anything not in quotes.