# New Ticket Created by  "John J. Trammell" 
# Please include the string:  [perl #39761]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=39761 >


Found in docs/pdds/pdd07_codingstd.pod:

        All indentation must consist of spaces, no tabs (for ease of
        patching).

This test looks for tabbed indents in source code and header files.

#! perl
# Copyright (C) 2001-2006, The Perl Foundation.

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
use Parrot::Distribution;


=head1 NAME

t/codingstd/tabs.t - checks for tab indents in C source and headers

=head1 SYNOPSIS

    % prove t/codingstd/tabs.t [file ...]

=head1 DESCRIPTION

Checks that the indicated file(s) do not use tabs to indent.

If no file(s) are specified, checks the Parrot C source and header files for
tab indents.

=head1 SEE ALSO

L<docs/pdds/pdd07_codingstd.pod>

=cut


my @files = @ARGV ? @ARGV : source_files();

plan tests => scalar @files;

foreach my $file (@files) {
    open FILE, "<$file" or die "Unable to open '$file' for reading: $!";

    my @tabs;
    LINE:
    while (<FILE>) {
        next unless /^ *\t/;
        push @tabs, "tab in leading whitespace, file '$file', line $.\n";
        if (@tabs >= 5) {
            push @tabs, "skipping remaining lines (you get the idea)\n";
            last LINE;
        }
    }
    close FILE;

    is(scalar(@tabs), 0, "file '$file' does not use tabs")
      or diag(@tabs);
}

sub source_files {
    my $dist = Parrot::Distribution->new;
    return map { $_->path } (
        map($_->files_of_type('C code'),   $dist->c_source_file_directories),
        map($_->files_of_type('C header'), $dist->c_header_file_directories),
    );
}

## vim: expandtab sw=4
Index: MANIFEST
===================================================================
--- MANIFEST    (revision 13197)
+++ MANIFEST    (working copy)
@@ -981,6 +981,7 @@
 t/examples/namespace.t                            []
 t/codingstd/cppcomments.t                         []
 t/codingstd/fixme.t                               []
+t/codingstd/tabs.t                                []
 config/inter/shlibs.pm                            []
 config/inter/types.pm                             []
 config/inter/encoding.pm                          []

Reply via email to