Skip to content

Commit

Permalink
Merge pull request #7 from kentfredric/master
Browse files Browse the repository at this point in the history
Add a sorted wordcount to the bottom of all_pod_files_spelling_ok
  • Loading branch information
sartak committed Sep 26, 2014
2 parents 5c89e54 + 655b00d commit e9a2a7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Revision history for Test-Spelling

- Add a sorted list of most commonly misspelled words to the end of
all_pod_files_spelling_ok to aid stopword list creation and
bulk correction. (Kent Fredric)

0.19 2013-05-05
- for more consistent results avoid using the user's local aspell
dictionary [rt.cpan.org #84869] (Karen Etheridge)
Expand Down
18 changes: 17 additions & 1 deletion lib/Test/Spelling.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use warnings;
use base 'Exporter';
use Pod::Spell;
use Test::Builder;
use Text::Wrap;
use File::Spec;
use IPC::Run3;
use Symbol 'gensym';
Expand All @@ -28,6 +29,7 @@ my $TEST = Test::Builder->new;
my $SPELLCHECKER;
my $FILE_FILTER = sub { 1 };
my $POD_PARSER;
our %ALL_WORDS;

sub spellchecker_candidates {
# if they've specified a spellchecker, use only that one
Expand Down Expand Up @@ -124,6 +126,7 @@ sub pod_file_spelling_ok {
# remove stopwords, select unique errors
my $WL = \%Pod::Wordlist::Wordlist;
@words = grep { !$WL->{$_} && !$WL->{lc $_} } @words;
$ALL_WORDS{$_}++ for @words;
my %seen;
@seen{@words} = ();
@words = sort keys %seen;
Expand All @@ -140,7 +143,7 @@ sub pod_file_spelling_ok {

sub all_pod_files_spelling_ok {
my @files = all_pod_files(@_);

local %ALL_WORDS;
if (!has_working_spellchecker()) {
return $TEST->plan(skip_all => "no working spellchecker found");
}
Expand All @@ -152,6 +155,19 @@ sub all_pod_files_spelling_ok {
local $Test::Builder::Level = $Test::Builder::Level + 1;
pod_file_spelling_ok($file) or undef $ok;
}
if ( keys %ALL_WORDS ) {
# Invert k => v to v => [ k ]
my %values;
push @{ $values{ $ALL_WORDS{$_} } }, $_ for keys %ALL_WORDS;

my $labelformat = q[%6s: ];
my $indent = q[ ] x 10;

$TEST->diag(qq[\nAll incorrect words, by number of occurrences:\n] .
join qq[\n], map { wrap( ( sprintf $labelformat, $_ ), $indent, join q[, ], sort @{ $values{$_} } ) }
sort { $a <=> $b } keys %values
);
}
return $ok;
}

Expand Down

0 comments on commit e9a2a7b

Please sign in to comment.