1b8851fccSafresh1#!/usr/bin/perl 2b8851fccSafresh1# 3b8851fccSafresh1# Tests for backward compatibility with Pod::Parser. 4b8851fccSafresh1# 5*56d68f1eSafresh1# Copyright 2006, 2008-2009, 2012, 2015, 2018-2019 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. 9f3efcd01Safresh1# 10f3efcd01Safresh1# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl 11b8851fccSafresh1 12*56d68f1eSafresh1use 5.008; 13b8851fccSafresh1use strict; 14b8851fccSafresh1use warnings; 15b8851fccSafresh1 16b8851fccSafresh1use lib 't/lib'; 17b8851fccSafresh1 18b8851fccSafresh1use File::Spec; 19b8851fccSafresh1use Test::More tests => 7; 20b8851fccSafresh1use Test::Podlators qw(slurp); 21b8851fccSafresh1 22b8851fccSafresh1# Ensure the modules load properly. 23b8851fccSafresh1BEGIN { 24b8851fccSafresh1 use_ok('Pod::Man'); 25b8851fccSafresh1 use_ok('Pod::Text'); 26b8851fccSafresh1} 27b8851fccSafresh1 28b8851fccSafresh1# Create a temporary directory to use for output, but don't fail if it already 29b8851fccSafresh1# exists. If we failed to create it, we'll fail later on. We unfortunately 30b8851fccSafresh1# have to create files on disk to easily create file handles for testing. 31b8851fccSafresh1my $tmpdir = File::Spec->catdir('t', 'tmp'); 32b8851fccSafresh1if (!-d $tmpdir) { 33b8851fccSafresh1 mkdir($tmpdir, 0777); 34b8851fccSafresh1} 35b8851fccSafresh1 36b8851fccSafresh1# Create some test POD to use to test the -cutting option. 37b8851fccSafresh1my $infile = File::Spec->catfile('t', 'tmp', "tmp$$.pod"); 38b8851fccSafresh1open(my $input, '>', $infile) or BAIL_OUT("cannot create $infile: $!"); 39b8851fccSafresh1print {$input} "Some random B<text>.\n" 40b8851fccSafresh1 or BAIL_OUT("cannot write to $infile: $!"); 41b8851fccSafresh1close($input) or BAIL_OUT("cannot write to $infile: $!"); 42b8851fccSafresh1 43b8851fccSafresh1# Test the -cutting option with Pod::Man. 44b8851fccSafresh1my $parser = Pod::Man->new; 45b8851fccSafresh1isa_ok($parser, 'Pod::Man', 'Pod::Man parser object'); 46b8851fccSafresh1my $outfile = File::Spec->catfile('t', 'tmp', "tmp$$.man"); 47b8851fccSafresh1open(my $output, '>', $outfile) or BAIL_OUT("cannot open $outfile: $!"); 48b8851fccSafresh1$parser->parse_from_file({ -cutting => 0 }, $infile, $output); 49b8851fccSafresh1close($output) or BAIL_OUT("cannot write to $outfile: $!"); 50b8851fccSafresh1my $got = slurp($outfile, 'man'); 51b8851fccSafresh1is($got, "Some random \\fBtext\\fR.\n", 'Pod::Man -cutting output'); 52b8851fccSafresh1unlink($outfile); 53b8851fccSafresh1 54b8851fccSafresh1# Likewise for Pod::Text. 55b8851fccSafresh1$parser = Pod::Text->new; 56b8851fccSafresh1isa_ok($parser, 'Pod::Text', 'Pod::Text parser object'); 57b8851fccSafresh1$outfile = File::Spec->catfile('t', 'tmp', "tmp$$.txt"); 58b8851fccSafresh1open($output, '>', $outfile) or BAIL_OUT("cannot open $outfile: $!"); 59b8851fccSafresh1$parser->parse_from_file({ -cutting => 0 }, $infile, $output); 60b8851fccSafresh1close($output) or BAIL_OUT("cannot write to $outfile: $!"); 61b8851fccSafresh1$got = slurp($outfile); 62b8851fccSafresh1is($got, " Some random text.\n\n", 'Pod::Text -cutting output'); 63b8851fccSafresh1unlink($outfile); 64b8851fccSafresh1 65b8851fccSafresh1# Rewrite the input file to be fully valid POD since we won't use -cutting. 66b8851fccSafresh1unlink($infile); 67b8851fccSafresh1open($input, '>', $infile) or BAIL_OUT("cannot create $infile: $!"); 68b8851fccSafresh1print {$input} "=pod\n\nSome random B<text>.\n" 69b8851fccSafresh1 or BAIL_OUT("cannot write to $infile: $!"); 70b8851fccSafresh1close($input) or BAIL_OUT("cannot write to $infile: $!"); 71b8851fccSafresh1 72b8851fccSafresh1# Now test the pod2text function with a single output. This will send the 73b8851fccSafresh1# results to standard output, so we need to redirect that to a file. 74b8851fccSafresh1open($output, '>', $outfile) or BAIL_OUT("cannot open $outfile: $!"); 75b8851fccSafresh1open(my $save_stdout, '>&', STDOUT) or BAIL_OUT("cannot dup stdout: $!"); 76b8851fccSafresh1open(STDOUT, '>&', $output) or BAIL_OUT("cannot redirect stdout: $!"); 77b8851fccSafresh1pod2text($infile); 78b8851fccSafresh1close($output) or BAIL_OUT("cannot write to $outfile: $!"); 79b8851fccSafresh1open(STDOUT, '>&', $save_stdout) or BAIL_OUT("cannot fix stdout: $!"); 80b8851fccSafresh1close($save_stdout) or BAIL_OUT("cannot close saved stdout: $!"); 81b8851fccSafresh1$got = slurp($outfile); 82b8851fccSafresh1is($got, " Some random text.\n\n", 'Pod::Text pod2text function'); 83b8851fccSafresh1 84b8851fccSafresh1# Clean up. 85b8851fccSafresh1unlink($infile, $outfile); 86