| 1 | package Test::Compile; | ||||||||||||
| 2 | |||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 8 | ▶ | use version; our $VERSION = version->declare("v3.3.3"); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 8 | ▶ | use parent 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 8 | ▶ | use Test::Compile::Internal; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 8 | my $Test = Test::Compile::Internal->new(); | |||||||||||
| 11 | |||||||||||||
| 12 | =head1 NAME | ||||||||||||
| 13 | |||||||||||||
| 14 | Test::Compile - Assert that your Perl files compile OK. | ||||||||||||
| 15 | |||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||
| 17 | |||||||||||||
| 18 | use Test::Compile qw(); | ||||||||||||
| 19 | |||||||||||||
| 20 | my $test = Test::Compile->new(); | ||||||||||||
| 21 | $test->all_files_ok(); | ||||||||||||
| 22 | $test->done_testing(); | ||||||||||||
| 23 | |||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||
| 25 | |||||||||||||
| 26 | C<Test::Compile> lets you check the whether your perl modules and scripts | ||||||||||||
| 27 | compile properly, results are reported in standard C<Test::Simple> fashion. | ||||||||||||
| 28 | |||||||||||||
| 29 | The basic usage - as shown above, will locate your perl files and test that they | ||||||||||||
| 30 | all compile. | ||||||||||||
| 31 | |||||||||||||
| 32 | Module authors can (and probably should) include the following in a F<t/00-compile.t> | ||||||||||||
| 33 | file and have C<Test::Compile> automatically find and check all Perl files | ||||||||||||
| 34 | in a module distribution: | ||||||||||||
| 35 | |||||||||||||
| 36 | #!perl | ||||||||||||
| 37 | use strict; | ||||||||||||
| 38 | use warnings; | ||||||||||||
| 39 | use Test::Compile qw(); | ||||||||||||
| 40 | |||||||||||||
| 41 | my $test = Test::Compile->new(); | ||||||||||||
| 42 | $test->all_files_ok(); | ||||||||||||
| 43 | $test->done_testing(); | ||||||||||||
| 44 | |||||||||||||
| 45 | =cut | ||||||||||||
| 46 | |||||||||||||
| 47 | 8 | our @EXPORT = qw( | |||||||||||
| 48 | pm_file_ok | ||||||||||||
| 49 | pl_file_ok | ||||||||||||
| 50 | |||||||||||||
| 51 | all_pm_files_ok | ||||||||||||
| 52 | all_pl_files_ok | ||||||||||||
| 53 | |||||||||||||
| 54 | all_pm_files | ||||||||||||
| 55 | all_pl_files | ||||||||||||
| 56 | ); | ||||||||||||
| 57 | 8 | our @EXPORT_OK = qw( | |||||||||||
| 58 | pm_file_ok | ||||||||||||
| 59 | pl_file_ok | ||||||||||||
| 60 | |||||||||||||
| 61 | all_files_ok | ||||||||||||
| 62 | all_pm_files_ok | ||||||||||||
| 63 | all_pl_files_ok | ||||||||||||
| 64 | |||||||||||||
| 65 | all_pm_files | ||||||||||||
| 66 | all_pl_files | ||||||||||||
| 67 | ); | ||||||||||||
| 68 | 8 | our %EXPORT_TAGS = ('all' => \@EXPORT_OK); | |||||||||||
| 69 | |||||||||||||
| 70 | =head1 METHODS | ||||||||||||
| 71 | |||||||||||||
| 72 | =over 4 | ||||||||||||
| 73 | |||||||||||||
| 74 | =item C<new()> | ||||||||||||
| 75 | |||||||||||||
| 76 | The constructor, which actually returns a | ||||||||||||
| 77 | L<Test::Compile::Internal> object. This gives you access to all the methods provided by | ||||||||||||
| 78 | C<Test::Compile::Internal>, including those listed below. | ||||||||||||
| 79 | |||||||||||||
| 80 | =cut | ||||||||||||
| 81 | |||||||||||||
| 82 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 83 | 1 | my $class = shift; | |||||||||||
| 84 | 1 | return Test::Compile::Internal->new(@_); | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | =item C<all_files_ok(@dirs)> | ||||||||||||
| 88 | |||||||||||||
| 89 | Looks for perl files and tests them all for compilation errors. | ||||||||||||
| 90 | |||||||||||||
| 91 | See L<Test::Compile::Internal/all_files_ok(@dirs)> for the full documentation. | ||||||||||||
| 92 | |||||||||||||
| 93 | =item C<done_testing()> | ||||||||||||
| 94 | |||||||||||||
| 95 | Declares that you are done testing, no more tests will be run after this point. | ||||||||||||
| 96 | |||||||||||||
| 97 | =item C<diag(@msgs)> | ||||||||||||
| 98 | |||||||||||||
| 99 | Prints out the given C<@msgs>. Like print, arguments are simply appended | ||||||||||||
| 100 | together. | ||||||||||||
| 101 | |||||||||||||
| 102 | Output will be indented and marked with a # so as not to interfere with | ||||||||||||
| 103 | test output. A newline will be put on the end if there isn't one already. | ||||||||||||
| 104 | |||||||||||||
| 105 | We encourage using this rather than calling print directly. | ||||||||||||
| 106 | |||||||||||||
| 107 | =item C<skip($reason)> | ||||||||||||
| 108 | |||||||||||||
| 109 | Skips the current test, reporting the C<$reason>. | ||||||||||||
| 110 | |||||||||||||
| 111 | =back | ||||||||||||
| 112 | |||||||||||||
| 113 | =head1 FUNCTIONS | ||||||||||||
| 114 | |||||||||||||
| 115 | The use of the following functions is deprecated and strongly discouraged. | ||||||||||||
| 116 | |||||||||||||
| 117 | Instead, you should use the object oriented interface described in the L</SYNOPSIS> | ||||||||||||
| 118 | and in L<Test::Compile::Internal>. | ||||||||||||
| 119 | |||||||||||||
| 120 | They are automatically exported to your namespace, which is | ||||||||||||
| 121 | no longer considered best practise. At some stage in the future, this will | ||||||||||||
| 122 | stop and you'll have to import them explicitly to keep using them. | ||||||||||||
| 123 | |||||||||||||
| 124 | The object oriented methods also provide a more consistent interface. | ||||||||||||
| 125 | For example: C<all_pm_files_ok()> calls the C<plan()> function - so you can't call | ||||||||||||
| 126 | multiple test functions in the same test file. | ||||||||||||
| 127 | |||||||||||||
| 128 | =over 4 | ||||||||||||
| 129 | |||||||||||||
| 130 | =item C<all_pm_files_ok(@files)> | ||||||||||||
| 131 | |||||||||||||
| 132 | B<This function is deprecated>. Please use | ||||||||||||
| 133 | L<Test::Compile::Internal/all_pm_files_ok(@dirs)> instead. It's pretty much the | ||||||||||||
| 134 | same, except it doesn't call the C<plan()> function. | ||||||||||||
| 135 | |||||||||||||
| 136 | Checks all the perl module files it can find for compilation errors. | ||||||||||||
| 137 | |||||||||||||
| 138 | It uses C<all_pm_files(@files)> to find the perl module files. | ||||||||||||
| 139 | |||||||||||||
| 140 | It also calls the C<plan()> function for you (one test for each module), so | ||||||||||||
| 141 | you can't have already called C<plan()>. Unfortunately, this also means | ||||||||||||
| 142 | you can't use this function with C<all_pl_files_ok()>. If this is a problem | ||||||||||||
| 143 | you should really be using the object oriented interface. | ||||||||||||
| 144 | |||||||||||||
| 145 | Returns true if all Perl module files are ok, or false if any fail. | ||||||||||||
| 146 | |||||||||||||
| 147 | =cut | ||||||||||||
| 148 | |||||||||||||
| 149 | 1 | ▶ | sub all_pm_files_ok { | ||||||||||
|
Subroutine
all_pm_files_ok: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 150 | 1 | ▶ | my @files = @_ ? @_ : all_pm_files(); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 151 | 1 | $Test->plan(tests => scalar @files); | |||||||||||
| 152 | 1 | return $Test->all_pm_files_ok(@files); | |||||||||||
| 153 | } | ||||||||||||
| 154 | |||||||||||||
| 155 | =item C<all_pl_files_ok(@files)> | ||||||||||||
| 156 | |||||||||||||
| 157 | B<This function is deprecated>. Please use | ||||||||||||
| 158 | L<Test::Compile::Internal/all_pl_files_ok(@dirs)> instead. It's pretty much the | ||||||||||||
| 159 | same, except it doesn't call the C<plan()> function. | ||||||||||||
| 160 | |||||||||||||
| 161 | Checks all the perl script files it can find for compilation errors. | ||||||||||||
| 162 | |||||||||||||
| 163 | It uses C<all_pl_files(@files)> to find the perl script files. | ||||||||||||
| 164 | |||||||||||||
| 165 | It also calls the C<plan()> function for you (one test for each script), so | ||||||||||||
| 166 | you can't have already called C<plan>. Unfortunately, this also means | ||||||||||||
| 167 | you can't use this function with C<all_pm_files_ok()>. If this is a problem | ||||||||||||
| 168 | you should really be using the object oriented interface. | ||||||||||||
| 169 | |||||||||||||
| 170 | Returns true if all Perl script files are ok, or false if any fail. | ||||||||||||
| 171 | |||||||||||||
| 172 | =cut | ||||||||||||
| 173 | |||||||||||||
| 174 | 1 | ▶ | sub all_pl_files_ok { | ||||||||||
|
Subroutine
all_pl_files_ok: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 175 | 1 | ▶ | my @files = @_ ? @_ : all_pl_files(); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 176 | 1 | ▶ | $Test->skip_all("no pl files found") unless @files; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 177 | 1 | $Test->plan(tests => scalar @files); | |||||||||||
| 178 | 1 | $Test->all_pl_files_ok(@files); | |||||||||||
| 179 | } | ||||||||||||
| 180 | |||||||||||||
| 181 | =item C<pm_file_ok($filename, $testname)> | ||||||||||||
| 182 | |||||||||||||
| 183 | B<This function is deprecated>. Please use | ||||||||||||
| 184 | L<Test::Compile::Internal/all_pm_files_ok(@dirs)> instead. It's pretty much the | ||||||||||||
| 185 | same, except it won't allow you to specify a test name, and it can handle more than | ||||||||||||
| 186 | one file at a time. | ||||||||||||
| 187 | |||||||||||||
| 188 | C<pm_file_ok()> will okay the test if $filename compiles as a perl module. | ||||||||||||
| 189 | |||||||||||||
| 190 | The optional second argument C<$testname> is the name of the test. If it is | ||||||||||||
| 191 | omitted, C<pm_file_ok()> chooses a default test name C<Compile test for | ||||||||||||
| 192 | $filename>. | ||||||||||||
| 193 | |||||||||||||
| 194 | =cut | ||||||||||||
| 195 | 2 | ▶ | sub pm_file_ok { | ||||||||||
|
Subroutine
pm_file_ok: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 196 | 2 | my ($file, $name) = @_; | |||||||||||
| 197 | |||||||||||||
| 198 | 2 | ▶ | $name ||= "Compile test for $file"; | ||||||||||
|
Condition100%2/2
$name ||= "Compile test for $file"
MC/DC100%1/1
$name ||= "Compile test for $file"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||
| 199 | |||||||||||||
| 200 | 2 | my $ok = $Test->pm_file_compiles($file); | |||||||||||
| 201 | |||||||||||||
| 202 | 2 | $Test->ok($ok, $name); | |||||||||||
| 203 | 2 | ▶ | $Test->diag("$file does not compile") unless $ok; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 204 | 2 | return $ok; | |||||||||||
| 205 | } | ||||||||||||
| 206 | |||||||||||||
| 207 | =item C<pl_file_ok($filename, $testname)> | ||||||||||||
| 208 | |||||||||||||
| 209 | B<This function is deprecated>. Please use | ||||||||||||
| 210 | L<Test::Compile::Internal/all_pl_files_ok(@dirs)> instead. It's pretty much the | ||||||||||||
| 211 | same, except you can't specify a test name, and it can handle more than one file at a | ||||||||||||
| 212 | time. | ||||||||||||
| 213 | |||||||||||||
| 214 | C<pl_file_ok()> will okay the test if $filename compiles as a perl script. You | ||||||||||||
| 215 | need to give the path to the script relative to this distribution's base | ||||||||||||
| 216 | directory. So if you put your scripts in a 'top-level' directory called script | ||||||||||||
| 217 | the argument would be C<script/filename>. | ||||||||||||
| 218 | |||||||||||||
| 219 | The optional second argument C<$testname> is the name of the test. If it is | ||||||||||||
| 220 | omitted, C<pl_file_ok()> chooses a default test name C<Compile test for | ||||||||||||
| 221 | $filename>. | ||||||||||||
| 222 | =cut | ||||||||||||
| 223 | |||||||||||||
| 224 | 4 | ▶ | sub pl_file_ok { | ||||||||||
|
Subroutine
pl_file_ok: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 225 | 4 | my ($file, $name) = @_; | |||||||||||
| 226 | |||||||||||||
| 227 | 4 | ▶ | $name ||= "Compile test for $file"; | ||||||||||
|
Condition100%2/2
$name ||= "Compile test for $file"
MC/DC100%1/1
$name ||= "Compile test for $file"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||
| 228 | |||||||||||||
| 229 | 4 | my $ok = $Test->pl_file_compiles($file); | |||||||||||
| 230 | |||||||||||||
| 231 | 4 | $Test->ok($ok, $name); | |||||||||||
| 232 | 4 | ▶ | $Test->diag("$file does not compile") unless $ok; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 233 | 4 | return $ok; | |||||||||||
| 234 | } | ||||||||||||
| 235 | |||||||||||||
| 236 | =item C<all_pm_files(@dirs)> | ||||||||||||
| 237 | |||||||||||||
| 238 | B<This function is deprecated>. Please use | ||||||||||||
| 239 | L<Test::Compile::Internal/all_pm_files(@dirs)> instead. | ||||||||||||
| 240 | |||||||||||||
| 241 | Returns a list of all the perl module files - that is, files ending in F<.pm> | ||||||||||||
| 242 | - in I<@dirs> and in directories below. If no directories are passed, it | ||||||||||||
| 243 | defaults to F<blib> if F<blib> exists, or else F<lib> if not. Skips any files | ||||||||||||
| 244 | in F<CVS>, F<.svn>, or F<.git> directories. | ||||||||||||
| 245 | |||||||||||||
| 246 | =cut | ||||||||||||
| 247 | |||||||||||||
| 248 | 1 | ▶ | sub all_pm_files { | ||||||||||
|
Subroutine
all_pm_files: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 249 | 1 | return $Test->all_pm_files(@_); | |||||||||||
| 250 | } | ||||||||||||
| 251 | |||||||||||||
| 252 | =item C<all_pl_files(@dirs)> | ||||||||||||
| 253 | |||||||||||||
| 254 | B<This function is deprecated>. Please use | ||||||||||||
| 255 | L<Test::Compile::Internal/all_pl_files(@dirs)> instead. | ||||||||||||
| 256 | |||||||||||||
| 257 | Returns a list of all the perl script files - that is, any files in C<@dirs> that | ||||||||||||
| 258 | either have a F<.pl> extension, or have no extension and have a perl shebang line. | ||||||||||||
| 259 | |||||||||||||
| 260 | If C<@dirs> is undefined, it searches F<script> if F<script> exists, or else | ||||||||||||
| 261 | F<bin> if F<bin> exists. | ||||||||||||
| 262 | |||||||||||||
| 263 | Skips any files in F<CVS>, F<.svn>, or F<.git> directories. | ||||||||||||
| 264 | |||||||||||||
| 265 | =cut | ||||||||||||
| 266 | |||||||||||||
| 267 | 1 | ▶ | sub all_pl_files { | ||||||||||
|
Subroutine
all_pl_files: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 268 | 1 | return $Test->all_pl_files(@_); | |||||||||||
| 269 | } | ||||||||||||
| 270 | |||||||||||||
| 271 | =item C<all_files_ok(@dirs)> | ||||||||||||
| 272 | |||||||||||||
| 273 | B<This function is deprecated>. Please use | ||||||||||||
| 274 | L<Test::Compile::Internal/all_files_ok(@dirs)> instead. | ||||||||||||
| 275 | |||||||||||||
| 276 | Checks all the perl files it can find for compilation errors. | ||||||||||||
| 277 | |||||||||||||
| 278 | If C<@dirs> is defined then it is taken as an array of directories to | ||||||||||||
| 279 | be searched for perl files, otherwise it searches some default locations | ||||||||||||
| 280 | - see L</all_pm_files(@dirs)> and L</all_pl_files(@dirs)>. | ||||||||||||
| 281 | |||||||||||||
| 282 | =back | ||||||||||||
| 283 | =cut | ||||||||||||
| 284 | 1 | ▶ | sub all_files_ok { | ||||||||||
|
Subroutine
all_files_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 285 | 1 | return $Test->all_files_ok(@_); | |||||||||||
| 286 | } | ||||||||||||
| 287 | |||||||||||||
| 288 | 8 | 1; | |||||||||||
| 289 | |||||||||||||
| 290 | =head1 AUTHORS | ||||||||||||
| 291 | |||||||||||||
| 292 | Sagar R. Shah C<< <srshah@cpan.org> >>, | ||||||||||||
| 293 | Marcel GrE<uuml>nauer, C<< <marcel@cpan.org> >>, | ||||||||||||
| 294 | Evan Giles, C<< <egiles@cpan.org> >> | ||||||||||||
| 295 | |||||||||||||
| 296 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 297 | |||||||||||||
| 298 | Copyright 2007-2023 by the authors. | ||||||||||||
| 299 | |||||||||||||
| 300 | This library is free software; you can redistribute it and/or modify | ||||||||||||
| 301 | it under the same terms as Perl itself. | ||||||||||||
| 302 | |||||||||||||
| 303 | =head1 SEE ALSO | ||||||||||||
| 304 | |||||||||||||
| 305 | L<Test::Compile::Internal> provides the object oriented interface to (and the | ||||||||||||
| 306 | inner workings for) the Test::Compile functionality. | ||||||||||||
| 307 | |||||||||||||
| 308 | L<Test::Strict> provides functions to ensure your perl files compile, with | ||||||||||||
| 309 | the added bonus that it will check you have used strict in all your files. | ||||||||||||
| 310 | |||||||||||||
| 311 | L<Test::LoadAllModules> just handles modules, not script files, but has more | ||||||||||||
| 312 | fine-grained control. | ||||||||||||
| 313 | |||||||||||||
| 314 | =cut | ||||||||||||