Change 31741 by [EMAIL PROTECTED] on 2007/08/21 08:56:31
Subject: [patch] File::CheckTree - a side effect of making the build
whitespace safe(r)
From: Max Maischein <[EMAIL PROTECTED]>
Date: Sun, 19 Aug 2007 23:45:57 +0200
Message-Id: <[EMAIL PROTECTED]>
(Applied with some tweaks.)
Affected files ...
... //depot/perl/lib/File/CheckTree.pm#16 edit
... //depot/perl/lib/File/CheckTree.t#7 edit
Differences ...
==== //depot/perl/lib/File/CheckTree.pm#16 (text) ====
Index: perl/lib/File/CheckTree.pm
--- perl/lib/File/CheckTree.pm#15~31654~ 2007-07-25 05:21:19.000000000
-0700
+++ perl/lib/File/CheckTree.pm 2007-08-21 01:56:31.000000000 -0700
@@ -87,8 +87,17 @@
# but earlier versions of File::CheckTree did not do this either
# split a line like "/foo -r || die"
- # so that $file is "/foo", $test is "-rwx || die"
- ($file, $test) = split(' ', $check, 2); # special whitespace split
+ # so that $file is "/foo", $test is "-r || die"
+ # (making special allowance for quoted filenames).
+ if ($check =~ m/^\s*"([^"]+)"\s+(.*?)\s*$/ or
+ $check =~ m/^\s*'([^']+)'\s+(.*?)\s*$/ or
+ $check =~ m/^\s*(\S+?)\s+(\S.*?)\s*$/)
+ {
+ ($file, $test) = ($1,$2);
+ }
+ else {
+ die "Malformed line: '$check'";
+ };
# change a $test like "!-ug || die" to "!-Z || die",
# capturing the bundled tests (e.g. "ug") in $2
@@ -155,12 +164,12 @@
eval $this;
# re-raise an exception caused by a "... || die" test
- if ($@) {
+ if (my $err = $@) {
# in case of any cd directives, return from whence we came
if ($starting_dir ne cwd) {
chdir($starting_dir) || die "$starting_dir: $!";
}
- die $@ if $@;
+ die $err;
}
}
==== //depot/perl/lib/File/CheckTree.t#7 (xtext) ====
Index: perl/lib/File/CheckTree.t
--- perl/lib/File/CheckTree.t#6~29519~ 2006-12-11 10:33:21.000000000 -0800
+++ perl/lib/File/CheckTree.t 2007-08-21 01:56:31.000000000 -0700
@@ -7,7 +7,7 @@
use Test;
-BEGIN { plan tests => 6 }
+BEGIN { plan tests => 8 }
use strict;
@@ -49,10 +49,11 @@
# indented comment, followed blank line (w/o whitespace):
README -f
- $path_to_README -e || warn
+ '$path_to_README' -e || warn
};
};
+ print STDERR $_ for @warnings;
if ( !$@ && [EMAIL PROTECTED] && defined($num_warnings) && $num_warnings
== 0 ) {
ok(1);
}
@@ -202,3 +203,39 @@
ok(0);
}
}
+
+#### TEST 7 -- Quoted file names ####
+{
+ my $num_warnings;
+ eval {
+ $num_warnings = validate q{
+ "a file with whitespace" !-ef
+ 'a file with whitespace' !-ef
+ };
+ };
+
+ if ( !$@ ) {
+ # No errors mean we compile correctly
+ ok(1);
+ } else {
+ ok(0);
+ print STDERR $@;
+ };
+}
+
+#### TEST 8 -- Malformed query ####
+{
+ my $num_warnings;
+ eval {
+ $num_warnings = validate q{
+ a file with whitespace !-ef
+ };
+ };
+
+ if ( $@ =~ /syntax error/) {
+ # We got a syntax error for a malformed file query
+ ok(1);
+ } else {
+ ok(0);
+ };
+}
End of Patch.