#!/usr/bin/perl
use
5.012;
BEGIN {
use_ok(
'Pod::Man'
);
use_ok(
'Pod::Text'
);
}
my
$tmpdir
= File::Spec->catdir(
't'
,
'tmp'
);
if
(!-d
$tmpdir
) {
mkdir
(
$tmpdir
, 0777);
}
my
$infile
= File::Spec->catfile(
't'
,
'tmp'
,
"tmp$$.pod"
);
open
(
my
$input
,
'>'
,
$infile
) or BAIL_OUT(
"cannot create $infile: $!"
);
print
{
$input
}
"Some random B<text>.\n"
or BAIL_OUT(
"cannot write to $infile: $!"
);
close
(
$input
) or BAIL_OUT(
"cannot write to $infile: $!"
);
my
$parser
= Pod::Man->new;
isa_ok(
$parser
,
'Pod::Man'
,
'Pod::Man parser object'
);
my
$outfile
= File::Spec->catfile(
't'
,
'tmp'
,
"tmp$$.man"
);
open
(
my
$output
,
'>'
,
$outfile
) or BAIL_OUT(
"cannot open $outfile: $!"
);
$parser
->parse_from_file({
-cutting
=> 0 },
$infile
,
$output
);
close
(
$output
) or BAIL_OUT(
"cannot write to $outfile: $!"
);
my
$got
= slurp(
$outfile
,
'man'
);
is(
$got
,
"Some random \\fBtext\\fR.\n"
,
'Pod::Man -cutting output'
);
unlink
(
$outfile
);
$parser
= Pod::Text->new;
isa_ok(
$parser
,
'Pod::Text'
,
'Pod::Text parser object'
);
$outfile
= File::Spec->catfile(
't'
,
'tmp'
,
"tmp$$.txt"
);
open
(
$output
,
'>'
,
$outfile
) or BAIL_OUT(
"cannot open $outfile: $!"
);
$parser
->parse_from_file({
-cutting
=> 0 },
$infile
,
$output
);
close
(
$output
) or BAIL_OUT(
"cannot write to $outfile: $!"
);
$got
= slurp(
$outfile
);
is(
$got
,
" Some random text.\n\n"
,
'Pod::Text -cutting output'
);
unlink
(
$outfile
);
unlink
(
$infile
);
open
(
$input
,
'>'
,
$infile
) or BAIL_OUT(
"cannot create $infile: $!"
);
print
{
$input
}
"=pod\n\nSome random B<text>.\n"
or BAIL_OUT(
"cannot write to $infile: $!"
);
close
(
$input
) or BAIL_OUT(
"cannot write to $infile: $!"
);
open
(
$output
,
'>'
,
$outfile
) or BAIL_OUT(
"cannot open $outfile: $!"
);
open
(
my
$save_stdout
,
'>&'
, STDOUT) or BAIL_OUT(
"cannot dup stdout: $!"
);
open
(STDOUT,
'>&'
,
$output
) or BAIL_OUT(
"cannot redirect stdout: $!"
);
pod2text(
$infile
);
close
(
$output
) or BAIL_OUT(
"cannot write to $outfile: $!"
);
open
(STDOUT,
'>&'
,
$save_stdout
) or BAIL_OUT(
"cannot fix stdout: $!"
);
close
(
$save_stdout
) or BAIL_OUT(
"cannot close saved stdout: $!"
);
$got
= slurp(
$outfile
);
is(
$got
,
" Some random text.\n\n"
,
'Pod::Text pod2text function'
);
unlink
(
$infile
,
$outfile
);