Commit | Line | Data |
42ae9e1d |
1 | #!/usr/bin/perl -w |
42ae9e1d |
2 | # |
3 | # pod-parser.t -- Tests for backward compatibility with Pod::Parser. |
4 | # |
eccdc4d7 |
5 | # Copyright 2006, 2008 by Russ Allbery <rra@stanford.edu> |
42ae9e1d |
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 | BEGIN { |
11 | chdir 't' if -d 't'; |
12 | if ($ENV{PERL_CORE}) { |
13 | @INC = '../lib'; |
14 | } else { |
15 | unshift (@INC, '../blib/lib'); |
16 | } |
17 | unshift (@INC, '../blib/lib'); |
18 | $| = 1; |
eccdc4d7 |
19 | print "1..4\n"; |
42ae9e1d |
20 | } |
21 | |
eccdc4d7 |
22 | my $loaded; |
23 | |
42ae9e1d |
24 | END { |
25 | print "not ok 1\n" unless $loaded; |
26 | } |
27 | |
28 | use Pod::Man; |
29 | use Pod::Text; |
eccdc4d7 |
30 | use strict; |
42ae9e1d |
31 | |
32 | $loaded = 1; |
33 | print "ok 1\n"; |
34 | |
35 | my $parser = Pod::Man->new or die "Cannot create parser\n"; |
36 | open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n"; |
37 | print TMP "Some random B<text>.\n"; |
38 | close TMP; |
39 | open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n"; |
40 | $parser->parse_from_file ({ -cutting => 0 }, 'tmp.pod', \*OUT); |
41 | close OUT; |
42 | open (OUT, 'out.tmp') or die "Cannot open out.tmp: $!\n"; |
43 | while (<OUT>) { last if /^\.nh/ } |
44 | my $output; |
45 | { |
46 | local $/; |
47 | $output = <OUT>; |
48 | } |
49 | close OUT; |
50 | if ($output eq "Some random \\fBtext\\fR.\n") { |
51 | print "ok 2\n"; |
52 | } else { |
53 | print "not ok 2\n"; |
54 | print "Expected\n========\nSome random \\fBtext\\fR.\n\n"; |
55 | print "Output\n======\n$output\n"; |
56 | } |
57 | |
58 | $parser = Pod::Text->new or die "Cannot create parser\n"; |
59 | open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n"; |
60 | $parser->parse_from_file ({ -cutting => 0 }, 'tmp.pod', \*OUT); |
61 | close OUT; |
62 | open (OUT, 'out.tmp') or die "Cannot open out.tmp: $!\n"; |
63 | { |
64 | local $/; |
65 | $output = <OUT>; |
66 | } |
67 | close OUT; |
68 | if ($output eq " Some random text.\n\n") { |
69 | print "ok 3\n"; |
70 | } else { |
71 | print "not ok 3\n"; |
72 | print "Expected\n========\n Some random text.\n\n\n"; |
73 | print "Output\n======\n$output\n"; |
74 | } |
75 | |
eccdc4d7 |
76 | # Test the pod2text function, particularly with only one argument. |
77 | open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n"; |
78 | print TMP "=pod\n\nSome random B<text>.\n"; |
79 | close TMP; |
80 | open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n"; |
81 | open (SAVE, '>&STDOUT') or die "Cannot dup stdout: $!\n"; |
82 | open (STDOUT, '>&OUT') or die "Cannot replace stdout: $!\n"; |
83 | pod2text ('tmp.pod'); |
84 | close OUT; |
85 | open (STDOUT, '>&SAVE') or die "Cannot fix stdout: $!\n"; |
86 | close SAVE; |
87 | open (OUT, 'out.tmp') or die "Cannot open out.tmp: $!\n"; |
88 | { |
89 | local $/; |
90 | $output = <OUT>; |
91 | } |
92 | close OUT; |
93 | if ($output eq " Some random text.\n\n") { |
94 | print "ok 4\n"; |
95 | } else { |
96 | print "not ok 4\n"; |
97 | print "Expected\n========\n Some random text.\n\n\n"; |
98 | print "Output\n======\n$output\n"; |
99 | } |
100 | |
42ae9e1d |
101 | unlink ('tmp.pod', 'out.tmp'); |
102 | exit 0; |