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 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 from perl v5.44.0, dated 2026-10-17 β€” that's the Test2:...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