Test::S...arnings(3)
β¨ Test::Stream::Plugin::Warnings β¨
okay bestie, so this is a page from the User Contributed Perl Documentation collection, and it's all about Test::Stream::Plugin::Warnings π β the lil plugin that gives you simple tools for testing code that may generate warnings. no cap, that's the whole NAME vibe.
π DEPRECATED π
ngl this one's giving "we need to talk." This distribution is deprecated in favor of Test2, Test2::Suite, and Test2::Workflow. π«Ά
There's a whole conversion guide waiting for you at Test::Stream::Manual::ToTest2 β go read it, it's the main character of your migration arc. π
πΈ SYNOPSIS πΈ
# Load the Warnings plugin, and Core cause we need that as well.
use Test::Stream qw/Core Warnings/;
# Returns undef if there are no warnings.
ok(!warns { ... }, "Codeblock did not warn");
is_deeply(
warns { warn "foo\n"; warn "bar\n" },
[
"foo\n",
"bar\n",
],
"Got expected warnings"
);
# Dies if there are 0 warnings, or 2+ warnings, otherwise returns the 1 warning.
like( warning { warn 'xxx' }, qr/xxx/, "Got expected warning");
π EXPORTS π
$warnings = warns { ... }β bestie, if the codeblock issues any warnings, they get captured and handed back to you in an arrayref. π If there were no warnings this returnsundef. And here's the tea: you can be sure this will always beundef, or an arrayref with 1 or more warnings. no in-between, it's not messy like that.
# Returns undef if there are no warnings.
ok(!warns { ... }, "Codeblock did not warn");
is_deeply(
warns { warn "foo\n"; warn "bar\n" },
[
"foo\n",
"bar\n",
],
"Got expected warnings"
);
$warning = warning { ... }β only use this one for code that should issue exactly 1 warning. periodt. It will throw an exception if there are no warnings, or if there are multiple warnings. it does not do gray areas, it does not do "eh close enough." π¨
like( warning { warn 'xxx' }, qr/xxx/, "Got expected warning");
These both die, fr fr:
warning { warn 'xxx'; warn 'yyy' };
warning { return };
$bool = no_warnings { ... }β this returns true if there are no warnings in the codeblock. π It returns false, and prints the warnings, if any are encountered. so you get the receipts.
ok(no_warnings { ... }, "Did not warn.");
Honestly this is sometimes more useful than checking !warns { ... } since it lets you see the warnings when it fails. it's giving "show your work." π
π₯ SOURCE π₯
The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/. go lurk, it's iconic. π
π MAINTAINERS π
- Chad Granum
<exodist@cpan.org>
π AUTHORS π
- Chad Granum
<exodist@cpan.org>
π COPYRIGHT π
Copyright 2015 Chad Granum <exodist7@gmail.com>.
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/
and that's a wrap, bestie! π¦ this page shipped as perl v5.42.0, dated 2025-07-25 β slay, go write some tests that actually check for warnings πβ¨π§
π¦ where this page comes from
- fedora 43: perl-Test-Stream 1.302027-35.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms