1#!/usr/bin/perl
2#
3# Test Pod::Man with a document that produces only errors.
4#
5# Copyright 2013, 2016, 2018-2019, 2022 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.010;
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.
34my $invalid_char = chr(utf8::unicode_to_native(0xa0));
35ok(
36    eval { $parser->parse_string_document("=$invalid_char") },
37    'Parsed invalid document',
38);
39is($@, q{}, '...with no errors');
40
41# With recent Pod::Simple, there will be a POD ERRORS section.  With older
42# versions of Pod::Simple, we have to skip the test since it doesn't trigger
43# this problem.
44SKIP: {
45    if ($output eq q{}) {
46        skip('Pod::Simple does not produce errors for invalid commands', 1);
47    }
48    like(
49        $output,
50        qr{ [.]SH [ ] "POD [ ] ERRORS" }xms,
51        '...and output contains a POD ERRORS section',
52    );
53}
54
55# Try with a document containing only =cut.
56ok(eval { $parser->parse_string_document('=cut') }, 'Parsed =cut document');
57is($@, q{}, '...with no errors');
58
59# Same check for a POD ERRORS section.
60SKIP: {
61    if ($output eq q{}) {
62        skip('Pod::Simple does not produce errors for invalid commands', 1);
63    }
64    like(
65        $output,
66        qr{ [.]SH [ ] "POD [ ] ERRORS" }xms,
67        '...and output contains a POD ERRORS section',
68    );
69}
70