Author: particle
Date: Wed Feb 7 11:17:54 2007
New Revision: 16916
Added:
trunk/t/codingstd/c_struct.t (contents, props changed)
Modified:
trunk/MANIFEST
Log:
[PDD07]: coding standard tests for C source
~ Structure types must have tags
30 failing tests
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Wed Feb 7 11:17:54 2007
@@ -2581,6 +2581,7 @@
t/codingstd/c_code_coda.t []
t/codingstd/c_indent.t []
t/codingstd/c_parens.t []
+t/codingstd/c_struct.t []
t/codingstd/cppcomments.t []
t/codingstd/cuddled_else.t []
t/codingstd/fixme.t []
Added: trunk/t/codingstd/c_struct.t
==============================================================================
--- (empty file)
+++ trunk/t/codingstd/c_struct.t Wed Feb 7 11:17:54 2007
@@ -0,0 +1,66 @@
+#! 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/c_struct.t - checks for struct tags in C source and headers
+
+=head1 SYNOPSIS
+
+ # test all files
+ % prove t/codingstd/c_struct.t
+
+ # test specific files
+ % perl t/codingstd/c_struct.t src/foo.c include/parrot/bar.h
+
+=head1 DESCRIPTION
+
+Checks that all C source files use struct tags, as defined in PDD07.
+
+=head1 SEE ALSO
+
+L<docs/pdds/pdd07_codingstd.pod>
+
+=cut
+
+my $DIST = Parrot::Distribution->new;
+my @files = @ARGV
+ ? $^O eq 'MSWin32' ? <@ARGV> : @ARGV
+ : $DIST->get_c_language_files();
+my @struct;
+
+for my $file (@files) {
+ my $path = ref $file ? $file->path : $file;
+
+ open my $fh, '<', $path
+ or die "Cannot open '$path' for reading: $!\n";
+
+ my $count;
+ my $message = qq< $path:>;
+ while (<$fh>) {
+ next unless /\bstruct\s+{/;
+ $count++;
+ $message .= " $.";
+ }
+ push @struct => "$message\n"
+ if $count;
+ close $fh;
+}
+
+# L<PDD07/Code Structure/=item Structure types must have tags>
+ok( !scalar(@struct), "structure types must have tags" )
+ or diag( "struct without tag found in " . scalar @struct . " files:[EMAIL
PROTECTED]" );
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4: