2 # Copyright (C) 2006-2010, Parrot Foundation.
8 use lib qw( . lib ../lib ../../lib );
9 use Test::More tests => 2;
10 use Parrot::Distribution;
14 t/codingstd/pir_code_coda.t - checks for editor hint coda in PIR source
19 % prove t/codingstd/pir_code_coda.t
22 % perl t/codingstd/pir_code_coda.t src/foo.pir
26 Checks that all PIR language source files have the proper editor hints coda,
27 as specified in PDD07.
31 L<docs/pdds/pdd07_codingstd.pod>
35 ## L<PDD07/Smart Editor Style Support/"PIR source files must end with this coda">
42 # vim: expandtab shiftwidth=4 ft=pir:
45 my $DIST = Parrot::Distribution->new;
46 my @files = @ARGV ? <@ARGV> : $DIST->get_pir_language_files();
50 foreach my $file (@files) {
52 # if we have command line arguments, the file is the full path
53 # otherwise, use the relevant Parrot:: path method
54 my $path = @ARGV ? $file : $file->path;
58 my $buf = $DIST->slurp($path);
60 # skip autogenerated files (based on the first line of the file)
61 next if ( index( $buf, "# THIS IS A GENERATED FILE! DO NOT EDIT!" ) == 0 );
63 # append to the no_coda array if the code doesn't match
64 push @no_coda => "$path\n"
65 unless $buf =~ m{\Q$coda\E\n*\z};
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 push @extra_coda => "$path\n"
73 if $vim_many > 1 || $emacs_many > 1;
76 # If we use is_deeply, then the differences will show in the test output.
77 is_deeply( \@no_coda, [], 'PIR code coda present' );
78 is_deeply( \@extra_coda, [], 'PIR code coda appears only once' );
82 # cperl-indent-level: 4
85 # vim: expandtab shiftwidth=4: