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


Hi,

This patch gets code_coda.t to test for multiply-defined codas (for
those cases when a file append or automated tool adds a coda
unnecessarily).  I have a feeling it's not pretty code, but my perl
foo is only slowly improving.

Regards,

Paul

Files affected by this patch:
parrot/t/codingstd/code_coda.t
Index: t/codingstd/code_coda.t
===================================================================
--- t/codingstd/code_coda.t	(revision 14683)
+++ t/codingstd/code_coda.t	(working copy)
@@ -46,6 +46,7 @@
 my $DIST = Parrot::Distribution->new;
 my @files = @ARGV ? @ARGV : source_files();
 my @comments;
+my @coda_extras;
 
 foreach my $file ( @files ) {
     my $buf;
@@ -72,11 +73,36 @@
     # append to the comments array if the code doesn't match
     push @comments => "$path\n"
         unless $buf =~ m{\Q$coda\E\n*\z};
+
+    # make an array of the buffer's lines to pass to grep nicely
+    my @buf_lines = split m/\n/, $buf;
+
+    # check to see how often 'Local variables:' occurs
+    my $emacs_coda_count = grep m{
+                                  \* \s* Local \s* variables: \s*
+                                  }gxms, @buf_lines;
+    
+    # check to see how often 'vim:' occurs
+    my $vim_coda_count = grep m{ 
+                                \* \s* vim: \s*
+                                }gxms, @buf_lines;
+
+    # if either the emacs or vim coda is found more than once, record the
+    # file name
+    print "emacs coda count: ", $emacs_coda_count, "\n";
+    if (($emacs_coda_count > 1) || 
+        ($vim_coda_count   > 1)) {
+        push @coda_extras => "$path\n";
+    }
 }
 
+# check that the coda exists
 ok(!scalar(@comments), 'C code coda')
     or diag("C code coda missing in ".scalar @comments." files:[EMAIL PROTECTED]");
 
+# check for extra emacs/vim codas
+ok(!scalar(@coda_extras), 'C code coda')
+    or diag("C code coda repeating in ".scalar @coda_extras." files:[EMAIL PROTECTED]");
 
 exit;
 
@@ -94,4 +120,9 @@
     );
 }
 
-## vim: expandtab sw=4
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Reply via email to