add and change NEWS for 2.8.0 release
[parrot.git] / t / codingstd / c_struct.t
blob81103655295d1f5ebef8298c74d501edb70fff3f
1 #! perl
2 # Copyright (C) 2006-2009, Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More tests => 1;
9 use Parrot::Distribution;
11 =head1 NAME
13 t/codingstd/c_struct.t - checks for struct tags in C source and headers
15 =head1 SYNOPSIS
17     # test all files
18     % prove t/codingstd/c_struct.t
20     # test specific files
21     % perl t/codingstd/c_struct.t src/foo.c include/parrot/bar.h
23 =head1 DESCRIPTION
25 Checks that all C source files use struct tags, as defined in PDD07.
27 =head1 SEE ALSO
29 L<docs/pdds/pdd07_codingstd.pod>
31 =cut
33 my $DIST = Parrot::Distribution->new;
34 my @files = @ARGV ? <@ARGV> : $DIST->get_c_language_files();
35 my @struct;
37 for my $file (@files) {
38     my $path = ref $file ? $file->path : $file;
40     open my $fh, '<', $path
41         or die "Cannot open '$path' for reading: $!\n";
43     my $count   = 0;
44     my $message = qq<  $path:>;
45     while (<$fh>) {
47         # we're only interested in lines with structs
48         next unless /\btypedef\s+struct\s+{/;
50         $count++;
51         $message .= " $.";
52     }
53     push @struct => "$message\n"
54         if $count;
55     close $fh;
58 # L<PDD07/Code Structure/=item Structure types must have tags>
59 ok( !scalar(@struct), "structure types must have tags" )
60     or diag( "struct without tag found in " . scalar @struct . " files:\n@struct" );
62 # Local Variables:
63 #   mode: cperl
64 #   cperl-indent-level: 4
65 #   fill-column: 100
66 # End:
67 # vim: expandtab shiftwidth=4: