Do They Compile?

Ovid on 2009-04-07T14:13:35

When you push more stuff into your compile time phase, it's great that compilation can warn you of serious problems. That's why when diddling with 'perl -pi.bak', I find variants of the following helpful:

$ ack '\$c->builder->add_main\(' lib/ -l|xargs perl -pi.bak -e 's/builder->add_main/add_to_builder/
$ for file in $(svn status |awk '/^M/ { print $2 }'); do perl -Ilib -c $file; done

Basically, did my global search/replace break my code? When your test suite takes well over an hour to run, this quick and dirty check is very useful.


One test to compile them all

petdance on 2009-04-07T14:44:04

We have a test in the test suite at Dev/perl.t that runs perl -c and tests POD on everything.

#!/usr/bin/perl -w

use warnings;
use strict;

use Test::More;
use Test::Pod;
use File::Next;
use App::Ack;

use FindBin;

my $startpath = $ENV{TTROOT} || '.';

my $iter =
    File::Next::files( {
        descend_filter  => sub { $_ ne '.svn' && $_ ne 'tmp' },
    }, $startpath );

my @files;

while ( my $file = $iter->() ) {
    my @types = App::Ack::filetypes( $file );
    push( @files, $file ) if grep { $_ eq 'perl' || $_ eq 'pod' } @types;
}

die 'No Perl files found!' unless @files;

plan( tests => 2 * @files );

my $lib = "$FindBin::Bin/../Lib";

for my $filename ( @files ) {
    open( my $fh, '<', $filename ) or die "Can't read $filename: $!";
    my $header = <$fh>;
    close $header;

    my $taint = $header && ( $header =~ /perl.+-T/ ) ? '-T' : '';
    my $output = qx( perl $taint -c -I$lib $filename 2>&1 );
    like( $output, qr/syntax OK/, "$filename passes perl -c" );

    pod_file_ok( $filename );
}

Re:One test to compile them all

Ovid on 2009-04-07T15:13:45

We have a virtually identical test. Takes four minutes to run. Hence the above snippet :)