xref: /openbsd-src/gnu/usr.bin/perl/cpan/podlators/t/man/empty.t (revision e068048151d29f2562a32185e21a8ba885482260)
15759b3d2Safresh1#!/usr/bin/perl
2b8851fccSafresh1#
35759b3d2Safresh1# Test Pod::Man with a document that produces only errors.
4b8851fccSafresh1#
5*e0680481Safresh1# Copyright 2013, 2016, 2018-2019, 2022 Russ Allbery <rra@cpan.org>
6b8851fccSafresh1#
7b8851fccSafresh1# This program is free software; you may redistribute it and/or modify it
8b8851fccSafresh1# under the same terms as Perl itself.
9b46d8ef2Safresh1#
10b46d8ef2Safresh1# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
11b8851fccSafresh1
12*e0680481Safresh1use 5.010;
13b8851fccSafresh1use strict;
145759b3d2Safresh1use warnings;
15b8851fccSafresh1
16b8851fccSafresh1use Test::More tests => 8;
175759b3d2Safresh1
185759b3d2Safresh1# Load the module.
195759b3d2Safresh1BEGIN {
205759b3d2Safresh1    use_ok('Pod::Man');
215759b3d2Safresh1}
22b8851fccSafresh1
23b8851fccSafresh1# Set up Pod::Man to output to a string.
24b8851fccSafresh1my $parser = Pod::Man->new;
25b8851fccSafresh1isa_ok($parser, 'Pod::Man');
26b8851fccSafresh1my $output;
27b8851fccSafresh1$parser->output_string(\$output);
28b8851fccSafresh1
295759b3d2Safresh1# Ensure there are no warnings by dying on a warning, forcing a test failure.
305759b3d2Safresh1local $SIG{__WARN__} = sub { croak($_[0]) };
315759b3d2Safresh1
325759b3d2Safresh1# Try a POD document where the only command is invalid.  Make sure it succeeds
335759b3d2Safresh1# and doesn't throw an exception.
34*e0680481Safresh1my $invalid_char = chr(utf8::unicode_to_native(0xa0));
35*e0680481Safresh1ok(
36*e0680481Safresh1    eval { $parser->parse_string_document("=$invalid_char") },
37*e0680481Safresh1    'Parsed invalid document',
38*e0680481Safresh1);
395759b3d2Safresh1is($@, q{}, '...with no errors');
405759b3d2Safresh1
415759b3d2Safresh1# With recent Pod::Simple, there will be a POD ERRORS section.  With older
425759b3d2Safresh1# versions of Pod::Simple, we have to skip the test since it doesn't trigger
435759b3d2Safresh1# this problem.
44b8851fccSafresh1SKIP: {
455759b3d2Safresh1    if ($output eq q{}) {
465759b3d2Safresh1        skip('Pod::Simple does not produce errors for invalid commands', 1);
475759b3d2Safresh1    }
485759b3d2Safresh1    like(
495759b3d2Safresh1        $output,
505759b3d2Safresh1        qr{ [.]SH [ ] "POD [ ] ERRORS" }xms,
51*e0680481Safresh1        '...and output contains a POD ERRORS section',
525759b3d2Safresh1    );
53b8851fccSafresh1}
54b8851fccSafresh1
55b8851fccSafresh1# Try with a document containing only =cut.
565759b3d2Safresh1ok(eval { $parser->parse_string_document('=cut') }, 'Parsed =cut document');
575759b3d2Safresh1is($@, q{}, '...with no errors');
585759b3d2Safresh1
595759b3d2Safresh1# Same check for a POD ERRORS section.
60b8851fccSafresh1SKIP: {
615759b3d2Safresh1    if ($output eq q{}) {
625759b3d2Safresh1        skip('Pod::Simple does not produce errors for invalid commands', 1);
635759b3d2Safresh1    }
645759b3d2Safresh1    like(
655759b3d2Safresh1        $output,
665759b3d2Safresh1        qr{ [.]SH [ ] "POD [ ] ERRORS" }xms,
67*e0680481Safresh1        '...and output contains a POD ERRORS section',
685759b3d2Safresh1    );
69b8851fccSafresh1}
70