1Test::NoWarnings(3) User Contributed Perl Documentation Test::NoWarnings(3)
2
3
4
6 Test::NoWarnings - Make sure you didn't emit any warnings while testing
7
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
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
34 Test::NoWarnings 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
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
55 Test::NoWarnings.
56
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
63 automatic test at the end of your script.
64
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
78 had_no_warnings()
79 This checks that there have been warnings emitted by your test scripts.
80 Usually you will not call this explicitly as it is called automatically
81 when your script finishes.
82
83 clear_warnings()
84 This will clear the array of warnings that have been captured. If the
85 array is empty then a call to "had_no_warnings()" will produce a pass
86 result.
87
88 warnings()
89 This will return the array of warnings captured so far. Each element of
90 this array is an object containing information about the warning. The
91 following methods are available on these object.
92
93 · $warn->getMessage
94
95 Get the message that would been printed by the warning.
96
97 · $warn->getCarp
98
99 Get a stack trace of what was going on when the warning happened,
100 this stack trace is just a string generated by the Carp module.
101
102 · $warn->getTrace
103
104 Get a stack trace object generated by the Devel::StackTrace module.
105 This will return undef if Devel::StackTrace is not installed.
106
107 · $warn->getTest
108
109 Get the number of the test that executed before the warning was
110 emitted.
111
112 · $warn->getTestName
113
114 Get the name of the test that executed before the warning was
115 emitted.
116
118 When counting your tests for the plan, don't forget to include the test
119 that runs automatically when your script ends.
120
122 None that I know of.
123
125 This was previously known as Test::Warn::None
126
128 Test::Builder, Test::Warn
129
131 Written by Fergal Daly <fergal@esatclear.ie>.
132
134 Copyright 2003 by Fergal Daly <fergal@esatclear.ie>.
135
136 This program is free software and comes with no warranty. It is
137 distributed under the LGPL license
138
139 See the file LGPL included in this distribution or
140 http://www.fsf.org/licenses/licenses.html.
141
142
143
144perl v5.12.0 2007-10-20 Test::NoWarnings(3)