1#!/usr/bin/perl -w 2# 3# Test Pod::Text with a document that produces only errors. 4# 5# Documents with only errors were shown as contentless but had a POD ERRORS 6# section, which previously led to internal errors because state variables 7# weren't properly initialized. See CPAN RT #88724. 8# 9# Copyright 2013, 2018, 2020 Russ Allbery <rra@cpan.org> 10# 11# This program is free software; you may redistribute it and/or modify it 12# under the same terms as Perl itself. 13# 14# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl 15 16use 5.008; 17use strict; 18use warnings; 19 20use Test::More tests => 8; 21 22BEGIN { 23 use_ok('Pod::Text'); 24} 25 26# Set up Pod::Text to output to a string. 27my $parser = Pod::Text->new; 28isa_ok($parser, 'Pod::Text'); 29my $output; 30$parser->output_string(\$output); 31 32# Ensure any warnings cause a test failure. 33## no critic (ErrorHandling::RequireCarping) 34local $SIG{__WARN__} = sub { die $_[0] }; 35 36# Parse a document provided as a string, ensure that it doesn't produce any 37# warnings or errors, and check that it either contains no content or a POD 38# ERRORS section. 39# 40# $document - Document to parse 41# $name - Name of the test 42sub check_document { 43 my ($document, $name) = @_; 44 my $result = eval { $parser->parse_string_document($document) }; 45 ok($result, "Parsed $name"); 46 is($@, q{}, 'No exceptions'); 47 if ($output eq q{}) { 48 # Older Pod::Simple doesn't always produce errors. 49 ok(1, 'Output is empty'); 50 } else { 51 like($output, qr{POD [ ] ERRORS}xms, 'Output contains POD ERRORS'); 52 } 53 return; 54} 55 56# Document whose only content is an invalid command. 57## no critic (ValuesAndExpressions::ProhibitEscapedCharacters) 58my $invalid_char = chr utf8::unicode_to_native(0xa0); 59check_document("=$invalid_char", 'invalid command'); 60 61# Document containing only a =cut. 62check_document('=cut', 'document with only =cut'); 63