| 1 |
use strict; |
| 2 |
use Test::More; |
| 3 |
use File::Spec; |
| 4 |
use File::Find; |
| 5 |
use File::Temp 'tempfile'; |
| 6 |
|
| 7 |
require './Makefile.PL'; |
| 8 |
# Loaded from Makefile.PL |
| 9 |
our %module = get_module_info(); |
| 10 |
|
| 11 |
my @files; |
| 12 |
my $blib = File::Spec->catfile(qw(blib lib)); |
| 13 |
find(\&wanted, grep { -d } ($blib)); |
| 14 |
|
| 15 |
#if( my $exe = $module{EXE_FILES}) { |
| 16 |
# push @files, @$exe; |
| 17 |
#}; |
| 18 |
|
| 19 |
plan tests => scalar @files; |
| 20 |
foreach my $file (@files) { |
| 21 |
synopsis_file_ok($file); |
| 22 |
} |
| 23 |
|
| 24 |
sub wanted { |
| 25 |
push @files, $File::Find::name if /\.p(l|m|od)$/ |
| 26 |
and $_ !~ /\bDSL\.pm$/; # we skip that one as it initializes immediately |
| 27 |
} |
| 28 |
|
| 29 |
sub synopsis_file_ok { |
| 30 |
my( $file ) = @_; |
| 31 |
my $name = "SYNOPSIS in $file compiles"; |
| 32 |
open my $fh, '<', $file |
| 33 |
or die "Couldn't read '$file': $!"; |
| 34 |
my @synopsis = map { s!^\s\s!!; $_ } # outdent all code for here-docs |
| 35 |
grep { /^\s\s/ } # extract all verbatim (=code) stuff |
| 36 |
grep { /^=head1\s+SYNOPSIS$/.../^=/ } # extract Pod synopsis |
| 37 |
<$fh>; |
| 38 |
if( @synopsis ) { |
| 39 |
my($tmpfh,$tempname) = tempfile(); |
| 40 |
print {$tmpfh} join '', @synopsis; |
| 41 |
close $tmpfh; # flush it |
| 42 |
my $output = `$^X -Ilib -c $tempname 2>&1`; |
| 43 |
if( $output =~ /\ssyntax OK$/ ) { |
| 44 |
pass $name; |
| 45 |
} else { |
| 46 |
fail $name; |
| 47 |
diag $output; |
| 48 |
diag $_ for @synopsis; |
| 49 |
}; |
| 50 |
unlink $tempname |
| 51 |
or warn "Couldn't clean up $tempname: $!"; |
| 52 |
} else { |
| 53 |
SKIP: { |
| 54 |
skip "$file has no SYNOPSIS section", 1; |
| 55 |
}; |
| 56 |
}; |
| 57 |
|
| 58 |
} |