Skip to content
This repository
tag: RELEASE_1_7_0
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 97 lines (87 sloc) 2.243 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 88 89 90 91 92 93 94 95 96
#! perl
# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$

use strict;
use warnings;

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

my $cwd = cwd();
my @pdddirs = (
    qq{$cwd/docs/pdds},
    qq{$cwd/docs/pdds/draft},
);

my @pddfiles = ();
foreach my $dir (@pdddirs) {
    opendir my $DIRH, $dir
        or croak "Unable to open directory handle: $!";
    my @pdds = map { qq|$dir/$_| } grep { m/^pdd\d{2,}_.*\.pod$/ }
        readdir $DIRH;
    closedir $DIRH or croak "Unable to close directory handle: $!";
    push @pddfiles, @pdds;
}

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

my $errmsg = q{};
if ( @diagnostics ) {
    $errmsg = join ("\n" => @diagnostics) . "\n";
}

$errmsg ? fail( qq{\n$errmsg} )
        : pass( q{All PDDs are formatted correctly} );

sub check_pdd_formatting {
    my $pdd = shift;
    my $base = $pdd;
    if ($pdd =~ m{((draft/)?[^/]+)$}) {
        $base = $1;
    }
    my $diag = q{};
    my @toolong = ();
    my @sections_needed = qw(
Version
Abstract
Description
Implementation
References
);
    my %sections_seen = map { $_, 0 } @sections_needed;
    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);
        }
        foreach my $need ( @sections_needed ) {
            $sections_seen{$need}++ if $lines[$i] =~ m{^=head2\s+$need};
        }
    }
    untie @lines or croak "Unable to untie from $pdd: $!";
    if ( @toolong ) {
        $diag .=
            qq{$base has } .
            scalar(@toolong) .
            qq{ lines > 78 chars: @toolong\n};
    }
    foreach my $need ( keys %sections_seen ) {
        if ( ! $sections_seen{$need} ) {
            $diag .= qq{$base 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.