Test::Compiles - tests if perl can compile a string of code
use Test::More; use Test::Compiles; compiles_ok q{ print "hello world" }; doesnt_compile q{ print "hello world }; # missing end of quote done_testing;
Test::Compiles exports two functions to allow you to check whether a string of code can be compiled by perl without errors. It doesn't check whether it can be executed.
Note that Perl code can execute arbitrary instructions as part of its compilation (e.g. in a BEGIN { ... } block), so don't pass untrusted strings to these test functions.
BEGIN { ... }
compiles $code, $message, %options
compiles $code, %options
compiles $code, $message
compiles $code
This test passes if $code can be compiled.
$code
Valid options are:
strict: boolean to indicate whether code should be compiled with use strict. Enabled by default.
strict
use strict
warnings: boolean to indicate whether code should be compiled with use warnings FATAL => 'all'. Disabled by default.
warnings
use warnings FATAL => 'all'
package: package that the code should be compiled in. Defaults to the caller.
package
prelude: a string of Perl code to prepend to $code. Defaults to $Test::Compiles::PRELUDE, which is (by default) an empty string.
prelude
$Test::Compiles::PRELUDE
message: an alternative to specifying $message.
message
$message
doesnt_compile $code, $message, %options
doesnt_compile $code, %options
doesnt_compile $code, $message
doesnt_compile $code
This test passes if $code cannot be compiled. It accepts the same options.
This module defines a package variable $Test::Compiles::PRELUDE which can be used to, for example, load pragmata like indirect or bareword::filehandles.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Test-Compiles.
Test::Fatal — checks for runtime errors.
Test::More — the test framework.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2017 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install Test::Compiles, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Compiles
CPAN shell
perl -MCPAN -e shell install Test::Compiles
For more information on module installation, please visit the detailed CPAN module installation guide.