1Test::NoWarnings(3)   User Contributed Perl Documentation  Test::NoWarnings(3)
2
3
4

NAME

6       Test::NoWarnings - Make sure you didn't emit any warnings while testing
7

SYNOPSIS

9       For scripts that have no plan
10
11         use Test::NoWarnings;
12
13       that's it, you don't need to do anything else
14
15       For scripts that look like
16
17         use Test::More tests => x;
18
19       change to
20
21         use Test::More tests => x + 1;
22         use Test::NoWarnings;
23

DESCRIPTION

25       In general, your tests shouldn't produce warnings. This modules causes
26       any warnings to be captured and stored. It automatically adds an extra
27       test that will run when your script ends to check that there were no
28       warnings. If there were any warings, the test will give a "not ok" and
29       diagnostics of where, when and what the warning was, including a stack
30       trace of what was going on when the it occurred.
31
32       If some of your tests are supposed to produce warnings then you should
33       be capturing and checking them with Test::Warn, that way Test::NoWarn‐
34       ings will not see them and so not complain.
35
36       The test is run by an END block in Test::NoWarnings. It will not be run
37       when any forked children exit.
38

USAGE

40       Simply by using the module, you automatically get an extra test at the
41       end of your script that checks that no warnings were emitted. So just
42       stick
43
44         use Test::NoWarnings
45
46       at the top of your script and continue as normal.
47
48       If you want more control you can invoke the test manually at any time
49       with "had_no_warnings()".
50
51       The warnings your test has generated so far are stored in an array. You
52       can look inside and clear this whenever you want with "warnings()" and
53       "clear_warnings()", however, if you are doing this sort of thing then
54       you probably want to use Test::Warn in combination with Test::NoWarn‐
55       ings.
56

USE vs REQUIRE

58       You will almost always want to do
59
60         use Test::NoWarnings
61
62       If you do a "require" rather than a "use", then there will be no auto‐
63       matic test at the end of your script.
64

OUTPUT

66       If warning is captured during your test then the details will output as
67       part of the diagnostics. You will get:
68
69       o the number and name of the test that was executed just before the
70         warning (if no test had been executed these will be 0 and '')
71
72       o the message passed to "warn",
73
74       o a full dump of the stack when warn was called, courtesy of the "Carp"
75         module
76

EXPORTABLE FUNCTIONS

78       had_no_warnings()
79
80       This checks that there have been warnings emitted by your test scripts.
81       Usually you will not call this explicitly as it is called automatically
82       when your script finishes.
83
84       clear_warnings()
85
86       This will clear the array of warnings that have been captured. If the
87       array is empty then a call to "had_no_warnings()" will produce a pass
88       result.
89
90       warnings()
91
92       This will return the array of warnings captured so far. Each element of
93       this array is an object containing information about the warning. The
94       following methods are available on these object.
95
96       · $warn->getMessage
97
98         Get the message that would been printed by the warning.
99
100       · $warn->getCarp
101
102         Get a stack trace of what was going on when the warning happened,
103         this stack trace is just a string generated by the Carp module.
104
105       · $warn->getTrace
106
107         Get a stack trace object generated by the Devel::StackTrace module.
108         This will return undef if Devel::StackTrace is not installed.
109
110       · $warn->getTest
111
112         Get the number of the test that executed before the warning was emit‐
113         ted.
114
115       · $warn->getTestName
116
117         Get the name of the test that executed before the warning was emit‐
118         ted.
119

PITFALLS

121       When counting your tests for the plan, don't forget to include the test
122       that runs automatically when your script ends.
123

BUGS

125       None that I know of.
126

HISTORY

128       This was previously known as Test::Warn::None
129

SEE ALSO

131       Test::Builder, Test::Warn
132

AUTHOR

134       Written by Fergal Daly <fergal@esatclear.ie>.
135
137       Copyright 2003 by Fergal Daly <fergal@esatclear.ie>.
138
139       This program is free software and comes with no warranty. It is dis‐
140       tributed under the LGPL license
141
142       See the file LGPL included in this distribution or
143       http://www.fsf.org/licenses/licenses.html.
144
145
146
147perl v5.8.8                       2006-12-15               Test::NoWarnings(3)
Impressum