1Test2::Tools::Warnings(U3s)er Contributed Perl DocumentatTieosnt2::Tools::Warnings(3)
2
3
4

NAME

6       Test2::Tools::Warnings - Tools to verify warnings.
7

DESCRIPTION

9       This is a collection of tools that can be used to test code that issues
10       warnings.
11

SYNOPSIS

13           use Test2::Tools::Warnings qw/warns warning warnings no_warnings/;
14
15           ok(warns { warn 'a' }, "the code warns");
16           ok(!warns { 1 }, "The code does not warn");
17           is(warns { warn 'a'; warn 'b' }, 2, "got 2 warnings");
18
19           ok(no_warnings { ... }, "code did not warn");
20
21           like(
22               warning { warn 'xxx' },
23               qr/xxx/,
24               "Got expected warning"
25           );
26
27           is(
28               warnings { warn "a\n"; warn "b\n" },
29               [
30                   "a\n",
31                   "b\n",
32               ],
33               "Got 2 specific warnings"
34           );
35

EXPORTS

37       All subs are exported by default.
38
39       $count = warns { ... }
40           Returns the count of warnings produced by the block. This will
41           always return 0, or a positive integer.
42
43       $warning = warning { ... }
44           Returns the first warning generated by the block. If the block
45           produces more than one warning, they will all be shown as notes,
46           and an actual warning will tell you about it.
47
48       $warnings_ref = warnings { ... }
49           Returns an arrayref with all the warnings produced by the block.
50           This will always return an array reference. If there are no
51           warnings, this will return an empty array reference.
52
53       $bool = no_warnings { ... }
54           Return true if the block has no warnings. Returns false if there
55           are warnings.
56

SOURCE

58       The source code repository for Test2-Suite can be found at
59       https://github.com/Test-More/Test2-Suite/.
60

MAINTAINERS

62       Chad Granum <exodist@cpan.org>
63

AUTHORS

65       Chad Granum <exodist@cpan.org>
66
68       Copyright 2018 Chad Granum <exodist@cpan.org>.
69
70       This program is free software; you can redistribute it and/or modify it
71       under the same terms as Perl itself.
72
73       See http://dev.perl.org/licenses/
74
75
76
77perl v5.36.0                      2022-07-22         Test2::Tools::Warnings(3)
Impressum