2 # Copyright (C) 2006-2009, Parrot Foundation.
8 use lib qw( . lib ../lib ../../lib );
9 use Test::More tests => 2;
10 use Parrot::Distribution;
11 use Parrot::Test::Util::Runloop;
15 t/codingstd/c_code_coda.t - checks for editor hint coda in C source
20 % prove t/codingstd/c_code_coda.t
23 % perl t/codingstd/c_code_coda.t src/foo.c include/parrot/bar.h
27 Checks that all C language source files have the proper editor hints coda,
28 as specified in PDD07.
32 L<docs/pdds/pdd07_codingstd.pod>
36 ## L<PDD07/Smart Editor Style Support/"C source files, and files largely consisting of C" "must end with this coda">
41 * c-file-style: "parrot"
43 * vim: expandtab shiftwidth=4:
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',
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',
60 per_file => \&check_duplicates,
61 diag_prefix => 'Duplicate coda found'
64 sub check_duplicates {
67 # append to the extra_coda array if coda-like text appears more than once
69 $vim_many++ while $buf =~ m{^ [* \t]* vim[:] }gmx;
71 $emacs_many++ while $buf =~ m{^ [* \t]* Local \s variables: }gmx;
72 return ($vim_many <= 1 && $emacs_many <= 1);
77 # cperl-indent-level: 4
80 # vim: expandtab shiftwidth=4: