tagged release 0.6.4
[parrot.git] / t / codingstd / filenames.t
blobf300d76b4c3317a4d17afcd723c52ef8a21220bd
1 #! perl
2 # Copyright (C) 2006-2007, The Perl 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.  Test currently "todoed".
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 $manifest = maniread('MANIFEST');
63 my @files = @ARGV ? @ARGV : sort keys %$manifest;
64 my ( @multi_dots, @strange_chars, @too_long );
66 foreach my $file ( @files ) {
68     # check for multiple dots in filenames
69     my $num_dots = grep(m/\./g, split( m//, $file));
70     if ( $num_dots > 1 ) {
71         push @multi_dots, $file . "\n";
72     }
74     # check the characters used in filenames
75     push @strange_chars, $file . "\n"
76         if $file =~ m/[^\w\/.\-]/g;
78     # check for filenames that are too long
79     my ($volume, $directory, $filename) = File::Spec->splitpath( $file );
80     my @filename_chars = split  m//, $filename;
81     my $filename_len = scalar @filename_chars;
82     push @too_long, $file . ":$filename_len chars\n"
83         if $filename_len > 32;
87 ok( !@multi_dots, 'No multi-dot filenames' )
88     or diag( "Multi-dot filename found in " . @multi_dots
89         . " files:\n@multi_dots" );
91 ok( !@strange_chars, 'Portable characters in filenames' )
92     or diag( "Filename with non-portable character found in "
93         . @strange_chars . " files:\n@strange_chars" );
95 ok( !@too_long, 'Filenames length' )
96     or diag( "Filename with with more than 32 chars found in "
97         . @too_long . " files:\n@too_long" );
99 # Local Variables:
100 #   mode: cperl
101 #   cperl-indent-level: 4
102 #   fill-column: 100
103 # End:
104 # vim: expandtab shiftwidth=4: