Codebase list libtest-pod-perl / 142fcd4
Importing Test::Pod 1.26 Andy Lester 14 years ago
25 changed file(s) with 812 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 *~
1 Makefile
2 Makefile.old
3 blib/
4 pm_to_blib
0 Change log for Test::Pod
1
2 1.26 - Wed Jul 19 09:54:48 CDT 2006
3
4 No new functionality in this version.
5
6 [FIXES]
7 * Fixed a Win32 build bug.
8 * Fixed a bug in the SYNOPSIS.
9
10 1.24 - Wed Feb 1 15:18:06 PST 2006
11 [THINGS THAT MAY BREAK YOUR CODE]
12 * The long-deprecated pod_ok() is now gone, along with all its
13 constants.
14
15 [ENHANCEMENTS]
16 * Now runs properly under VMS. Thanks to Peter Edwards.
17
18 1.22 - Sun Oct 23 23:45:51 CDT 2005
19 [ENHANCEMENTS]
20 * Added check for lines with only whitespace before or after a
21 directive. Older POD formatters can get confused by such
22 lines since they goof up paragraph mode. (RT #6467)
23
24 [FIXES]
25 * Bumped up requirements to Test::Simple 0.62.
26
27 1.20 - Wed Jun 23 00:28:35 CDT 2004
28 [ENHANCEMENTS]
29 * Looks in blib/ if there is one, otherwise looks in lib/
30 * Thanks to David Wheeler for nudging.
31
32 1.18 - Fri May 28 23:48:28 CDT 2004
33 [FIXES]
34 * Now exports all_pod_files() as advertised.
35 * Also includes *.t files as Pod.
36
37 1.16 - Fri Apr 30 17:42:50 CDT 2004
38 [FIXES]
39 * Fixed a warning under 5.8.3. Also explicitly closes dir handles
40 when searching for POD.
41
42 1.14 - Wed Apr 28 23:38:29 CDT 2004
43 [ENHANCEMENTS]
44 * Now runs taint-safe. No longer uses File::Find. I'm trying to
45 get all my modules to run under -T correctly, so this is big.
46
47 1.12 - Sat Mar 13 10:34:06 CST 2004
48 [ENHANCEMENTS]
49 * all_pod_files() now picks up *.PL files.
50
51 1.10 - Tue Mar 9 23:27:16 CST 2004
52 [ENHANCEMENTS]
53 * Almost all of my coverage is almost to 100%.
54
55 [FIXES]
56 * Fixed some test bugs on Win32.
57 * Message problems if the file is missing.
58
59 1.08 - Wed Jan 21 00:40:07 CST 2004
60 No new features or fixes.
61
62 [FIXES]
63 * t/all_pod_files.t failed because in my zeal to be a good
64 cross-platform guy, I used File::Spec separators on lists to
65 compare against those coming from File::Find, which uses slashes.
66
67 1.06 - Sat Jan 10 08:47:55 CST 2004
68 No new features or fixes.
69
70 [FIXES]
71 * t/all_pod_files.t failed because all_pod_files() returns an
72 unsorted list. Fixed.
73
74 1.04 - Fri Jan 9 22:39:15 CST 2004
75 [ENHANCEMENTS]
76 * all_pod_files() can now take multiple start directories.
77 Thanks to David Wheeler for the patch.
78
79 1.03
80 [FIXES]
81 * All the *ok() functions now return the value of the underlying ok().
82
83 [DOCUMENTATION]
84 * All functions are now documented.
85
86 [INTERNALS]
87 * Removed valid_file, which was not being used.
88
89
90 1.02 - Mon Nov 10 09:07:39 CST 2003
91 No new functionality. If 1.00 installed for you, then you don't
92 need 1.02.
93
94 [FIXES]
95 * Fixed dumb test failure in t/all_pod_files.t.
96
97 [DOCUMENTATION]
98 * Spiffed up the SYNOPSIS.
99
100
101 1.00 - Mon Nov 10 00:06:30 CST 2003
102 [NEW FEATURES]
103 * Added all_pod_files_ok() method.
104
105 0.96 - Sat Oct 11 22:46:00 CST 2003
106 * Removed dependency on IO::Scalar, which was wrong.
107 * Requires newest, most-lenient Pod::Simple.
108 * Added various tests to the t/ hierarchy. Thanks to David Wheeler
109 for help on this.
110
111 0.95 - Mon Mar 3 09:35:00 CST 2002
112 * Rewrote to use Pod::Simple instead of Pod::Checker
113 * Deprecated the pod_ok function.
114 * Added pod_file_ok() to replace pod_ok().
115
116 0.90 - Tue Dec 3 18:59:39 CST 2002
117 * things seem to be going well, so this is not in beta :)
118 * cleanup up some formatting
119 * fixed the bad pod test which some Pod::Checker versions reported
120 extra errors
121
122 0.72 - Thu Nov 14 20:16:13 CST 2002
123 * cleaned up Makefile.PL and tests
124 * no code changes
125
126 0.71 - Mon Sep 9 10:58:22 CDT 2002
127 * added Test::Builder::Tester to PREREQ_PM
128
129 0.70 - Thu Sep 5 22:39:13 CDT 2002
130 * pod_ok shows POD errors and warnings if it fails
131 * you can give the test a name
0 Changes
1 MANIFEST
2 Makefile.PL
3 Pod.pm
4
5 t/00-load.t
6 t/all_pod_files.t
7 t/cut-outside-block.pod
8 t/cut-outside-block.t
9 t/empty-file.pod
10 t/good.t
11 t/item-ordering.pod
12 t/item-ordering.t
13 t/load.t
14 t/missing-file.t
15 t/pod.t
16 t/pod/good-pod-script
17 t/pod/good-pod-script
18 t/pod/good.pod
19 t/pod/no_pod.pod
20 t/selftest.t
21 t/spaced-directives.pod
22 t/spaced-directives.t
23 t/unknown-directive.pod
24 t/unknown-directive.t
25 META.yml Module meta-data (added by MakeMaker)
0 # http://module-build.sourceforge.net/META-spec.html
1 #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
2 name: Test-Pod
3 version: 1.26
4 version_from: Pod.pm
5 installdirs: site
6 requires:
7 File::Spec: 0
8 Pod::Simple: 2.04
9 Test::Builder::Tester: 1.02
10 Test::More: 0.62
11
12 distribution_type: module
13 generated_by: ExtUtils::MakeMaker version 6.30
0 # $Id: Makefile.PL 125 2005-10-24 04:55:20Z andy $
1 use ExtUtils::MakeMaker;
2
3 WriteMakefile (
4 'NAME' => 'Test::Pod',
5 'VERSION_FROM' => 'Pod.pm',
6 'PREREQ_PM' => {
7 'Pod::Simple' => '2.04',
8 'Test::More' => '0.62',
9 'Test::Builder::Tester' => '1.02',
10 'File::Spec' => 0,
11 },
12 clean => { FILES => 'Test-Pod-*' },
13 );
14
0 package Test::Pod;
1
2 use strict;
3
4 =head1 NAME
5
6 Test::Pod - check for POD errors in files
7
8 =head1 VERSION
9
10 Version 1.26
11
12 =cut
13
14 use vars qw( $VERSION );
15 $VERSION = '1.26';
16
17 =head1 SYNOPSIS
18
19 C<Test::Pod> lets you check the validity of a POD file, and report
20 its results in standard C<Test::Simple> fashion.
21
22 use Test::Pod tests => $num_tests;
23 pod_file_ok( $file, "Valid POD file" );
24
25 Module authors can include the following in a F<t/pod.t> file and
26 have C<Test::Pod> automatically find and check all POD files in a
27 module distribution:
28
29 use Test::More;
30 eval "use Test::Pod 1.00";
31 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
32 all_pod_files_ok();
33
34 You can also specify a list of files to check, using the
35 C<all_pod_files()> function supplied:
36
37 use strict;
38 use Test::More;
39 eval "use Test::Pod 1.00";
40 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
41 my @poddirs = qw( blib script );
42 all_pod_files_ok( all_pod_files( @poddirs ) );
43
44 Or even (if you're running under L<Apache::Test>):
45
46 use strict;
47 use Test::More;
48 eval "use Test::Pod 1.00";
49 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
50
51 my @poddirs = qw( blib script );
52 use File::Spec::Functions qw( catdir updir );
53 all_pod_files_ok(
54 all_pod_files( map { catdir updir, $_ } @poddirs )
55 );
56
57 =head1 DESCRIPTION
58
59 Check POD files for errors or warnings in a test file, using
60 C<Pod::Simple> to do the heavy lifting.
61
62 =cut
63
64 use 5.004;
65
66 use Pod::Simple;
67 use Test::Builder;
68 use File::Spec;
69
70 my $Test = Test::Builder->new;
71
72 sub import {
73 my $self = shift;
74 my $caller = caller;
75
76 for my $func ( qw( pod_file_ok all_pod_files all_pod_files_ok ) ) {
77 no strict 'refs';
78 *{$caller."::".$func} = \&$func;
79 }
80
81 $Test->exported_to($caller);
82 $Test->plan(@_);
83 }
84
85 =head1 FUNCTIONS
86
87 =head2 pod_file_ok( FILENAME[, TESTNAME ] )
88
89 C<pod_file_ok()> will okay the test if the POD parses correctly. Certain
90 conditions are not reported yet, such as a file with no pod in it at all.
91
92 When it fails, C<pod_file_ok()> will show any pod checking errors as
93 diagnostics.
94
95 The optional second argument TESTNAME is the name of the test. If it
96 is omitted, C<pod_file_ok()> chooses a default test name "POD test
97 for FILENAME".
98
99 =cut
100
101 sub pod_file_ok {
102 my $file = shift;
103 my $name = @_ ? shift : "POD test for $file";
104
105 if ( !-f $file ) {
106 $Test->ok( 0, $name );
107 $Test->diag( "$file does not exist" );
108 return;
109 }
110
111 my $checker = Pod::Simple->new;
112
113 $checker->output_string( \my $trash ); # Ignore any output
114 $checker->parse_file( $file );
115
116 my $ok = !$checker->any_errata_seen;
117 $Test->ok( $ok, $name );
118 if ( !$ok ) {
119 my $lines = $checker->{errata};
120 for my $line ( sort { $a<=>$b } keys %$lines ) {
121 my $errors = $lines->{$line};
122 $Test->diag( "$file ($line): $_" ) for @$errors;
123 }
124 }
125
126 return $ok;
127 } # pod_file_ok
128
129 =head2 all_pod_files_ok( [@files/@directories] )
130
131 Checks all the files in C<@files> for valid POD. It runs
132 L<all_pod_files()> on each file/directory, and calls the C<plan()> function for you
133 (one test for each function), so you can't have already called C<plan>.
134
135 If C<@files> is empty or not passed, the function finds all POD files in
136 the F<blib> directory if it exists, or the F<lib> directory if not.
137 A POD file is one that ends with F<.pod>, F<.pl> and F<.pm>, or any file
138 where the first line looks like a shebang line.
139
140 If you're testing a module, just make a F<t/pod.t>:
141
142 use Test::More;
143 eval "use Test::Pod 1.00";
144 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
145 all_pod_files_ok();
146
147 Returns true if all pod files are ok, or false if any fail.
148
149 =cut
150
151 sub all_pod_files_ok {
152 my @files = @_ ? @_ : all_pod_files();
153
154 $Test->plan( tests => scalar @files );
155
156 my $ok = 1;
157 foreach my $file ( @files ) {
158 pod_file_ok( $file, $file ) or undef $ok;
159 }
160 return $ok;
161 }
162
163 =head2 all_pod_files( [@dirs] )
164
165 Returns a list of all the Perl files in I<$dir> and in directories below.
166 If no directories are passed, it defaults to F<blib> if F<blib> exists,
167 or else F<lib> if not. Skips any files in CVS or .svn directories.
168
169 A Perl file is:
170
171 =over 4
172
173 =item * Any file that ends in F<.PL>, F<.pl>, F<.pm>, F<.pod> or F<.t>.
174
175 =item * Any file that has a first line with a shebang and "perl" on it.
176
177 =back
178
179 The order of the files returned is machine-dependent. If you want them
180 sorted, you'll have to sort them yourself.
181
182 =cut
183
184 sub all_pod_files {
185 my @queue = @_ ? @_ : _starting_points();
186 my @pod = ();
187
188 while ( @queue ) {
189 my $file = shift @queue;
190 if ( -d $file ) {
191 local *DH;
192 opendir DH, $file or next;
193 my @newfiles = readdir DH;
194 closedir DH;
195
196 @newfiles = File::Spec->no_upwards( @newfiles );
197 @newfiles = grep { $_ ne "CVS" && $_ ne ".svn" } @newfiles;
198
199 foreach my $newfile (@newfiles) {
200 my $filename = File::Spec->catfile( $file, $newfile );
201 if ( -f $filename ) {
202 push @queue, $filename;
203 }
204 else {
205 push @queue, File::Spec->catdir( $file, $newfile );
206 }
207 }
208 }
209 if ( -f $file ) {
210 push @pod, $file if _is_perl( $file );
211 }
212 } # while
213 return @pod;
214 }
215
216 sub _starting_points {
217 return 'blib' if -e 'blib';
218 return 'lib';
219 }
220
221 sub _is_perl {
222 my $file = shift;
223
224 return 1 if $file =~ /\.PL$/;
225 return 1 if $file =~ /\.p(l|m|od)$/;
226 return 1 if $file =~ /\.t$/;
227
228 local *FH;
229 open FH, $file or return;
230 my $first = <FH>;
231 close FH;
232
233 return 1 if defined $first && ($first =~ /^#!.*perl/);
234
235 return;
236 }
237
238 =head1 TODO
239
240 STUFF TO DO
241
242 Note the changes that are being made.
243
244 Note that you no longer can test for "no pod".
245
246 =head1 AUTHOR
247
248 Currently maintained by Andy Lester, C<< <andy at petdance.com> >>.
249
250 Originally by brian d foy.
251
252 =head1 ACKNOWLEDGEMENTS
253
254 Thanks to
255 David Wheeler
256 and
257 Peter Edwards
258 for contributions and to C<brian d foy> for the original code.
259
260 =head1 COPYRIGHT
261
262 Copyright 2006, Andy Lester, All Rights Reserved.
263
264 You may use, modify, and distribute this package under the
265 same terms as Perl itself.
266
267 =cut
268
269 1;
0 #!perl -T
1
2 use warnings;
3 use strict;
4 use Test::More tests => 1;
5
6 BEGIN {
7 use_ok( 'Test::Pod' );
8 }
9
10 diag( "Testing Test::Pod $Test::Pod::VERSION, Perl $], $^X" );
0 #!perl -Tw
1
2 use strict;
3
4 use Test::More tests => 2;
5
6 BEGIN {
7 use_ok( "Test::Pod" );
8 }
9
10 my @expected;
11 if ( $^O eq "VMS" ) {
12 @expected = (
13 File::Spec->catfile( 'blib', 'lib', 'Test', 'Pod.pm' ),
14 File::Spec->catfile( 't', 'pod', 'good-pod-script.' ),
15 File::Spec->catfile( 't', 'pod', 'good.pod' ),
16 File::Spec->catfile( 't', 'pod', 'no_pod.pod' ),
17 );
18 }
19 else {
20 # The expected files have slashes, not File::Spec separators, because
21 # that's how File::Find does it.
22 @expected = qw(
23 blib/lib/Test/Pod.pm
24 t/pod/good-pod-script
25 t/pod/good.pod
26 t/pod/no_pod.pod
27 );
28 }
29 my @files = sort map { lc } all_pod_files( "blib", "t/pod" );
30 @expected = sort map { lc } @expected;
31 s{\\}{/}g for @files, @expected;
32 is_deeply( \@files, \@expected, "Got all the distro files" );
0 # $Id: cut-outside-block.pod 48 2003-03-04 17:16:27Z petdance $
1
2 use strict;
3
4 =cut
5
6 =head1 COPYRIGHT
7
8 Copyright 2002, Andy Lester
9
10 =cut
11
12 use warnings;
0 #!perl -T
1
2 use strict;
3
4 use Test::Builder::Tester tests => 2;
5 use Test::More;
6
7 BEGIN {
8 use_ok( 'Test::Pod' );
9 }
10
11 BAD: {
12 my $file = 't/cut-outside-block.pod';
13 test_out( "not ok 1 - POD test for $file" );
14 pod_file_ok( $file );
15 test_fail(-1);
16 test_diag(
17 "$file (5): =cut found outside a pod block. Skipping to next block."
18 );
19 test_test( "$file is bad" );
20 }
(New empty file)
0 #!perl -T
1
2 use strict;
3
4 use Test::Builder::Tester tests => 3;
5 use Test::More;
6
7 BEGIN {
8 use_ok( 'Test::Pod' );
9 }
10
11
12 my $filename = "t/pod/good.pod";
13 GOOD: {
14 test_out( "ok 1 - Blargo!" );
15 pod_file_ok( $filename, "Blargo!" );
16 test_test( 'Handles good.pod OK' );
17 }
18
19 DEFAULT_NAME: {
20 test_out( "ok 1 - POD test for t/pod/good.pod" );
21 pod_file_ok( $filename );
22 test_test( 'Handles good.pod OK, and builds default name OK' );
23 }
0 # $Id: item-ordering.pod 53 2003-03-04 17:41:18Z petdance $
1
2 =head1 COPYRIGHT
3
4 Copyright 2002, Andy Lester
5
6 =cut
7
8 # Here's a list with items out of order
9
10 =over 4
11
12 =item 2
13
14 This is the first prime number
15
16 =item 3
17
18 This is the second prime number
19
20 =item 5
21
22 This is the third prime number
23
24 =back
25
26 =cut
27
28
29 # Here's a list with items that can't be
30
31 =over 4
32
33 Blah blah blah
34
35 =item 1
36
37 Item One
38
39 =item 2
40
41 Item 2
42
43 =cut
44
0 #!perl -T
1
2 use strict;
3
4 use Test::Builder::Tester tests => 2;
5 use Test::More;
6
7 BEGIN {
8 use_ok( 'Test::Pod' );
9 }
10
11 my $file = 't/item-ordering.pod';
12 test_out( "not ok 1 - POD test for $file" );
13 pod_file_ok( $file );
14 test_fail(-1);
15 test_diag(
16 "$file (32): You can't have =items (as at line 36) unless the first thing after the =over is an =item",
17 );
18 test_test( "$file is bad" );
0 #!perl -T
1
2 use Test::More tests=>1;
3
4 BEGIN {
5 use_ok( 'Test::Pod' );
6 }
0 #!perl -T
1
2 use strict;
3
4 use Test::Builder::Tester tests => 3;
5 use Test::More;
6
7 BEGIN {
8 use_ok( 'Test::Pod' );
9 }
10
11 MISSING_FILE: {
12 my $file = 't/non-existent.pod';
13 test_out( "not ok 1 - I hope the file is there" );
14 test_fail(+1);
15 pod_file_ok( $file, "I hope the file is there" );
16 test_diag( "$file does not exist" );
17 test_test( "$file is bad" );
18 }
19
20
21 MISSING_FILE_NO_MESSAGE: {
22 my $file = 't/non-existent.pod';
23 test_out( "not ok 1 - POD test for $file" );
24 test_fail(+1);
25 pod_file_ok( $file );
26 test_diag( "$file does not exist" );
27 test_test( "$file is bad" );
28 }
0 #!/usr/bin/perl
1
2 =head1 NAME
3
4 This is a pretend script that we need to check
5
6 =head1 DESCRIPTION
7
8 This is a pod file without errors.
9
10 =head1 AUTHOR
11
12 Andy Lester, garbage-address@aol.com
13
14 =head1 COPYRIGHT
15
16 Copyright 2004, Andy Lester
17
18 =cut
0 =head1 NAME
1
2 Test::Pod test pod -- a valid pod file
3
4 =head1 DESCRIPTION
5
6 This is a pod file without errors.
7
8 =head1 AUTHOR
9
10 Andy Lester, garbage-address@aol.com
11
12 =head1 COPYRIGHT
13
14 Copyright 2004, Andy Lester
15
16 =cut
0 Test::Pod test pod -- a valid pod file
1
2 This is a pod file without pod commands
3
4 Andy Lester, garbage-address@aol.com
5
6 Copyright 2004, Andy Lester
0 #!perl -Tw
1 use Test::More;
2 eval "use Test::Pod 1.00";
3 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
4 all_pod_files_ok();
0 #!perl -T
1
2 use Test::More tests=>2;
3
4 BEGIN {
5 use_ok( "Test::Pod" );
6 }
7
8 my $self = $INC{'Test/Pod.pm'};
9
10 pod_file_ok($self, "My own pod is OK");
11
0 =head1 NAME
1
2 Test::Pod test pod -- a valid pod file
3
4 =head1 DESCRIPTION
5
6 This is a pod file where there are invisible
7 spaces on either side of directives. One row
8 of spaces is just before the AUTHOR directive,
9 and one is right after the COPYRIGHT.
10
11 =head1 AUTHOR
12
13 Andy Lester, garbage-address@aol.com
14
15 =head1 COPYRIGHT
16
17 Copyright 2004, Andy Lester
18
19 =cut
0 #!perl -T
1
2 use strict;
3
4 use Test::More skip_all => "Not written yet";
5 use Test::Builder::Tester tests => 2;
6 use Test::More;
7
8 BEGIN {
9 use_ok( 'Test::Pod' );
10 }
11
12 BAD: {
13 my $name = 'Test name: Something not likely to accidentally occur!';
14 my $file = 't/spaced-rectives.pod';
15 test_out( "not ok 1 - $name" );
16 pod_file_ok( $file, $name );
17 test_fail(-1);
18 test_diag( "$file (9): Unknown directive: =over4",);
19 test_diag( "$file (13): Unknown directive: =under",);
20 test_test( "$name is bad" );
21 }
0 # $Id: unknown-directive.pod 91 2004-01-26 03:50:06Z petdance $
1
2 =head1 NAME
3
4 Test::Pod test pod -- a valid pod file
5
6 =head1 DESCRIPTION
7
8 =over4
9
10 This is a pod file with an incorrect =over.
11
12 =under 4
13
14 This is a pod file with a bad directive.
15
16 =head1 AUTHOR
17
18 brian d foy, E<lt>bdfoy@cpan.orgE<gt>
19
20 =head1 COPYRIGHT
21
22 Copyright 2002, brian d foy
23
24 =cut
0 #!perl -T
1
2 use strict;
3
4 use Test::Builder::Tester tests => 2;
5 use Test::More;
6
7 BEGIN {
8 use_ok( 'Test::Pod' );
9 }
10
11 BAD: {
12 my $name = 'Test name: Something not likely to accidentally occur!';
13 my $file = 't/unknown-directive.pod';
14 test_out( "not ok 1 - $name" );
15 pod_file_ok( $file, $name );
16 test_fail(-1);
17 test_diag( "$file (9): Unknown directive: =over4",);
18 test_diag( "$file (13): Unknown directive: =under",);
19 test_test( "$name is bad" );
20 }