2 # Copyright (C) 2006-2009, Parrot Foundation.
7 t/codingstd/linelength.t - Test code lines length
12 % prove t/codingstd/linelength.t
15 % perl t/codingstd/linelength.t src/foo.c include/parrot/bar.h
19 Tests source files for the line length limit as defined in
20 F<pdd07_codingstd.pod>. Only files for some language implementations are
25 L<docs/pdds/pdd07_codingstd.pod>
31 use lib qw( . lib ../lib ../../lib );
34 use Test::More tests => 1;
35 use ExtUtils::Manifest qw( maniread );
37 use Parrot::Config qw/ %PConfig /;
39 my $num_col_limit = 100;
41 my $build_dir = $PConfig{build_dir};
42 my $manifest = maniread( File::Spec->catfile( $build_dir, 'MANIFEST' ) );
44 # skip files listed in the __DATA__ section
53 # find the files that we need to check
54 my @files = @ARGV ? <@ARGV> : source_files();
56 # check all the files and keep a list of those failing
59 my $lineinfo = info_for_first_long_line($_);
60 next unless $lineinfo;
61 push @lines_too_long => $lineinfo;
64 ## L<PDD07/Code Formatting/"Source line length is limited to 100 characters">
65 ok( !@lines_too_long, 'Line length ok' )
66 or diag( "Lines longer than coding standard limit ($num_col_limit columns) in "
67 . scalar @lines_too_long
69 . join( "\n", @lines_too_long ) );
71 sub info_for_first_long_line {
74 open my $fh, '<', $file or die "Can't open file '$file'";
75 while ( my $line = <$fh> ) {
77 $line =~ s/\t/' ' x (1 + length($`) % 8)/eg; # expand \t
78 next if $line =~ m/https?:\/\//; # skip long web addresses
79 next if $line =~ m/\$Id:/;
80 next if $line =~ m/CONST_STRING\(/;
82 return sprintf '%s:%d: %d cols', $file, $., length($line)
83 if length($line) > $num_col_limit;
90 foreach my $file ( sort keys(%$manifest) ) {
91 my $full_path = File::Spec->catfile( $build_dir, $file );
93 # skip files specified in __DATA__ section
94 next if exists $skip_files{$file};
96 push @files => $full_path
97 if $file =~ m{\.(c|pmc|ops|pod)$};
104 # cperl-indent-level: 4
107 # vim: expandtab shiftwidth=4:
110 # Lex and Bison generated
111 compilers/imcc/imclexer.c
112 compilers/imcc/imcparser.c
113 compilers/pirc/src/main.c
114 compilers/pirc/src/pirlexer.c
115 compilers/pirc/src/pirlexer.h
116 compilers/pirc/src/pirparser.c
117 compilers/pirc/src/pircompunit.h
118 compilers/pirc/src/pircompunit.c
119 compilers/pirc/src/pasm.l
120 compilers/pirc/src/pasm.y
121 compilers/pirc/macro/macro.h
122 compilers/pirc/macro/macrolexer.c
123 compilers/pirc/macro/macrolexer.h
124 compilers/pirc/macro/macroparser.c
125 compilers/pirc/macro/macroparser.h
126 compilers/pirc/src/hdocprep.l
127 compilers/pirc/src/hdocprep.c
130 # generated by tools/dev/nci_thunk_gen.pir
131 src/nci/core_thunks.c
132 src/nci/extra_thunks.c
133 # these ones include long POD