Test::Compile - Check whether Perl files compile correctly.
use Test::Compile; all_pm_files_ok();
Test::Compile lets you check the whether your perl modules and scripts compile properly, and report its results in standard Test::Simple fashion.
Test::Compile
Test::Simple
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 all_pm_files() function supplied:
all_pm_files()
my @pmdirs = qw(blib script); all_pm_files_ok(all_pm_files(@pmdirs));
all_pm_files_ok(@files)
Checks all the perl module files it can find for compilation errors.
It uses all_pm_files(@files) to find the perl module files.
all_pm_files(@files)
It also calls the plan() function for you (one test for each module), so you can't have already called plan. Unfortunately, this also means you can't use this function with all_pl_files_ok(). If this is a problem you should really be using Test::Compile::Internal.
plan()
plan
all_pl_files_ok()
Returns true if all Perl module files are ok, or false if any fail.
Module authors can include the following in a t/00_compile.t file and have Test::Compile 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();
all_pl_files_ok(@files)
Checks all the perl script files it can find for compilation errors.
It uses all_pl_files(@files) to find the perl script files.
all_pl_files(@files)
It also calls the plan() function for you (one test for each script), so you can't have already called plan. Unfortunately, this also means you can't use this function with all_pm_files_ok(). If this is a problem you should really be using Test::Compile::Internal.
all_pm_files_ok()
Returns true if all Perl script files are ok, or false if any fail.
Module authors can include the following in a t/00_compile_scripts.t file and have Test::Compile 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();
pm_file_ok($filename,$testname)
pm_file_ok() will okay the test if $filename compiles as a perl module.
pm_file_ok()
The optional second argument $testname is the name of the test. If it is omitted, pm_file_ok() chooses a default test name Compile test for $filename.
$testname
Compile test for $filename
pl_file_ok($filename,$testname)
pl_file_ok() 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 script/filename.
pl_file_ok()
script/filename
The optional second argument $testname is the name of the test. If it is omitted, pl_file_ok() chooses a default test name Compile test for $filename.
all_pm_files(@dirs)
Returns a list of all the perl module files - that is, files ending in .pm - in @dirs and in directories below. If no directories are passed, it defaults to blib if blib exists, or else lib if not. Skips any files in CVS or .svn directories.
CVS
.svn
The order of the files returned is machine-dependent. If you want them sorted, you'll have to sort them yourself.
all_pl_files(@dirs)
Returns a list of all the perl script files - that is, files ending in .pl or with no extension. Directory arguments are searched recursively . If @dirs is undefined, it defaults to script if script exists, or else bin if bin exists. Skips any files in CVS or .svn directories.
Sagar R. Shah <srshah@cpan.org>, Marcel Grünauer, <marcel@cpan.org>, Evan Giles, <egiles@cpan.org>
<srshah@cpan.org>
<marcel@cpan.org>
<egiles@cpan.org>
Copyright 2007-2013 by the authors.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Test::Compile::Internal provides an object oriented interface to the Test::Compile functionality.
Test::Strict proveds functions to ensure your perl files comnpile, with added bonus that it will check you have used strict in all your files. Test::LoadAllModules just handles modules, not script files, but has more fine-grained control.
To install Test::Compile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Compile
CPAN shell
perl -MCPAN -e shell install Test::Compile
For more information on module installation, please visit the detailed CPAN module installation guide.