1#!/usr/bin/perl 2# 3# Test Pod::Man with a document that produces only errors. 4# 5# Copyright 2013, 2016, 2018-2019 Russ Allbery <rra@cpan.org> 6# 7# This program is free software; you may redistribute it and/or modify it 8# under the same terms as Perl itself. 9# 10# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl 11 12use 5.008; 13use strict; 14use warnings; 15 16use Test::More tests => 8; 17 18# Load the module. 19BEGIN { 20 use_ok('Pod::Man'); 21} 22 23# Set up Pod::Man to output to a string. 24my $parser = Pod::Man->new; 25isa_ok($parser, 'Pod::Man'); 26my $output; 27$parser->output_string(\$output); 28 29# Ensure there are no warnings by dying on a warning, forcing a test failure. 30local $SIG{__WARN__} = sub { croak($_[0]) }; 31 32# Try a POD document where the only command is invalid. Make sure it succeeds 33# and doesn't throw an exception. 34## no critic (ValuesAndExpressions::ProhibitEscapedCharacters) 35ok(eval { $parser->parse_string_document("=\xa0") }, 36 'Parsed invalid document'); 37is($@, q{}, '...with no errors'); 38## use critic 39 40# With recent Pod::Simple, there will be a POD ERRORS section. With older 41# versions of Pod::Simple, we have to skip the test since it doesn't trigger 42# this problem. 43SKIP: { 44 if ($output eq q{}) { 45 skip('Pod::Simple does not produce errors for invalid commands', 1); 46 } 47 like( 48 $output, 49 qr{ [.]SH [ ] "POD [ ] ERRORS" }xms, 50 '...and output contains a POD ERRORS section' 51 ); 52} 53 54# Try with a document containing only =cut. 55ok(eval { $parser->parse_string_document('=cut') }, 'Parsed =cut document'); 56is($@, q{}, '...with no errors'); 57 58# Same check for a POD ERRORS section. 59SKIP: { 60 if ($output eq q{}) { 61 skip('Pod::Simple does not produce errors for invalid commands', 1); 62 } 63 like( 64 $output, 65 qr{ [.]SH [ ] "POD [ ] ERRORS" }xms, 66 '...and output contains a POD ERRORS section' 67 ); 68} 69