This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Pod-Simple-3.07
[perl5.git] / lib / Pod / t / user.t
1 #!perl
2
3 # Purpose: test UserPreamble and UserPostamble
4 # It's a minor variation of 'pod2latex.t',
5 # subject to the same limitations.
6 #   Variant provided by
7 #       Adriano Rodrigues Ferreira <ferreira@triang.com.br>
8
9 use Test;
10 use strict;
11
12 BEGIN { plan tests => 17 }
13
14 use Pod::LaTeX;
15
16 # The link parsing changed between v0.22 and v0.30 of Pod::ParseUtils
17 use Pod::ParseUtils;
18 my $linkver = $Pod::ParseUtils::VERSION;
19
20 # Set up an END block to remove the test output file
21 END {
22   unlink "test.tex";
23 };
24
25 ok(1);
26
27 # First thing to do is to read the expected output from
28 # the DATA filehandle and store it in a scalar.
29 # Do this until we read an =pod
30 my @reference;
31 while (my $line = <DATA>) {
32   last if $line =~ /^=pod/;
33   push(@reference,$line);
34 }
35
36 my $user_preamble = <<PRE;
37
38 \\documentclass{article}
39
40 \\begin{document}
41 PRE
42
43 my $user_postamble = <<POST;
44 \\end{document}
45
46 POST
47
48 # Create a new parser
49 my %params = (
50         UserPreamble => $user_preamble,
51         UserPostamble => $user_postamble
52 );
53
54 my $parser = Pod::LaTeX->new(%params);
55 ok($parser);
56
57 # Create an output file
58 open(OUTFH, "> test.tex" ) or die "Unable to open test tex file: $!\n";
59
60 # Read from the DATA filehandle and write to a new output file
61 # Really want to write this to a scalar
62 $parser->parse_from_filehandle(\*DATA,\*OUTFH);
63
64 close(OUTFH) or die "Error closing OUTFH test.tex: $!\n";
65
66 # Now read in OUTFH and compare
67 open(INFH, "< test.tex") or die "Unable to read test tex file: $!\n";
68 my @output = <INFH>;
69
70 ok(@output, @reference);
71
72 for my $i (0..$#reference) {
73   next if $reference[$i] =~ /^%%/; # skip timestamp comments
74   ok($output[$i], $reference[$i]);
75 }
76
77 close(INFH) or die "Error closing INFH test.tex: $!\n";
78
79
80 __DATA__
81
82 \documentclass{article}
83
84 \begin{document}
85
86 %%  Latex generated from POD in document (unknown)
87 %%  Using the perl module Pod::LaTeX
88 %%  Converted on Wed Jan 14 19:04:22 2004
89
90 %%  Preamble supplied by user.
91
92 \section{POD\label{POD}\index{POD}}
93
94
95 This is a POD file, very simple. \textit{Bye}.
96
97 \end{document}
98
99 =pod
100
101 =head1 POD
102
103 This is a POD file, very simple. I<Bye>.
104