Test::Compile(3pm)
π NAME π
Test::Compile β Assert that your Perl files compile OK.
Okay so this is the Test::Compile(3pm) page from the User Contributed Perl Documentation section, and we are about to make sure your Perl files pass their literal vibe check. No cap. π
πΈ SYNOPSIS πΈ
use Test::Compile qw();
my $test = Test::Compile->new();
$test->all_files_ok();
$test->done_testing();
π¦ DESCRIPTION π¦
Test::Compile lets you check whether your perl modules and scripts compile properly β and the results are reported in standard Test::Simple fashion. Slay. β¨
The basic usage, like the synopsis above, will locate your perl files and test that they all compile. Iconic behavior, honestly.
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 aTest::Compile::Internalobject. This gives you access to all the methods provided byTest::Compile::Internal, including those listed below.all_files_ok(@dirs)β Looks for perl files and tests them all for compilation errors. Seeall_files_ok(@dirs)inTest::Compile::Internalfor the full documentation.done_testing()β Declares that you are done testing; no more tests will be run after this point. Periodt.diag(@msgs)β Prints out the given@msgs. Likeprint, 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 callingprintdirectly. π«Ά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 useall_pm_files_ok(@dirs)inTest::Compile::Internalinstead. Itβs pretty much the same, except it doesnβt call theplan()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 useall_pl_files_ok(@dirs)inTest::Compile::Internalinstead. Itβs pretty much the same, except it doesnβt call theplan()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 useall_pm_files_ok(@dirs)inTest::Compile::Internalinstead. 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 useall_pl_files_ok(@dirs)inTest::Compile::Internalinstead. 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 useall_pm_files(@dirs)inTest::Compile::Internalinstead.
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 useall_pl_files(@dirs)inTest::Compile::Internalinstead.
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 useall_files_ok(@dirs)inTest::Compile::Internalinstead.
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::Internalprovides the object oriented interface to β and the inner workings for β theTest::Compilefunctionality.Test::Strictprovides functions to ensure your perl files compile, with the added bonus that it will check you have usedstrictin all your files.Test::LoadAllModulesjust handles modules, not script files, but has more fine-grained control.
okay thatβs the whole Test::Compile(3pm) manual, from perl v5.42.0, dated 2024-05-06 β bye bestie, go make those files compile πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Compile 3.3.3-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms