README
1NAME
2 Test::NoWarnings - Make sure you didn't emit any warnings while testing
3
4SYNOPSIS
5 For scripts that have no plan
6
7 use Test::NoWarnings;
8
9 that's it, you don't need to do anything else
10
11 For scripts that look like
12
13 use Test::More tests => x;
14
15 change to
16
17 use Test::More tests => x + 1;
18 use Test::NoWarnings;
19
20DESCRIPTION
21 In general, your tests shouldn't produce warnings. This modules causes
22 any warnings to be captured and stored. It automatically adds an extra
23 test that will run when your script ends to check that there were no
24 warnings. If there were any warings, the test will give a "not ok" and
25 diagnostics of where, when and what the warning was, including a stack
26 trace of what was going on when the it occurred.
27
28 If some of your tests are supposed to produce warnings then you should
29 be capturing and checking them with Test::Warn, that way
30 Test::NoWarnings will not see them and so not complain.
31
32 The test is run by an END block in Test::NoWarnings. It will not be run
33 when any forked children exit.
34
35USAGE
36 Simply by using the module, you automatically get an extra test at the
37 end of your script that checks that no warnings were emitted. So just
38 stick
39
40 use Test::NoWarnings
41
42 at the top of your script and continue as normal.
43
44 If you want more control you can invoke the test manually at any time
45 with "had_no_warnings()".
46
47 The warnings your test has generated so far are stored in an array. You
48 can look inside and clear this whenever you want with "warnings()" and
49 "clear_warnings()", however, if you are doing this sort of thing then
50 you probably want to use Test::Warn in combination with
51 Test::NoWarnings.
52
53USE vs REQUIRE
54 You will almost always want to do
55
56 use Test::NoWarnings
57
58 If you do a "require" rather than a "use", then there will be no
59 automatic test at the end of your script.
60
61OUTPUT
62 If warning is captured during your test then the details will output as
63 part of the diagnostics. You will get:
64
65 o the number and name of the test that was executed just before the
66 warning (if no test had been executed these will be 0 and '')
67
68 o the message passed to "warn",
69
70 o a full dump of the stack when warn was called, courtesy of the "Carp"
71 module
72
73EXPORTABLE FUNCTIONS
74 had_no_warnings()
75 This checks that there have been warnings emitted by your test scripts.
76 Usually you will not call this explicitly as it is called automatically
77 when your script finishes.
78
79 clear_warnings()
80 This will clear the array of warnings that have been captured. If the
81 array is empty then a call to "had_no_warnings()" will produce a pass
82 result.
83
84 warnings()
85 This will return the array of warnings captured so far. Each element of
86 this array is an object containing information about the warning. The
87 following methods are available on these object.
88
89 * $warn->getMessage
90
91 Get the message that would been printed by the warning.
92
93 * $warn->getCarp
94
95 Get a stack trace of what was going on when the warning happened, this
96 stack trace is just a string generated by the Carp module.
97
98 * $warn->getTrace
99
100 Get a stack trace object generated by the Devel::StackTrace module.
101 This will return undef if Devel::StackTrace is not installed.
102
103 * $warn->getTest
104
105 Get the number of the test that executed before the warning was
106 emitted.
107
108 * $warn->getTestName
109
110 Get the name of the test that executed before the warning was emitted.
111
112PITFALLS
113 When counting your tests for the plan, don't forget to include the test
114 that runs automatically when your script ends.
115
116BUGS
117 None that I know of.
118
119SUPPORT
120 Bugs should be reported via the CPAN bug tracker at
121
122 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-NoWarnings>
123
124 For other issues, contact the author.
125
126HISTORY
127 This was previously known as Test::Warn::None
128
129SEE ALSO
130 Test::Builder, Test::Warn
131
132AUTHORS
133 Fergal Daly <fergal@esatclear.ie>
134
135 Adam Kennedy <adamk@cpan.org>
136
137COPYRIGHT
138 Copyright 2003 - 2007 Fergal Daly.
139
140 Some parts copyright 2010 Adam Kennedy.
141
142 This program is free software and comes with no warranty. It is
143 distributed under the LGPL license
144
145 See the file LGPL included in this distribution or
146 http://www.fsf.org/licenses/licenses.html.
147
148