1Test::Stream::Plugin::WUasrenrinCgosn(t3r)ibuted Perl DoTceusmte:n:tSattrieoanm::Plugin::Warnings(3)
2
3
4

NAME

6       Test::Stream::Plugin::Warnings - Simple tools for testing code that may
7       generate warnings.
8

DEPRECATED

10       This distribution is deprecated in favor of Test2, Test2::Suite, and
11       Test2::Workflow.
12
13       See Test::Stream::Manual::ToTest2 for a conversion guide.
14

SYNOPSIS

16           # Load the Warnings plugin, and Core cause we need that as well.
17           use Test::Stream qw/Core Warnings/;
18
19           # Returns undef if there are no warnings.
20           ok(!warns { ... }, "Codeblock did not warn");
21
22           is_deeply(
23               warns { warn "foo\n"; warn "bar\n" },
24               [
25                   "foo\n",
26                   "bar\n",
27               ],
28               "Got expected warnings"
29           );
30
31           # Dies if there are 0 warnings, or 2+ warnings, otherwise returns the 1 warning.
32           like( warning { warn 'xxx' }, qr/xxx/, "Got expected warning");
33

EXPORTS

35       $warnings = warns { ... }
36           If the codeblock issues any warnings they will be captured and
37           returned in an arrayref. If there were no warnings this will return
38           undef. You can be sure this will always be undef, or an arrayref
39           with 1 or more warnings.
40
41               # Returns undef if there are no warnings.
42               ok(!warns { ... }, "Codeblock did not warn");
43
44               is_deeply(
45                   warns { warn "foo\n"; warn "bar\n" },
46                   [
47                       "foo\n",
48                       "bar\n",
49                   ],
50                   "Got expected warnings"
51               );
52
53       $warning = warning { ... }
54           Only use this for code that should issue exactly 1 warning. This
55           will throw an exception if there are no warnings, or if there are
56           multiple warnings.
57
58               like( warning { warn 'xxx' }, qr/xxx/, "Got expected warning");
59
60           These both die:
61
62               warning { warn 'xxx'; warn 'yyy' };
63               warning { return };
64
65       $bool = no_warnings { ... }
66           This will return true if there are no warnings in the codeblock.
67           This will return false, and print the warnings if any are
68           encountered.
69
70               ok(no_warnings { ... }, "Did not warn.");
71
72           This is sometimes more useful that checking "!warns { ... }" since
73           it lets you see the warnings when it fails.
74

SOURCE

76       The source code repository for Test::Stream can be found at
77       http://github.com/Test-More/Test-Stream/.
78

MAINTAINERS

80       Chad Granum <exodist@cpan.org>
81

AUTHORS

83       Chad Granum <exodist@cpan.org>
84
86       Copyright 2015 Chad Granum <exodist7@gmail.com>.
87
88       This program is free software; you can redistribute it and/or modify it
89       under the same terms as Perl itself.
90
91       See http://dev.perl.org/licenses/
92
93
94
95perl v5.32.0                      2020-07-28 Test::Stream::Plugin::Warnings(3)
Impressum