-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaspell.t
executable file
·72 lines (54 loc) · 1.95 KB
/
aspell.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env perl6
use v6;
use Test;
use lib 'lib';
use Pod::Cache;
use Test-Files;
=begin overview
Spell check all the pod and most markdown files in the documentation directory.
Ignore case, and provide a repo-specific list of approved words,
which include technical jargon, method and class names, etc.
If the test fails, you can make it pass again by changing the
text (fixing the spelling issue), or adding the new word to
C<xt/words.pws> (if it's a word, a class/method name, known
program name, etc.), or to C<xt/code.pws> (if it's a fragment of
text that is part of a code example)
=end overview
my @files = Test-Files.documents.grep({not $_ ~~ / 'README.' .. '.md' /});
plan +@files;
my $proc = shell('aspell -v');
if $proc.exitcode {
skip-rest "This test requires aspell";
exit;
}
# generate a combined words file
my $dict = open "xt/aspell.pws", :w;
$dict.say('personal_ws-1.1 en 0 utf-8');
$dict.say("xt/words.pws".IO.slurp.chomp);
$dict.say("xt/code.pws".IO.slurp.chomp);
$dict.close;
my %output;
sub test-it($promises, $file) {
await Promise.allof: |$promises;
my $tasks = $promises».result;
my $count;
for %output{$file}.lines -> $line {
FIRST next; # dump first line
next if $line eq '';
diag $line;
$count++;
}
my $so-many = $count // "no";
ok !$count, "$file has $so-many spelling errors";
}
for @files -> $file {
my $input-file = $file.ends-with('.pod6') ?? Pod::Cache.cache-file($file) !! $file;
my $fixer = Proc::Async.new(«perl -pne 「BEGIN {print "!\n"} s/\S\K\\[tn]/ /g; s/^/^/」 $input-file»);
my $proc = Proc::Async.new(<aspell -a -l en_US --ignore-case --extra-dicts=./xt/aspell.pws --mode=url>);
$proc.bind-stdin: $fixer.stdout: :bin;
%output{$file}="";
$proc.stdout.tap(-> $buf { %output{$file} = %output{$file} ~ $buf });
$proc.stderr.tap(-> $buf {});
test-it([$fixer.start, $proc.start], $file);
}
# vim: expandtab shiftwidth=4 ft=perl6