package Test::Compile; use 5.006; use warnings; use strict; use Test::Builder; use UNIVERSAL::require; use Test::Compile::Internal; our $VERSION = '0.23'; my $Test = Test::Compile::Internal->new(); _verbose(1); =head1 NAME Test::Compile - Check whether Perl files compile correctly. =head1 SYNOPSIS use Test::Compile; all_pm_files_ok(); =head1 DESCRIPTION C lets you check the whether your perl modules and scripts compile properly, and report its results in standard C fashion. The basic usage - as shown above, will find all pm files and test that they all compile. You can explicitly specify the list of directories to check, using the C function supplied: my @pmdirs = qw(blib script); all_pm_files_ok(all_pm_files(@pmdirs)); =cut sub import { my $self = shift; my $caller = caller; for my $func ( qw( pm_file_ok pl_file_ok all_pm_files all_pl_files all_pm_files_ok all_pl_files_ok ) ) { no strict 'refs'; *{ $caller . "::" . $func } = \&$func; } $Test->exported_to($caller); $Test->plan(@_); } =head1 FUNCTIONS =over 4 =item C Checks all the files in C<@files> for compilation. It runs L on each file/directory, and calls the C function for you (one test for each module), so you can't have already called C. If C<@files> is empty or not passed, the function finds all Perl module files in the F directory if it exists, or the F directory if not. A Perl module file is one that ends with F<.pm>. Returns true if all Perl module files are ok, or false if any fail. Module authors can include the following in a F file and have C automatically find and check all Perl module files in a module distribution: #!perl -w use strict; use warnings; use Test::More; eval "use Test::Compile"; Test::More->builder->BAIL_OUT( "Test::Compile required for testing compilation") if $@; all_pm_files_ok(); =cut sub all_pm_files_ok { my @files = @_ ? @_ : all_pm_files(); $Test->plan(tests => scalar @files); my $ok = 1; for (@files) { pm_file_ok($_) or undef $ok; } $ok; } =item C Checks all the files in C<@files> for compilation. It runs L on each file, and calls the C function for you (one test for each script), so you can't have already called C. If C<@files> is empty or not passed, the function uses all_pl_files() to find scripts to test. Returns true if all Perl module files are ok, or false if any fail. Module authors can include the following in a F file and have C automatically find and check all Perl script files in a module distribution: #!perl -w use strict; use warnings; use Test::More; eval "use Test::Compile"; plan skip_all => "Test::Compile required for testing compilation" if $@; all_pl_files_ok(); =cut sub all_pl_files_ok { my @files = @_ ? @_ : all_pl_files(); $Test->skip_all("no pl files found") unless @files; $Test->plan(tests => scalar @files); my $ok = 1; for (@files) { pl_file_ok($_) or undef $ok; } $ok; } =item C C will okay the test if $filename compiles as a perl module. The optional second argument C<$testname> is the name of the test. If it is omitted, C chooses a default test name C. =cut sub pm_file_ok { my ($file,$name) = @_; $name ||= "Compile test for $file"; my $ok = $Test->pm_file_compiles($file); $Test->ok($ok, $name); $Test->diag("$file does not compile") unless $ok; return $ok; } =item C C will okay the test if $filename compiles as a perl script. You need to give the path to the script relative to this distribution's base directory. So if you put your scripts in a 'top-level' directory called script the argument would be C