Test::Needs(3)
π Test::Needs β a tiny manual, but make it iconic π
okay so bestie, this is the manual page for Test::Needs β part of the User Contributed Perl Documentation crew π«Ά β and it's basically the module that lets your tests say "nah, not today" when a dependency isn't installed. no drama, no explosions, just a polite skip. let's get into it β¨
πΈ NAME πΈ
Test::Needs β literally "Skip tests when modules not available". that's the whole vibe π
π¦ SYNOPSIS π¦
here's the group chat of usage patterns, copied exactly because details are sacred:
# need one module
use Test::Needs 'Some::Module';
# need multiple modules
use Test::Needs 'Some::Module', 'Some::Other::Module';
# need a given version of a module
use Test::Needs {
'Some::Module' => '1.005',
};
# check later
use Test::Needs;
test_needs 'Some::Module';
# skips remainder of subtest
use Test::More;
use Test::Needs;
subtest 'my subtest' => sub {
test_needs 'Some::Module';
...
};
# check perl version
use Test::Needs { perl => 5.020 };
like, pick your fighter π
β¨ DESCRIPTION β¨
So the whole point: skip test scripts if modules are not available. The requested modules get loaded, and optionally their versions get checked too. If a module is straight-up missing? the test script gets skipped, no hard feelings π
But β and this is important, bestie β modules that are found but fail to compile will exit with an error rather than skip. no quiet hiding of broken code here, periodt π
If you use this inside a subtest, the remainder of the subtest gets skipped. π
And skipping still works even if some tests have already been run, or if a plan has already been declared. it's giving "it's never too late" energy fr fr β¨
Versions are checked via a $module->VERSION($wanted_version) call. Versions must be provided in a format that will be accepted β and no extra processing is done on them. so like, format them right, iykyk π
If "perl" is used as a module, the version is checked against the running perl version ($]). cute, right? and the version can be specified as a number, dotted-decimal string, v-string, or version object β so many options, all valid π
β οΈ heads up: if the RELEASE_TESTING environment variable is set, the tests will fail rather than skip. Subtests will be aborted, but the test script will continue running after that point. so like, release mode does NOT play π
π§ EXPORTS π§
π test_needs
Has the same interface as when using Test::Needs in a use. that's it, that's the export π
π SEE ALSO π
the little family tree of similar modules, and why they're not this one:
- Test::Requires β A similar module, with some important differences. Test::Requires will act as a
"use"statement (despite its name), calling the import sub. Under"RELEASE_TESTING", it willBAIL_OUTif a module fails to load rather than using a normal test fail. It also doesn't distinguish between missing modules and broken modules. so like... it's giving "close but no" π - Test2::Require::Module β Part of the Test2 ecosystem. Only supports running as a
"use"command to skip an entire plan. - Test2::Require::Perl β Part of the Test2 ecosystem. Only supports running as a
"use"command to skip an entire plan. Checks perl versions. πͺ - Test::If β Acts as a
"use"statement. Only supports running as a"use"command to skip an entire plan. Can skip based on subref results.
β AUTHORS β
haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org> β the main character of this story π
π CONTRIBUTORS π
None so far. (bestie... that could be you πβ¨)
π COPYRIGHT AND LICENSE π
Copyright (c) 2016 the Test::Needs "AUTHORS" and "CONTRIBUTORS" as listed above.
This library is free software and may be distributed under the same terms as perl itself. See <http://dev.perl.org/licenses/>
and that's the whole page, bestie π«Ά this was documented in perl v5.42.0 and dated 2023-01-23 β go forth and skip responsibly π β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Needs 0.002010-160000.2.2 Β· 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