Test2::...arnings(3)

πŸ“¦ version 1.302214, in opensuse-leap 16.0

πŸ’… 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 return 0, or a positive integer. that's it. no weird negative nonsense, no undef, 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 the undef check 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 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 with perl v5.42.0, dated 2025-07-28, and yeah β€” the manual page is literally titled Test2::...arnings(3) because even manpage headers get abbreviated sometimes lmaooo πŸ˜­πŸ’€ slay πŸ’…
πŸ“¦ where this page comes from