2 # Copyright (C) 2001-2005, The Perl Foundation.
7 t/doc/pod.t - Pod document syntax tests
15 % perl t/doc/pod.t perl_module.pm perl_file.pl
19 Tests the Pod syntax for all files listed in F<MANIFEST> and
20 F<MANIFEST.generated> that appear to contain Pod markup. If any files
21 contain invalid POD markup, they are reported in the test output.
22 Use C<podchecker> to ferret out individual issues.
29 use lib qw( . lib ../lib ../../lib );
33 use ExtUtils::Manifest qw(maniread);
35 use vars qw(@failed_syntax @empty_description);
40 plan skip_all => 'Pod::Find not installed';
43 eval 'use Pod::Simple';
45 plan skip_all => 'Pod::Simple not installed';
52 # RT#44437 this should really be using src_dir instead of build_dir but it
53 # does not exist (yet)
54 my $build_dir = $PConfig{build_dir};
55 my $manifest = maniread("$build_dir/MANIFEST");
56 my $manifest_gen = maniread("$build_dir/MANIFEST.generated");
58 # if we have files passed in at the command line, use them
64 diag "finding files with POD, this may take a minute.";
65 @files = ( keys(%$manifest), keys(%$manifest_gen) );
68 foreach my $file (@files) {
69 $file = "$build_dir/$file";
71 # skip missing MANIFEST.generated files ( -e )
72 # skip binary files (including .pbc files) ( -B )
73 # skip files that pass the -e test because they resolve the .exe variant
76 # Skip the book, because it uses extended O'Reilly-specific POD
77 next if $file =~ m{docs/book/};
79 # skip files without POD
80 next unless Pod::Find::contains_pod( $file, 0 );
82 # skip POD generating scripts
83 next if $file =~ m/ops_summary\.pl/;
85 # skip file which includes malformed POD for other testing purposes
86 next if $file =~ m{t/tools/dev/searchops/samples\.pm};
88 # skip files with valid POD
89 if (file_pod_ok($file)) {
91 #check DESCRIPTION section on valid POD files
92 push @empty_description, $file if empty_description($file);
97 # report whatever is not skipped
98 push @failed_syntax, $file;
102 my $bad_syntax_files = join( "\n", @failed_syntax );
103 my $empty_description_files = join( "\n", @empty_description);
104 my $nempty_description = scalar( @empty_description );
106 is( $bad_syntax_files, q{}, 'Pod syntax correct' ); # only ok if everything passed
109 local $TODO = "not quite done yet";
110 is( $empty_description_files, q{}, 'All Pod files have non-empty DESCRIPTION sections' );
113 diag("You should use podchecker to check the failed files.\n")
114 if $bad_syntax_files;
116 diag("Found $nempty_description files without DESCRIPTION sections.\n")
117 if $nempty_description;
119 # Pulled from Test::Pod
122 my $checker = Pod::Simple->new;
124 $checker->output_string( \my $trash ); # Ignore any output
125 $checker->parse_file($file);
127 return !$checker->any_errata_seen;
130 sub empty_description {
133 use Pod::Simple::PullParser;
134 my $parser = Pod::Simple::PullParser->new;
135 $parser->set_source( $file );
136 my $description = $parser->get_description;
138 if ( $description =~ m{^\s*$}m ) {
147 # cperl-indent-level: 4
150 # vim: expandtab shiftwidth=4: