Testing Ponie

petdance on 2003-07-18T19:09:05

Ponie has renewed my faith in the Perl 6 effort. I've never been comfortable with the idea of Perl 6 being two, two, two projects in one: Perl 6 and Parrot. Now we can have two separate and distinct goals.

Having Ponie and Parrot as two deliverables means we can have twice the faith in the correctness of the code. Without this setup, we might not know if a problem lies with Parrot or Perl 6. Now, we'll be able to isolate some of our problems.

Once I started thinking about the project (and talking with Leon Brocard over gin & tonics), I realized how much automated testing would be required to verify that Ponie works as advertised. I put on my Testing Evangelist hat and started hatching plans for how to make use of the existing Perl 5 tests, as well as the tests for the top 20% of CPAN (following the 80/20 rule), to help verify the correctness of Ponie. Not all modules have great test suites, so I'm going to work with those authors to see how we can beef them up, and increase the coverage, both for the module and for Ponie.

Automated testing is a low-cost, high-payback benefit. Cycles are cheap, and it makes sense to let the machine be watching over your shoulder as much as possible. I'd like to see daily, or even hourly, builds of Ponie to make sure that nothing's been broken.

(Mirrored at http://www.oreillynet.com/pub/wlg/3520)


I'm gonna hate myself in the morning but...

SparkeyG on 2003-07-18T19:28:10

Andy, I'll help you in this. I am interested in contributing something other than book reviews.

Top 20% of CPAN?

IlyaM on 2003-07-19T08:47:37

I'm just curious how you are going to find what modules are in top 20%. This list could be interesting on its own.

Re:Top 20% of CPAN?

Matts on 2003-07-19T15:55:07

Kobesearch is a good place to start. They keep stats on their downloads.

Re:Top 20% of CPAN?

petdance on 2003-07-19T21:22:15

Leon has some ideas that make use of Module::CPANTS. However, I'm more concerned about getting a rough idea than any sort of mathematical certainty. Even if we have to guess, that'll do.

Tests

drhyde on 2003-07-22T20:42:01

OK, so it's not one of the top modules, but if you have any suggestions for a sane way to test File::Find::Rule::Permissions, I'm all ears.

Re:Tests

petdance on 2003-07-23T22:33:07

First off, throw away test.pl. Create a t/ directory.

Here's t/readable.t to check that the permissions actually work for the current user at least.

use warnings;
use strict;

use Test::More tests => 3;
use_ok( 'File::Find::Rule::Permissions' );

# Could easily check all 512 possibilities
my @readable = qw( 777 644 600 700 400 );
my @unreadable = qw( 000 222 333 );

my $scratch = "t/scratch";

# Clean up any leftovers from previous tests
mkdir $scratch;
my @leftovers = <$scratch/*>;
chmod 0777, @leftovers;
unlink @leftovers;

# Create scratch files with proper modes
for my $perm ( @readable, @unreadable ) {
    my $filename = "$scratch/$perm";
    open FH, ">$filename" or die "Couldn't create $filename: $!";
    close FH;
    chmod oct $perm, $filename or die "Couldn't chmod $filename to $perm: $!";
}

TRY_READABLE: {
    # Which files can the 'nobody' user read in the current directory?
    my @wanted = sort map { "$scratch/$_" } @readable;
    my @actual = sort File::Find::Rule::Permissions->file()
          ->permissions( isReadable => 1 )
          ->in( $scratch );

    ok( eq_array( \@actual, \@wanted ), "Got all my readables" );
}

TRY_UNREADABLE: {
    # Which files can the 'nobody' user NOT read in the current directory?
    my @wanted = sort map { "$scratch/$_" } @unreadable;
    my @actual = sort File::Find::Rule::Permissions->file()
          ->permissions( isReadable => 0 )
          ->in( $scratch );

    ok( eq_array( \@actual, \@wanted ), "Got all the unreadables" );
}
Here's your t/load.t to just make sure everything loads OK:
use Test::More tests => 1;

use_ok( 'File::Find::Rule::Permissions' );
Here's your t/pod.t to test POD validity:
use Test::More;

use File::Spec;
use File::Find;
use strict;

eval {
    require Test::Pod;
};

my $ok = !$@ && ($Test::Pod::VERSION >= '0.95');

if (!$ok) {
    plan skip_all => "Test::Pod v0.95 required for testing POD";
} else {
    Test::Pod->import;
    my @files;
    my $blib = File::Spec->catfile(qw(blib lib));
    find( sub {push @files, $File::Find::name if /\.p(l|m|od)$/}, $blib);
    plan tests => scalar @files;
    foreach my $file (@files) {
        pod_file_ok($file);
    }
}

Does that get you going in the right direction?