Skip to content
This repository
branch: chromatic/lori…
Fetching contributors…

Cannot retrieve contributors at this time

file 87 lines (76 sloc) 1.908 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#! perl
# Copyright (C) 2001-2009, Parrot Foundation.

use strict;
use warnings;

use Test::More tests => 1;
use Carp;
use Tie::File;

my @pdddirs = qw(
./docs/pdds
./docs/pdds/draft
);

my @pddfiles = ();
foreach my $dir (@pdddirs) {
    die "Directory '$dir' is not found, or not a directory" if not -d $dir;

    my @pdds = glob "$dir/pdd*.pod"
        or warn "No PDD files found in directory '$dir'";

    push @pddfiles, @pdds;
}

my @diagnostics = ();
foreach my $pdd (@pddfiles) {
    my $diag = check_pdd_formatting($pdd);
    if ( $diag ) {
        push @diagnostics, $diag;
    }
}

for my $msg (@diagnostics) {
    diag($msg);
}
cmp_ok( scalar(@diagnostics), '==', 0, 'PDDs are formatted correctly' );

sub check_pdd_formatting {
    my $pdd = shift;

    my $diag = q{};
    my @toolong = ();
    my @sections_needed = qw(
Version
Abstract
Description
Implementation
References
);
    my %sections_seen;
    my @lines;
    tie @lines, 'Tie::File', $pdd
        or croak "Unable to tie to $pdd: $!";
    for (my $i=0; $i<=$#lines; $i++) {
        if (
            ( length( $lines[$i] ) > 78 )
            and
            ( $lines[$i] !~ m/^(?:F|L)<|<http|\$Id:\s+/ )
        ) {
            push @toolong, ($i + 1);
        }
        if ( $lines[$i] =~ m{^=head2\s+(.+?)\s*$} ) {
            $sections_seen{$1}++;
        }
    }
    untie @lines or croak "Unable to untie from $pdd: $!";
    if ( @toolong ) {
        $diag .=
            qq{$pdd has } .
            scalar(@toolong) .
            qq{ lines > 78 chars: @toolong\n};
    }
    foreach my $need (@sections_needed) {
        if ( ! $sections_seen{$need} ) {
            $diag .= qq{$pdd lacks 'head2' $need section\n};
        }
    }
    return $diag;
}

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
Something went wrong with that request. Please try again.