Test2::...arnings(3)
π NAME π
Test2::Tools::Warnings β bestie, it's a whole toolkit for checking that your code warns the way it's supposed to πβ¨ (this one lives in the User Contributed Perl Documentation section, fyi π)
πΈ DESCRIPTION πΈ
okay so this is a little collection of tools β literally a friend group of subs β that you use to test code that issues warnings π¦. That's it, that's the vibe check. Your code warns, you wanna know about it, these help you prove it. periodt π
β¨ SYNOPSIS β¨
use Test2::Tools::Warnings qw/warns warning warnings no_warnings/;
ok(warns { warn 'a' }, "the code warns");
ok(!warns { 1 }, "The code does not warn");
is(warns { warn 'a'; warn 'b' }, 2, "got 2 warnings");
ok(no_warnings { ... }, "code did not warn");
like(
warning { warn 'xxx' },
qr/xxx/,
"Got expected warning"
);
is(
warnings { warn "a\n"; warn "b\n" },
[
"a\n",
"b\n",
],
"Got 2 specific warnings"
);
like look at that. iconic behaviour honestly π
π EXPORTS π
All subs are exported by default β no cap, you get the whole squad automatically π«Ά
$count = warns { ... }β returns the count of warnings produced by the block. This will always return0, or a positive integer. that's it. no weird negative nonsense, noundef, just a nice clean number, we love a consistent icon β$warning = warning { ... }β returns the first warning generated by the block. kinda the main character of the warnings if you will π . But heads up bestie: if the block produces more than one warning, they will all be shown as notes, and an actual warning will tell you about it π so like, the extras don't get silently yeeted, they get called out.$warnings_ref = warnings { ... }β returns an arrayref with all the warnings produced by the block. This will always return an array reference β always always, fr fr. If there are no warnings, this will return an empty array reference. so you never have to do theundefcheck dance, she's reliable π$bool = no_warnings { ... }β return true if the block has no warnings. Returns false if there are warnings. simple as that, the vibes are either clean π§ or they're not π
π₯ SOURCE π₯
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. go star it, the maintainers deserve it π
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
okay that's the whole page bestie, you're officially warned-certified πβ¨
this gem shipped withperl v5.42.0, dated2025-07-28, and yeah β the manual page is literally titledTest2::...arnings(3)because even manpage headers get abbreviated sometimes lmaooo ππ slay π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.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