Test2:...rnings(3perl)
β¨ NAME β¨
Test2::Tools::Warnings β the lil toolkit for verifying warnings, bestie π
(yeah the page title is Test2:...rnings(3perl) bestie, they truncate it, it's giving dramatic ellipsis β¨, and it lives in the Perl Programmers Reference Guide π
)
π¦ DESCRIPTION π¦
Okay so this is a whole collection of tools π§° that you use to test code that issues warnings. That's it, that's the vibe. Code warns β you check that it warned β you slay π β¨
πΈ 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"
);
no cap, that's the whole flow π«Ά
π EXPORTS π
All subs are exported by default. Every single one. You don't gotta ask, you don't gotta beg, they just show up πβ¨
π $count = warns { ... }
Returns the count of warnings produced by the block. This will always return 0, or a positive integer. Never negative, never weird, never a lie fr fr π’
π $warning = warning { ... }
Returns the first warning generated by the block. And listen β 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, you'll know. The tool snitches on your code, affectionately π
π $warnings_ref = warnings { ... }
Returns an arrayref with all the warnings produced by the block. This will always return an array reference. If there are no warnings, this will return an empty array reference. Empty arrayref, not undef, not sadness, just [] π«Ά
π $bool = no_warnings { ... }
Return true if the block has no warnings. Returns false if there are warnings. Clean code = true, noisy code = false, simple as π¦βοΈ
π₯ SOURCE π₯
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go lurk, go star it, go read the code, it's lowkey iconic π
π 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 bestie real talk: this whole page came fromperl v5.44.0, dated2026-10-17β that's theTest2:...rnings(3perl)energy, and it ate β¨ mwah π
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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