# New Ticket Created by "Paul Cochrane" # Please include the string: [perl #40543] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=40543 >
Hi, This patch adds a test to the coding standards which checks for space or tab characters after a curly brace when the curly is the last printable character on the line. The pumpking hasn't explicitly declared that this should be a coding standard, but particle mentioned that it was a pet peeve, and I thought I might as well write a test :-) Regards, Paul
Index: MANIFEST =================================================================== --- MANIFEST (revision 14906) +++ MANIFEST (working copy) @@ -2445,6 +2445,7 @@ t/codingstd/c_code_coda.t [] t/codingstd/cppcomments.t [] t/codingstd/cuddled_else.t [] +t/codingstd/curly_space.t [] t/codingstd/fixme.t [] t/codingstd/linelength.t [] t/codingstd/perlcritic.t [] Index: t/codingstd/curly_space.t =================================================================== --- t/codingstd/curly_space.t (revision 0) +++ t/codingstd/curly_space.t (revision 0) @@ -0,0 +1,88 @@ +#! perl +# Copyright (C) 2006, The Perl Foundation. +# $Id$ + +use strict; +use warnings; + +use lib qw( . lib ../lib ../../lib ); +use Test::More tests => 1; +use Parrot::Distribution; + +=head1 NAME + +t/codingstd/curly_space.t - checks for space characters after trailing curly braces + +=head1 SYNOPSIS + + # test all files + % prove t/codingstd/curly_space.t + + # test specific files + % perl t/codingstd/curly_space.t src/foo.c include/parrot/bar.h + +=head1 DESCRIPTION + +Checks that files don't have space or tab characters after curly braces if +the curly is nominally the last character on the line. + +=head1 SEE ALSO + +L<docs/pdds/pdd07_codingstd.pod> + +=cut + +my $DIST = Parrot::Distribution->new; +my @files = @ARGV ? @ARGV : source_files(); +my @failing_files; + +foreach my $file (@files) { + my $buf; + my $path; + + ## get the full path of the file + # if we have command line arguments, the file is the full path + if (@ARGV) { + $path = $file; + } + + # otherwise, use the relevant Parrot:: path method + else { + $path = $file->path; + } + + # slurp in the file + open( my $fh, '<', $path ) + or die "Cannot open '$path' for reading: $!\n"; + { + local $/; + $buf = <$fh>; + } + + # append to the list of failing files if the code matches + push @failing_files => "$path\n" + if $buf =~ m{(\}|\{)[ \t]+$}m; +} + +ok( !scalar(@failing_files), 'No spaces after curlies' ) + or diag( "Space char found after curly brace in " + . scalar @failing_files . " files:[EMAIL PROTECTED]" ); + +exit; + +sub source_files { + return ( + map( $_->files_of_type('C code'), $DIST->c_source_file_directories ), + map( $_->files_of_type('C header'), $DIST->c_header_file_directories ), + map( $_->files_of_type('PMC code'), $DIST->pmc_source_file_directories ), + map( $_->files_of_type('Yacc file'), $DIST->yacc_source_file_directories ), + map( $_->files_of_type('Lex file'), $DIST->lex_source_file_directories ), + ); +} + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: