From 3013c637d1218ee9b8d88c8df6a48b0413a63df9 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 28 Aug 2012 22:01:19 +0200 Subject: [PATCH] Refactor t/porting/filenames.t to shrink the code and the TAP generated. Fold the function validate_file_name() into its only caller. Put the tested pathname into each test description to avoid a call to note() - this halves the size of the TAP generated. Fold the chained tests into a chained if/elsif/else sequence. Eliminate the use of File::Spec, as all platforms can cope internally with F<../MANIFEST>. --- t/porting/filenames.t | 68 +++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/t/porting/filenames.t b/t/porting/filenames.t index 268dd1c..b65ab8e 100644 --- a/t/porting/filenames.t +++ b/t/porting/filenames.t @@ -27,12 +27,11 @@ BEGIN { } use strict; -use File::Spec; use File::Basename; require './test.pl'; -my $manifest = File::Spec->catfile(File::Spec->updir(), 'MANIFEST'); +my $manifest = '../MANIFEST'; open my $m, '<', $manifest or die "Can't open '$manifest': $!"; my @files; @@ -46,59 +45,38 @@ close $m or die $!; plan(scalar @files); -for my $file (@files) { - validate_file_name($file); -} -exit 0; - - -sub validate_file_name { - my $path = shift; - my $filename = basename $path; - - note("testing $path"); - - my @path_components = split('/',$path); - pop @path_components; # throw away the filename +PATHNAME: for my $pathname (@files) { + my @path_components = split('/',$pathname); + my $filename = pop @path_components; for my $component (@path_components) { - if ($component =~ /\./) { - fail("no directory components containing '.'"); - return; - } - if (length $component > 32) { - fail("no directory with a name over 32 characters (VOS requirement)"); - return; - } + if ($component =~ /\./) { + fail("$pathname has directory components containing '.'"); + next PATHNAME; + } + if (length $component > 32) { + fail("$pathname has a name over 32 characters (VOS requirement)"); + next PATHNAME; + } } if ($filename =~ /^\-/) { - fail("filename does not start with -"); - return; + fail("$pathname starts with -"); + next PATHNAME; } my($before, $after) = split /\./, $filename; if (length $before > 39) { - fail("filename has 39 or fewer characters before the dot"); - return; - } - if ($after) { - if (length $after > 39) { - fail("filename has 39 or fewer characters after the dot"); - return; - } - } - - if ($filename =~ /^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])\./i) { - fail("filename has a reserved name"); - return; - } - - if ($filename =~ /\s|\(|\&/) { - fail("filename has a reserved character"); - return; + fail("$pathname has more than 39 characters before the dot"); + } elsif ($after && length $after > 39) { + fail("$pathname has more than 39 characters after the dot"); + } elsif ($filename =~ /^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])\./i) { + fail("$pathname has a reserved name"); + } elsif ($filename =~ /\s|\(|\&/) { + fail("$pathname has a reserved character"); + } else { + pass("$pathname ok"); } - pass("filename ok"); } # EOF -- 1.8.3.1