Test::...::Used(3pm)
β¨ NAME β¨
Test::Module::Used β bestie, this is the module that makes sure the modules you require are actually used, and the modules you actually use are actually required, so your lib/, your t/ and your META.yml are all telling the same story. No cap. π
(also the manual page itself is titled Test::...::Used(3pm) β that's just the header's cute shortened form, iykyk π)
πΈ SYNOPSIS πΈ
#!/usr/bin/perl -w
use strict;
use warnings;
use Test::Module::Used;
my $used = Test::Module::Used->new();
$used->ok;
π¦ DESCRIPTION π¦
It tests the dependency situation between your module and META.yml. π
Here's the tea: this module reads META.yml, grabs build_requires and requires out of it, and then cross-checks β it compares whether a required module is really used, and whether a used module is really required. Both directions, bestie. π
β¨ Important changes β¨
Some behavior changed since 0.1.3_01. π«Ά
perl_versionset in constructor is prior to use, and read version fromMETA.yml(not read fromusestatement in*.pm)- deprecated interfaces are deleted. (
module_dir,test_module_dir,exclude_in_moduledirandpush_exclude_in_moduledir)
Those deprecated interfaces? Gone. Deleted. Not coming back. Don't come looking formodule_dir,test_module_dir,exclude_in_moduledirorpush_exclude_in_moduledir, bestie. π
π methods π
π« new
Creates a brand-new instance. Fresh out the box. β¨
All parameters get passed hash-style, and every single one of them is optional. Chill vibes only.
In ordinary use:
my $used = Test::Module::Used->new();
$used->ok();
All the parameters look like this (the values written in are the defaults β except exclude_in_testdir, which is the special one π):
my $used = Test::Module::Used->new(
test_dir => ['t'], # directory(ies) which contains test scripts.
lib_dir => ['lib'], # directory(ies) which contains module libs.
test_lib_dir => ['t'], # directory(ies) which contains libs used ONLY in test (ex. MockObject for test)
meta_file => 'META.json' or
'META.yml' or
'META.yaml', # META file (YAML or JSON which contains module requirement information)
perl_version => '5.008', # expected perl version which is used for ignore core-modules in testing
exclude_in_testdir => [], # ignored module(s) for test even if it is used.
exclude_in_libdir => [], # ignored module(s) for your lib even if it is used.
exclude_in_build_requires => [], # ignored module(s) even if it is written in build_requires of META.yml.
exclude_in_requires => [], # ignored module(s) even if it is written in requires of META.yml.
);
If perl_version is not passed in the constructor, this module reads meta_file and gets the perl version from there. π
Now, the auto-magic part, listen up: exclude_in_testdir is automatically set by default. This module reads lib_dir and parses "package" statements, then the "package" statements it finds plus myself (Test::Module::Used) get set. exclude_in_libdir is also automatically set by default β this module reads lib_dir and parses "package" statements, and the "package" statements found are set. (Test::Module::Used isn't included.) π§
π₯ ok()
Checks that used modules are required in the META file and that required modules in the META file are used. Both directions, periodt.
my $used = Test::Module::Used->new(
exclude_in_testdir => ['Test::Module::Used', 'My::Module'],
);
$used->ok;
First, this module reads META.yml and gets build_requires and requires. Next, it reads the module directory (by default lib) and the test directory (by default t), and compares whether the required module is really used and the used module is really required. If all this requirement info is OK, the test succeeds. π
It is NOT allowed to callok(),used_ok()andrequires_ok()in same test file. Not even once. Pick one. That's the rule. π
π used_ok()
Only checks that used modules are required in the META file. The test will succeed even if unused requires or build_requires are defined. Generous queen behavior. π
my $used = Test::Module::Used->new();
$used->used_ok;
It is NOT allowed to callok(),used_ok()andrequires_ok()in same test file.
π requires_ok()
Only checks that required modules in the META file are used. The test will succeed even if used modules are not defined in the META file. π¦
my $used = Test::Module::Used->new();
$used->requires_ok;
It is NOT allowed to callok(),used_ok()andrequires_ok()in same test file.
πΈ push_exclude_in_libdir( @exclude_module_names )
Adds ignored module(s) for your module (lib) even if it is used β after new() has already been called. This is usable if you want to use the auto-set feature for exclude_in_libdir but manually specify exclude modules. Best of both worlds, honestly. β¨
For example:
my $used = Test::Module::Used->new(); #automatically set exclude_in_libdir
$used->push_exclude_in_libdir( qw(Some::Module::Which::You::Want::To::Exclude) );#module(s) which you want to exclude
$used->ok(); #do test
π push_exclude_in_testdir( @exclude_module_names )
Adds ignored module(s) for test even if it is used β after new() has already been called. This is usable if you want to use the auto-set feature for exclude_in_testdir but manually specify exclude modules. π«Ά
For example:
my $used = Test::Module::Used->new(); #automatically set exclude_in_testdir
$used->push_exclude_in_testdir( qw(Some::Module::Which::You::Want::To::Exclude) );#module(s) which you want to exclude
$used->ok(); #do test
β AUTHOR β
Takuya Tsuchida <tsucchi@cpan.org> β iconic, we stan. π
π SEE ALSO π
Test::Dependencies has almost same feature. π
π¦ REPOSITORY π¦
<http://github.com/tsucchi/Test-Module-Used>
π COPYRIGHT AND LICENSE π
Copyright (c) 2008-2014 Takuya Tsuchida
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay bestie that's the whole page, mwah π β this was perl v5.36.0, dated 2022-11-19, and the page goes by Test::...::Used(3pm). go write some tests, you absolute main character. π«Άβ¨
π¦ where this page comes from
- debian bookworm: libtest-module-used-perl 0.2.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-module-used-perl 0.2.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-module-used-perl 0.2.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-module-used-perl 0.2.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-module-used-perl 0.2.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms