Tuesday, July 28, 2009

Testing in Perl 6

So, here's my first hesitant step to building Perl test code (specifically Perl 6 in this case, but I've never used any of the Test modules for Perl 5, either).
#!/Users/sf/tools/rakudo/perl6
use v6;
use Test;
plan *;
run "rm as1-2092.step as1-A.step as1-B.step";
{
run "../step_extract.pl as1-tc-214.stp as1-2092.step 2092";
my $results = qx{diff -w -B proper-as1-2092.step as1-2092.step};
nok($results ~~ /\S+/, "Extracting styled_item using 2092");
}
{
run "../step_extract.pl as1-tc-214.stp as1-A.step 2092 2093 2094";
run "../step_extract.pl as1-tc-214.stp as1-B.step 2092-2094";
my $results = qx{diff -w -B as1-A.step as1-B.step};
nok($results ~~ /\S+/, "Extracting 2092-2094");
}
view raw gistfile1.txt hosted with ❤ by GitHub

Simple and short, but with it I learned a significant limitation of my STEP extract script and turned up a Rakudobug. All in all, a most successful first foray into testing Perl code.

Now all I need to do is figure out the proper directory structure, and how to automatically build a makefile with a "test" target, and get the hacked version of Test.pm which properly handles planless testing.

No comments:

Post a Comment