Better diagnostics for Whitespace test
This commit is contained in:
parent
3f9331a774
commit
41bdf0e28d
1 changed files with 20 additions and 18 deletions
|
|
@ -13,15 +13,29 @@ use FindBin qw($Bin);
|
||||||
use lib "$FindBin::Bin/lib";
|
use lib "$FindBin::Bin/lib";
|
||||||
|
|
||||||
use File::Find;
|
use File::Find;
|
||||||
use Test::More tests => 1; # increment this value for each test you create
|
use Test::More;
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
|
|
||||||
my (@modules, @failedModules);
|
my (@modules, @failedModules);
|
||||||
my $wgLib = WebGUI::Test->lib;
|
my $wgLib = WebGUI::Test->lib;
|
||||||
File::Find::find( \&getWebGUIModules, $wgLib);
|
File::Find::find( \&getWebGUIModules, $wgLib);
|
||||||
|
|
||||||
my $numFailedModules = checkModules();
|
plan tests => scalar(@modules);
|
||||||
is($numFailedModules, 0, "No erroneous whitespace in or before POD");
|
|
||||||
|
foreach my $module (@modules) {
|
||||||
|
open(FILE, "< $module") or die "Can't open file $module";
|
||||||
|
my @content = <FILE>;
|
||||||
|
close FILE;
|
||||||
|
|
||||||
|
my $lineNumber = checkContent(\@content);
|
||||||
|
is($lineNumber, 0, "Whitespace test for $module");
|
||||||
|
|
||||||
|
if ($lineNumber > 0) {
|
||||||
|
push(@failedModules, $module);
|
||||||
|
diag("Failed on $module, near line $lineNumber");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my $numFailedModules = scalar(@failedModules);
|
||||||
|
|
||||||
if ($numFailedModules) {
|
if ($numFailedModules) {
|
||||||
print "\n# The folling modules have erroneous whitespace in or before POD:\n";
|
print "\n# The folling modules have erroneous whitespace in or before POD:\n";
|
||||||
|
|
@ -37,19 +51,6 @@ sub getWebGUIModules {
|
||||||
push( @modules, $File::Find::name ) if /\.pm$/;
|
push( @modules, $File::Find::name ) if /\.pm$/;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub checkModules {
|
|
||||||
foreach my $module (@modules) {
|
|
||||||
open(FILE, "< $module") or die "Can't open file $module";
|
|
||||||
my @content = <FILE>;
|
|
||||||
close FILE;
|
|
||||||
|
|
||||||
if (checkContent(\@content)) {
|
|
||||||
push(@failedModules, $module);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return scalar(@failedModules);
|
|
||||||
}
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
# Note: this test checks for non-empty lines before POD commands
|
# Note: this test checks for non-empty lines before POD commands
|
||||||
# which are not detected by podchecker, but are causing problems
|
# which are not detected by podchecker, but are causing problems
|
||||||
|
|
@ -61,15 +62,16 @@ sub checkContent {
|
||||||
my @content = @{$content};
|
my @content = @{$content};
|
||||||
|
|
||||||
my $podAllowed = 0;
|
my $podAllowed = 0;
|
||||||
|
my $lineNumber = 1;
|
||||||
foreach my $line (@content) {
|
foreach my $line (@content) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
my $isPodWord = ($line =~ m/^=/);
|
my $isPodWord = ($line =~ m/^=/);
|
||||||
if ($isPodWord && !$podAllowed) {
|
if ($isPodWord && !$podAllowed) {
|
||||||
diag $line;
|
return $lineNumber;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
# POD is allowed on next line if current line is empty
|
# POD is allowed on next line if current line is empty
|
||||||
$podAllowed = ($line eq '');
|
$podAllowed = ($line eq '');
|
||||||
|
$lineNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue