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