1Test::FailWarnings(3) User Contributed Perl DocumentationTest::FailWarnings(3)
2
3
4

NAME

6       Test::FailWarnings - Add test failures if warnings are caught
7

VERSION

9       version 0.008
10

SYNOPSIS

12       Test file:
13
14           use strict;
15           use warnings;
16           use Test::More;
17           use Test::FailWarnings;
18
19           ok( 1, "first test" );
20           ok( 1 + "lkadjaks", "add non-numeric" );
21
22           done_testing;
23
24       Output:
25
26           ok 1 - first test
27           not ok 2 - Test::FailWarnings should catch no warnings
28           #   Failed test 'Test::FailWarnings should catch no warnings'
29           #   at t/bin/main-warn.pl line 7.
30           # Warning was 'Argument "lkadjaks" isn't numeric in addition (+) at t/bin/main-warn.pl line 7.'
31           ok 3 - add non-numeric
32           1..3
33           # Looks like you failed 1 test of 3.
34

DESCRIPTION

36       This module hooks $SIG{__WARN__} and converts warnings to Test::More
37       "fail()" calls.  It is designed to be used with "done_testing", when
38       you don't need to know the test count in advance.
39
40       Just as with Test::NoWarnings, this does not catch warnings if other
41       things localize $SIG{__WARN__}, as this is designed to catch unhandled
42       warnings.
43

USAGE

45   Overriding $SIG{__WARN__}
46       On "import", $SIG{__WARN__} is replaced with
47       "Test::FailWarnings::handler".
48
49           use Test::FailWarnings;  # global
50
51       If you don't want global replacement, require the module instead and
52       localize in whatever scope you want.
53
54           require Test::FailWarnings;
55
56           {
57               local $SIG{__WARN__} = \&Test::FailWarnings::handler;
58               # ... warnings will issue fail() here
59           }
60
61       When the handler reports on the source of the warning, it will look
62       past any calling packages starting with "Carp" or "warnings" to try to
63       detect the real origin of the warning.
64
65   Allowing warnings from dependencies
66       If you want to ignore failures from outside your own code, you can set
67       $Test::FailWarnings::ALLOW_DEPS to a true value.  You can do that on
68       the "use" line with "-allow_deps".
69
70           use Test::FailWarnings -allow_deps => 1;
71
72       When true, warnings will only be thrown if they appear to originate
73       from a filename matching "qr/^(?:t|xt|lib|blib)/"
74
75   Allowing warnings from specific modules
76       If you want to white-list specific modules only, you can add their
77       package names to @Test::NoWarnings::ALLOW_FROM.  You can do that on the
78       "use" line with "-allow_from".
79
80           use Test::FailWarnings -allow_from => [ qw/Annoying::Module/ ];
81

SEE ALSO

83       •   Test::NoWarnings -- catches warnings and reports in an "END" block.
84           Not (yet) friendly with "done_testing".
85
86       •   Test::Warnings -- a replacement for Test::NoWarnings that works
87           with done_testing
88
89       •   Test::Warn -- test for warnings without triggering failures from
90           this modules
91

SUPPORT

93   Bugs / Feature Requests
94       Please report any bugs or feature requests through the issue tracker at
95       <https://github.com/dagolden/Test-FailWarnings/issues>.  You will be
96       notified automatically of any progress on your issue.
97
98   Source Code
99       This is open source software.  The code repository is available for
100       public review and contribution under the terms of the license.
101
102       <https://github.com/dagolden/Test-FailWarnings>
103
104         git clone https://github.com/dagolden/Test-FailWarnings.git
105

AUTHOR

107       David Golden <dagolden@cpan.org>
108
110       This software is Copyright (c) 2013 by David Golden.
111
112       This is free software, licensed under:
113
114         The Apache License, Version 2.0, January 2004
115
116
117
118perl v5.34.0                      2022-01-21             Test::FailWarnings(3)
Impressum