Test::...Modules(3pm)

πŸ’– Test::UseAllModules β€” like, the manual page but make it slay πŸ’–

okay bestie, this is the page for Test::UseAllModules, sitting pretty in the Test::...Modules(3pm) slot of your local perl docs. she's a tiny little testing gem and honestly? she ate. let's get into it 🫢


✨ NAME ✨

Test::UseAllModules β€” she does use_ok() for all the MANIFESTed modules. every single one. no cap. πŸ’…


🌸 SYNOPSIS 🌸

basic usage, the moment, the vibe:

# basic usage
use strict;
use Test::UseAllModules;

BEGIN { all_uses_ok(); }

and if you also wanna test the modules chillin' under t/lib:

# if you also want to test modules under t/lib
use strict;
use Test::UseAllModules under => qw(lib t/lib);

BEGIN { all_uses_ok(); }

and for when some modules are just gonna fail use_ok() on themselves (we all have that one friend 😭):

# if you have modules that'll fail use_ok() for themselves
use strict;
use Test::UseAllModules;

BEGIN {
  all_uses_ok except => qw(
    Some::Dependent::Module
    Another::Dependent::Module
    ^Yet::Another::Dependent::.*   # you can use regex
  )
}

like, yes, you can throw a regex in there. iconic. ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so real talk. the author is sick of writing 00_load.t (or whatever you wanna call it) that does use_ok() for every module they write. and they're even sicker β€” like, sicker sicker β€” of updating that 00_load.t every single time a new file gets added to the distro. exhausting. the audacity of it. πŸ’€

so this module does the thing for you: it reads MANIFEST to find the modules that need testing, and then it does use_ok() for each of them. that's it. that's the whole job. now all you have to do is update MANIFEST and you literally never have to touch the test again. (hopefully. crossing our fingers, bestie πŸ™ˆ)


πŸŽ€ EXPORTED FUNCTION πŸŽ€

all_uses_ok

she performs Test::More's use_ok() for every module found in MANIFEST. that's the main character energy right there. πŸ‘‘

if there are modules you don't wanna test, you just hand her those module names, or some regex rules, as the argument. the word except gets completely ignored β€” it's just there for you, so the code reads like a human wrote it. (shown in the synopsis above, iykyk πŸ’…)

as of 0.11, you can also test modules sitting under arbitrary directories by passing a directory list at loading time β€” and yeah, the word under gets ignored too, same deal as except. modules under the lib directory are always tested, no matter what. periodt. ✨


🧚 PROTECTED FUNCTION 🧚

_get_module_list

returns the module paths to test. she does not get exported, bestie β€” so if you wanna use her (there's an example below πŸ‘€), you always gotta call her by her full qualified name:

Test::UseAllModules::_get_module_list()

no shortcuts. she's exclusive. πŸ’…


πŸ”₯ NOTES πŸ”₯

  • as of 0.03, this module calls BAIL_OUT from Test::More if any of the use_ok tests should fail. and yeah β€” that means the tests after it get ignored. it's for a good reason though: missing or unloadable modules cause a whole lotta errors of the exact same kind, and nobody needs that spam. 😭
  • as of 0.12, you can add extra tests before and/or after all_uses_ok() β€” but only if you explicitly declare your test plan, like this:
use strict;
use warnings;
use Test::More;
use Test::UseAllModules;
use Test::NoWarnings;

plan tests => Test::UseAllModules::_get_module_list() + 1;

all_uses_ok();

# and extra nowarnings test

look at that + 1 doing the heavy lifting for the extra nowarnings test. she's organized. she has a plan. literally. 🌈


🌟 SEE ALSO 🌟

there are a few modules like this on the CPAN these days. <yellow>Test::Compile, and <yellow>Test::LoadAllModules β€” which is, ngl, a little bit confusing β€” both try to find modules to test by traversing directories. and honestly? the author is not a big fan. those ones tend to find temporary or unrelated modules too, which is giving chaos. πŸ™ˆ

but like, fair warning: they might be handier for you, especially if you're too lazy to update MANIFEST every time. no judgement, we've all been there. 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Kenichi Ishigaki, <ishigaki@cpan.org>


Copyright (C) 2006 by Kenichi Ishigaki

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie!! πŸŽ€ this little beauty is living in perl v5.36.0 and got her date stamp on 2022-10-13, filed under Test::...Modules(3pm) β€” go update your MANIFEST and never write a load test again. mwah πŸ’–βœ¨

πŸ“¦ where this page comes from