Stories
Slash Boxes
Comments
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
  {book} {at} {cpan.org}
http://paris.mongueurs.net/
Yahoo! ID: philippe_bruhat (Add User, Send Message)

Obfuscation [plover.com]. Pink [axis-of-aevil.net]. HTTP::Proxy [cpan.org]. YEF [yapceurope.org]. Fishnet [perl.org]. Kapow [cpan.org]. Cog's [perl.org] bitch [cpan.org]. Invitation [perl.org]. White [perl.org] Camel [perl.org]. 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.
 Full
 Abbreviated
 Hidden
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.