diff options
author | Craig A. Berry <craigberry@mac.com> | 2016-01-30 17:25:05 -0600 |
---|---|---|
committer | Craig A. Berry <craigberry@mac.com> | 2016-01-30 18:29:35 -0600 |
commit | 259f5e0bbc6277b397458cb905d37baaa68aaada (patch) | |
tree | 74073e496254c5afd1621f918fe911f57059ab38 /cpan/podlators/t | |
parent | 9c903d5937fa3682f21b2aece7f6011b6fcb2750 (diff) | |
download | perl-259f5e0bbc6277b397458cb905d37baaa68aaada.tar.gz |
Tweaks to podlators integration.
It's only perlpodstyle that we can't build the man page for since
it lives in the top-level pod/ directory. Plus there was a new test
that I had missed in the integration.
Diffstat (limited to 'cpan/podlators/t')
-rw-r--r-- | cpan/podlators/t/man/no-encode.t | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cpan/podlators/t/man/no-encode.t b/cpan/podlators/t/man/no-encode.t new file mode 100644 index 0000000000..bdd4e683b1 --- /dev/null +++ b/cpan/podlators/t/man/no-encode.t @@ -0,0 +1,69 @@ +#!/usr/bin/perl +# +# Test for graceful degradation to non-utf8 output without Encode module. +# +# Copyright 2016 Niko Tyni <ntyni@iki.fi> +# Copyright 2016 Russ Allbery <rra@cpan.org> +# +# This program is free software; you may redistribute it and/or modify it +# under the same terms as Perl itself. + +use 5.006; +use strict; +use warnings; + +use Test::More tests => 6; + +# Force the Encode module to be impossible to import. +BEGIN { + ok(!$INC{'Encode.pm'}, 'Encode is not loaded yet'); + my $reject_encode = sub { + if ($_[1] eq 'Encode.pm') { + die "refusing to load Encode\n"; + } + }; + unshift(@INC, $reject_encode); + ok(!eval { require Encode }, 'Cannot load Encode any more'); +} + +# Load the module. +BEGIN { + use_ok('Pod::Man'); +} + +# Ensure we don't get warnings by throwing an exception if we see any. This +# is overridden below when we enable utf8 and do expect a warning. +local $SIG{__WARN__} = sub { die "No warnings expected\n" }; + +# First, check that everything works properly when utf8 isn't set. We expect +# to get accent-mangled ASCII output. Don't use Test::Podlators, since it +# wants to import Encode. +# +## no critic (ValuesAndExpressions::ProhibitEscapedCharacters) +my $pod = "=encoding latin1\n\n=head1 NAME\n\nBeyonc\xE9!"; +my $parser = Pod::Man->new(utf8 => 0, name => 'test'); +my $output; +$parser->output_string(\$output); +$parser->parse_string_document($pod); +like( + $output, + qr{ Beyonce\\[*]\' }xms, + 'Works without Encode for non-utf8 output' +); + +# Now, try with the utf8 option set. We should then get a warning that we're +# falling back to non-utf8 output. +{ + local $SIG{__WARN__} = sub { + like( + $_[0], + qr{ falling [ ] back [ ] to [ ] non-utf8 }xms, + 'Pod::Man warns on utf8 option with no Encode module' + ); + }; + $parser = Pod::Man->new(utf8 => 1, name => 'test'); +} +my $output_fallback; +$parser->output_string(\$output_fallback); +$parser->parse_string_document($pod); +is($output_fallback, $output, 'Degraded gracefully to non-utf8 output'); |