Debian Codegraph @

script/pod2test

raw
1 #!perl
2
3 =pod
4
5 =head1 NAME
6
7 pod2test - (DEPRECATED) Convert embedded tests and code examples to .t files
8
9 =head1 SYNOPSIS
10
11 pod2test [-Mmodule] [input [output]]
12
13 =head1 DESCRIPTION
14
15 B<pod2test> is a front-end for L<Pod::Tests> (formerly Test::Inline 1).
16 It generates TAP-compatible .t testing scripts from embedded tests and
17 code examples.
18
19 If output is not specified, the resulting .t file will go to STDOUT.
20 Otherwise, it will go to the given output file. If input is not
21 given, it will draw from STDIN.
22
23 If the given file contains no tests or code examples, no output will
24 be given, no output file will be created and pod2test will exit with
25 1.
26
27 The Test::More module is made available to the testing blocks using
28 the 'no_plan' feature. Any further modules which should be used are
29 specified with -M. B<UNIMPLEMENTED>
30
31 =cut
32
33 use 5.005;
34 use strict;
35
36 our $VERSION = '1.20';
37
38 use File::Spec ();
39 use Pod::Tests ();
40 use Symbol ();
41
42 my($infile, $outfile) = @ARGV;
43 my($infh,$outfh);
44
45 if( defined $infile ) {
46 $infh = Symbol::gensym();
47 open($infh, $infile) or
48 die "Can't open the POD file $infile: $!";
49 } else {
50 $infh = \*STDIN;
51 }
52
53 my $p = Pod::Tests->new;
54 $p->parse_fh($infh);
55
56 # XXX Hack to put the filename into the #line directive
57 $p->{file} = $infile || '';
58
59 my @tests = $p->build_tests($p->tests);
60 my @examples = $p->build_examples($p->examples);
61
62 exit 1 unless @tests or @examples;
63
64
65 if( defined $outfile) {
66 $outfh = Symbol::gensym();
67 open($outfh, ">$outfile") or
68 die "Can't open the test file $outfile: $!";
69 } else {
70 $outfh = \*STDOUT;
71 }
72
73
74 my $perl = $^X; # XXX eventually this will be smarter.
75 print $outfh <<"TEST";
76 #!$perl -w
77 TEST
78
79 my $original_file = File::Spec->abs2rel($infile);
80
81 print $outfh sprintf <<'TEST', $original_file;
82
83 use Test::More 'no_plan';
84
85 package Catch;
86
87 sub TIEHANDLE {
88 my($class, $var) = @_;
89 return bless { var => $var }, $class;
90 }
91
92 sub PRINT {
93 my($self) = shift;
94 ${'main::'.$self->{var}} .= join '', @_;
95 }
96
97 sub OPEN {} # XXX Hackery in case the user redirects
98 sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want.
99
100 sub READ {}
101 sub READLINE {}
102 sub GETC {}
103 sub BINMODE {}
104
105 my $Original_File = '%s';
106
107 package main;
108
109 # pre-5.8.0's warns aren't caught by a tied STDERR.
110 $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; };
111 tie *STDOUT, 'Catch', '_STDOUT_' or die $!;
112 tie *STDERR, 'Catch', '_STDERR_' or die $!;
113
114 TEST
115
116 foreach my $test (@tests, @examples) {
117 print $outfh "$test\n";
118 }
119
120 =pod
121
122 =head1 BUGS and CAVEATS
123
124 This is a very simple rough cut. It only does very rudimentary tests
125 on the examples.
126
127 =head1 SUPPORT
128
129 This script has been superceded by C<inline2test> from the newer
130 L<Test::Inline> 2. Most testing code that currently works with
131 C<pod2test> should continue to work with the new version.
132
133 The most notable exceptions are C<=for begin> and C<=for end>, which
134 are deprecated in the newer version.
135
136 After upgrading L<Test::Inline>, L<Pod::Tests> and C<pod2test> were split
137 out to provide a compatibility package for legacy code.
138
139 C<pod2test> will stay in CPAN, but should remain unchanged indefinately,
140 with the exception of any minor bugs that will require squishing.
141
142 Bugs in this dist should be reported via the following URL. Feature requests
143 should not be submitted, as further development is now occuring in
144 L<Test::Inline>.
145
146 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Pod-Tests>
147
148 =head1 AUTHOR
149
150 Michael G Schwern E<lt>[email protected]<gt>
151
152 Adam Kennedy E<lt>[email protected]<gt>
153
154 =head1 SEE ALSO
155
156 L<Pod::Tests>, L<Test::Inline>
157
158 =head1 COPYRIGHT
159
160 Copyright 2005 - 2008 Adam Kennedy.
161
162 Copyright 2001 - 2003 Michael G Schwern.
163
164 This program is free software; you can redistribute
165 it and/or modify it under the same terms as Perl itself.
166
167 The full text of the license can be found in the
168 LICENSE file included with this module.
169
170 =cut