NAME

Test::Compile - Assert that your Perl files compile OK.

SYNOPSIS

    use Test::Compile qw();

    my $test = Test::Compile->new();
    $test->all_files_ok();
    $test->done_testing();

DESCRIPTION

Test::Compile lets you check the whether your perl modules and scripts compile properly, results are reported in standard Test::Simple fashion.

The basic usage - as shown above, will locate your perl files and test that they all compile.

Module authors can (and probably should) include the following in a t/00-compile.t file and have Test::Compile automatically find and check all Perl files in a module distribution:

    #!perl
    use strict;
    use warnings;
    use Test::Compile qw();
    
    my $test = Test::Compile->new();
    $test->all_files_ok();
    $test->done_testing();

METHODS

new()

The constructor, which actually returns a Test::Compile::Internal object. This gives you access to all the methods provided by Test::Compile::Internal, including those listed below.

all_files_ok(@dirs)

Looks for perl files and tests them all for compilation errors.

See "all_files_ok(@dirs)" in Test::Compile::Internal for the full documentation.

done_testing()

Declares that you are done testing, no more tests will be run after this point.

diag(@msgs)

Prints out the given @msgs. Like print, arguments are simply appended together.

Output will be indented and marked with a # so as not to interfere with test output. A newline will be put on the end if there isn't one already.

We encourage using this rather than calling print directly.

skip($reason)

Skips the current test, reporting the $reason.

FUNCTIONS

The use of the following functions is deprecated and strongly discouraged.

Instead, you should use the object oriented interface described in the "SYNOPSIS" and in Test::Compile::Internal.

They are automatically exported to your namespace, which is no longer considered best practise. At some stage in the future, this will stop and you'll have to import them explicitly to keep using them.

The object oriented methods also provide a more consistent interface. For example: all_pm_files_ok() calls the plan() function - so you can't call multiple test functions in the same test file.

all_pm_files_ok(@files)

This function is deprecated. Please use "all_pm_files_ok(@dirs)" in Test::Compile::Internal instead. It's pretty much the same, except it doesn't call the plan() function.

Checks all the perl module files it can find for compilation errors.

It uses all_pm_files(@files) to find the perl module 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 the object oriented interface.

Returns true if all Perl module files are ok, or false if any fail.

all_pl_files_ok(@files)

This function is deprecated. Please use "all_pl_files_ok(@dirs)" in Test::Compile::Internal instead. It's pretty much the same, except it doesn't call the plan() function.

Checks all the perl script files it can find for compilation errors.

It uses all_pl_files(@files) to find the perl script 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 the object oriented interface.

Returns true if all Perl script files are ok, or false if any fail.

pm_file_ok($filename, $testname)

This function is deprecated. Please use "all_pm_files_ok(@dirs)" in Test::Compile::Internal instead. It's pretty much the same, except it won't allow you to specify a test name, and it can handle more than one file at a time.

pm_file_ok() will okay the test if $filename compiles as a perl module.

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.

pl_file_ok($filename, $testname)

This function is deprecated. Please use "all_pl_files_ok(@dirs)" in Test::Compile::Internal instead. It's pretty much the same, except you can't specify a test name, and it can handle more than one file at a time.

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.

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)

This function is deprecated. Please use "all_pm_files(@dirs)" in Test::Compile::Internal instead.

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, .svn, or .git directories.

all_pl_files(@dirs)

This function is deprecated. Please use "all_pl_files(@dirs)" in Test::Compile::Internal instead.

Returns a list of all the perl script files - that is, any files in @dirs that either have a .pl extension, or have no extension and have a perl shebang line.

If @dirs is undefined, it searches script if script exists, or else bin if bin exists.

Skips any files in CVS, .svn, or .git directories.

all_files_ok(@dirs)

This function is deprecated. Please use "all_files_ok(@dirs)" in Test::Compile::Internal instead.

Checks all the perl files it can find for compilation errors.

If @dirs is defined then it is taken as an array of directories to be searched for perl files, otherwise it searches some default locations - see "all_pm_files(@dirs)" and "all_pl_files(@dirs)".

AUTHORS

Sagar R. Shah <srshah@cpan.org>, Marcel Grünauer, <marcel@cpan.org>, Evan Giles, <egiles@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2007-2023 by the authors.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Test::Compile::Internal provides the object oriented interface to (and the inner workings for) the Test::Compile functionality.

Test::Strict provides functions to ensure your perl files compile, with the 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.