add and change NEWS for 2.8.0 release
[parrot.git] / t / codingstd / c_code_coda.t
blob90fdb56089fc77080bb505f2301a6150bcf6ac57
1 #! perl
2 # Copyright (C) 2006-2009, Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
8 use lib qw( . lib ../lib ../../lib );
9 use Test::More tests => 2;
10 use Parrot::Distribution;
11 use Parrot::Test::Util::Runloop;
13 =head1 NAME
15 t/codingstd/c_code_coda.t - checks for editor hint coda in C source
17 =head1 SYNOPSIS
19     # test all files
20     % prove t/codingstd/c_code_coda.t
22     # test specific files
23     % perl t/codingstd/c_code_coda.t src/foo.c include/parrot/bar.h
25 =head1 DESCRIPTION
27 Checks that all C language source files have the proper editor hints coda,
28 as specified in PDD07.
30 =head1 SEE ALSO
32 L<docs/pdds/pdd07_codingstd.pod>
34 =cut
36 ## L<PDD07/Smart Editor Style Support/"C source files, and files largely consisting of C" "must end with this coda">
38 my $coda = <<'CODA';
40  * Local variables:
41  *   c-file-style: "parrot"
42  * End:
43  * vim: expandtab shiftwidth=4:
44  */
45 CODA
47 my $DIST = Parrot::Distribution->new;
48 my @files = @ARGV ? <@ARGV> : $DIST->get_c_language_files();
50 Parrot::Test::Util::Runloop->testloop(
51     name        => 'every file has a coda',
52     files       => [@files],
53     per_file    => sub { shift =~ m{\Q$coda\E\n*\z} },
54     diag_prefix => 'No coda found'
57 Parrot::Test::Util::Runloop->testloop(
58     name        => 'only one coda per file',
59     files       => [@files],
60     per_file    => \&check_duplicates,
61     diag_prefix => 'Duplicate coda found'
64 sub check_duplicates {
65     my $buf = shift;
67     # append to the extra_coda array if coda-like text appears more than once
68     my $vim_many = 0;
69     $vim_many++ while $buf =~ m{^ [* \t]* vim[:] }gmx;
70     my $emacs_many = 0;
71     $emacs_many++ while $buf =~ m{^ [* \t]* Local \s variables: }gmx;
72     return ($vim_many <= 1 && $emacs_many <= 1);
75 # Local Variables:
76 #   mode: cperl
77 #   cperl-indent-level: 4
78 #   fill-column: 100
79 # End:
80 # vim: expandtab shiftwidth=4: