add and change NEWS for 2.8.0 release
[parrot.git] / t / codingstd / filenames.t
blob4ba8d296f47341546b7540674c7d1aa8410a27d2
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;
10 use ExtUtils::Manifest qw(maniread);
11 use Parrot::Distribution;
12 use File::Spec;
14 # set up how many tests to run
15 plan tests => 3;
17 =head1 NAME
19 t/codingstd/filenames.t - checks that filenames conform to standards
21 =head1 SYNOPSIS
23     # test all files
24     % prove t/codingstd/filenames.t
26     # test specific files
27     % perl t/codingstd/filenames.t src/foo.c include/parrot/bar.h
29 =head1 DESCRIPTION
31 Checks that the filenames used for files within the Parrot distribution
32 conform to a set of highly portable standards.
34 =over 4
36 =item No multiple dots within filenames
38 Files with more than one dot ( '.' ) in their filename are problematic on
39 some platforms (e.g. VMS) hence avoid these in Parrot.
41 =item No strange characters in filenames
43 Filenames are restricted to the characters C<a-zA-Z0-9_-.>
45 =item Filenames length restriction
47 Filenames are restricted to 32 characters.
49 =back
51 =head1 SEE ALSO
53 L<docs/pdds/pdd07_codingstd.pod>
55 =head1 AUTHOR
57 Paul Cochrane <paultcochrane at gmail dot com>
59 =cut
61 my $DIST = Parrot::Distribution->new;
62 my @files;
63 if (@ARGV){
64     @files = <@ARGV>;
66 else {
67     my $manifest = maniread('MANIFEST');
68     # Give ports a little more leeway
69     @files = grep {! /^ports/} sort keys %$manifest;
71 my ( @multi_dots, @strange_chars, @too_long );
73 foreach my $file ( @files ) {
75     # check for multiple dots in filenames
76     my $num_dots = grep(m/\./g, split( m//, $file));
77     if ( $num_dots > 1 ) {
78         push @multi_dots, $file . "\n";
79     }
81     # check the characters used in filenames
82     push @strange_chars, $file . "\n"
83         if $file =~ m/[^\w\/.\-]/g;
85     # check for filenames that are too long
86     my ($volume, $directory, $filename) = File::Spec->splitpath( $file );
87     my @filename_chars = split  m//, $filename;
88     my $filename_len = scalar @filename_chars;
89     push @too_long, $file . ":$filename_len chars\n"
90         if $filename_len > 32;
94 ok( !@multi_dots, 'No multi-dot filenames' )
95     or diag( "Multi-dot filename found in " . @multi_dots
96         . " files:\n@multi_dots" );
98 ok( !@strange_chars, 'Portable characters in filenames' )
99     or diag( "Filename with non-portable character found in "
100         . @strange_chars . " files:\n@strange_chars" );
102 ok( !@too_long, 'Filenames length' )
103     or diag( "Filename with more than 32 chars found in "
104         . @too_long . " files:\n@too_long" );
106 # Local Variables:
107 #   mode: cperl
108 #   cperl-indent-level: 4
109 #   fill-column: 100
110 # End:
111 # vim: expandtab shiftwidth=4: