5 use warnings FATAL => 'all';
7 use Capture::Tiny qw(capture);
8 use Encode qw(decode_utf8);
10 use File::Temp qw(tempfile);
11 use File::Which qw(which);
14 use XML::LibXSLT qw();
16 binmode Test::More->builder->$_, ':encoding(UTF-8)'
17 for qw(output failure_output todo_output);
19 # Skip means sweep bugs under the rug.
20 # I want this test to be actually run.
21 BAIL_OUT 'aspell is not installed.' unless which 'aspell';
26 push @stopwords, $_ unless /\A (?: \# | \s* \z)/msx; # skip comments, whitespace
31 my $runtime_params_file = '_build/runtime_params';
32 my $runtime_params = do $runtime_params_file;
33 die "Could not load $runtime_params_file. Run Build.PL first.\n"
34 unless $runtime_params;
35 $destdir = $runtime_params->{destdir};
38 my $iter = File::Next::files({
39 file_filter => sub {/\.html \z/msx},
47 my $stylesheet = XML::LibXSLT->new->parse_stylesheet(
48 XML::LibXML->load_xml(string => <<''));
49 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
50 xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
51 <xsl:template match="xhtml:abbr"/>
52 <xsl:template match="xhtml:acronym"/>
53 <xsl:template match="xhtml:code"/> <!-- filter computerese -->
54 <xsl:template match="@* | node()"> <!-- apply identity function to rest of nodes -->
56 <xsl:apply-templates select="@* | node()"/>
61 while (defined(my $html_file = $iter->())) {
64 my ($temp_handle, $temp_file) = tempfile;
65 my $transformed = $stylesheet->transform(XML::LibXML->load_xml(location => $html_file, load_ext_dtd => 0,));
66 $stylesheet->output_fh($transformed, $temp_handle);
68 my ($stdout) = capture {
69 system "aspell -H --encoding=UTF-8 -l en list < $temp_file";
71 my @misspelt_words = grep {!($_ ~~ @stopwords)} split /\n/, decode_utf8 $stdout;
72 ok !@misspelt_words, "$html_file ($temp_file) spell-check";
73 diag join "\n", sort @misspelt_words if @misspelt_words;
76 done_testing($file_counter);
165 ## things that should be in the dictionary, but are not
171 ## single foreign words
173 ## misspelt on purpose