Tests: In t_dist_whitespace, indicate what line has errant whitespace

Signed-off-by: Wilson Snyder <wsnyder@wsnyder.org>
This commit is contained in:
John Coiner 2017-10-01 16:09:56 -04:00 committed by Wilson Snyder
parent 04ca6a4307
commit 59aa0f43d5
1 changed files with 12 additions and 1 deletions

View File

@ -20,7 +20,18 @@ foreach my $file (sort keys %files) {
} elsif ($contents =~ /[\001\002\003\004\005\006]/) {
# Ignore binrary files
} elsif ($contents =~ /[ \t]\n/) {
$warns{$file} = "File contains trailing whitespace: $file";
my @lines = split(/\n/, $contents);
my $line_no = 0;
foreach my $line (@lines) {
$line_no++;
# Trim trailing carriage-return (ascii 0xd) and form feed (0xc),
# as we expect a few of those
$line =~ s/[\x{d}\x{c}]//g;
if ($line =~ /\s$/) {
$warns{$file} = "Trailing whitespace at $file:$line_no";
$warns{$file} .= " (last character is ASCII " . ord(substr($line, -1, 1)) . ")";
}
}
}
}