1 Author: Jay Bonci <jaybonci@debian.org>
2 Description: Patch from Era Eriksson to clean up some manpage language
8 warning_is {foo(-dri => "/")} "Unknown Parameter 'dri'", "dri != dir gives warning";
9 warnings_are {bar(1,1)} ["Width very small", "Height very small"];
11 - warning_is {add(2,2)} undef, "No warning to calc 2+2"; # or
12 - warnings_are {add(2,2)} [], "No warning to calc 2+2"; # what reads better :-)
13 + warning_is {add(2,2)} undef, "No warning for calc 2+2"; # or
14 + warnings_are {add(2,2)} [], "No warning for calc 2+2"; # what reads better :-)
16 warning_like {foo(-dri => "/")} qr/unknown param/i, "an unknown parameter test";
17 warnings_like {bar(1,1)} [qr/width.*small/i, qr/height.*small/i];
19 - warning_is {foo()} {carped => "didn't found the right parameters"};
20 + warning_is {foo()} {carped => "didn't find the right parameters"};
21 warnings_like {foo()} [qr/undefined/,qr/undefined/,{carped => qr/no result/i}];
23 warning_like {foo(undef)} 'uninitialized';
28 -This module provides a few convenience methods for testing warning based code.
29 +This module provides a few convenience methods for testing warning-based code.
31 -If you are not already familiar with the Test::More manpage
32 +If you are not already familiar with the Test::More manpage,
33 now would be the time to go take a look.
38 =item warning_is BLOCK STRING, TEST_NAME
40 -Tests that BLOCK gives exactly the one specificated warning.
41 -The test fails if the BLOCK warns more then one times or doesn't warn.
42 +Tests that BLOCK give exactly the one specified warning.
43 +The test fails if the BLOCK warns more then one time or doesn't warn.
44 If the string is undef,
45 then the tests succeeds iff the BLOCK doesn't give any warning.
46 -Another way to say that there aren't ary warnings in the block,
47 -is C<warnings_are {foo()} [], "no warnings in">.
48 +Another way to say that there aren't any warnings in the block
49 +is C<warnings_are {foo()} [], "no warnings">.
51 -If you want to test for a warning given by carp,
52 -You have to write something like:
53 +If you want to test for a warning given by carp
54 +you have to write something like:
55 C<warning_is {carp "msg"} {carped =E<gt> 'msg'}, "Test for a carped warning">.
58 if a "normal" warning is found instead of a "carped" one.
60 Note: C<warn "foo"> would print something like C<foo at -e line 1>.
61 This method ignores everything after the at. That means, to match this warning
62 you would have to call C<warning_is {warn "foo"} "foo", "Foo succeeded">.
63 If you need to test for a warning at an exactly line,
64 -try better something like C<warning_like {warn "foo"} qr/at XYZ.dat line 5/>.
65 +try something like C<warning_like {warn "foo"} qr/at XYZ.dat line 5/>.
67 warning_is and warning_are are only aliases to the same method.
68 So you also could write
69 C<warning_is {foo()} [], "no warning"> or something similar.
70 -I decided me to give two methods to have some better readable method names.
71 +I decided to give two methods to have some more readable method names.
73 A true value is returned if the test succeeds, false otherwise.
76 =item warnings_are BLOCK ARRAYREF, TEST_NAME
78 Tests to see that BLOCK gives exactly the specificated warnings.
79 -The test fails if the BLOCK warns a different number than the size of the ARRAYREf
81 +The test fails if the warnings from BLOCK are not exactly the ones in ARRAYREF.
82 If the ARRAYREF is equal to [],
83 then the test succeeds iff the BLOCK doesn't give any warning.
85 Please read also the notes to warning_is as these methods are only aliases.
87 -If you want more than one tests for carped warnings look that way:
88 +If you want more than one test for carped warnings, try this:
89 C<warnings_are {carp "c1"; carp "c2"} {carped => ['c1','c2'];> or
90 C<warnings_are {foo()} ["Warning 1", {carped => ["Carp 1", "Carp 2"]}, "Warning 2"]>.
91 -Note that C<{carped => ...}> has always to be a hash ref.
92 +Note that C<{carped => ...}> always has to be a hash ref.
94 =item warning_like BLOCK REGEXP, TEST_NAME
96 -Tests that BLOCK gives exactly one warning and it can be matched to the given regexp.
97 +Tests that BLOCK gives exactly one warning and it can be matched by
99 If the string is undef,
100 then the tests succeeds iff the BLOCK doesn't give any warning.
102 -The REGEXP is matched after the whole warn line,
103 -which consists in general of "WARNING at __FILE__ line __LINE__".
104 -So you can check for a warning in at File Foo.pm line 5 with
105 +The REGEXP is matched against the whole warning message,
106 +which in general has the form "WARNING at __FILE__ line __LINE__".
107 +So you can check for a warning in the file Foo.pm on line 5 with
108 C<warning_like {bar()} qr/at Foo.pm line 5/, "Testname">.
109 -I don't know whether it's sensful to do such a test :-(
110 -However, you should be prepared as a matching with 'at', 'file', '\d'
111 +Perhaps it isn't sensible to perform such a test;
112 +however, you should be aware that matching on a sweeping regular expression
113 +such as 'at', 'file', '\d'
114 or similar will always pass.
115 -Think to the qr/^foo/ if you want to test for warning "foo something" in file foo.pl.
116 +Consider qr/^foo/ if you want to test for warning "foo something" in file foo.pl.
118 You can also write the regexp in a string as "/.../"
119 instead of using the qr/.../ syntax.
121 as strings without slashes are reserved for warning categories
122 (to match warning categories as can be seen in the perllexwarn man page).
124 -Similar to C<warning_is>,
125 +As with C<warning_is>,
126 you can test for warnings via C<carp> with:
127 C<warning_like {bar()} {carped => qr/bar called too early/i};>
129 @@ -119,17 +120,18 @@
130 Tests whether a BLOCK gives exactly one warning of the passed category.
131 The categories are grouped in a tree,
132 like it is expressed in perllexwarn.
133 -Note, that they have the hierarchical structure from perl 5.8.0,
134 -wich has a little bit changed to 5.6.1 or earlier versions
135 -(You can access the internal used tree with C<$Test::Warn::Categorization::tree>,
136 -allthough I wouldn't recommend it)
137 +Note that they have the hierarchical structure from perl 5.8.0,
138 +which is slightly different from how it was organized up through perl 5.6.1.
139 +(You can access the internal hierarchy with
140 +C<$Test::Warn::Categorization::tree>,
141 +although it isn't recommended).
143 Thanks to the grouping in a tree,
144 -it's simple possible to test for an 'io' warning,
145 -instead for testing for a 'closed|exec|layer|newline|pipe|unopened' warning.
146 +it's possible to test simply for an 'io' warning,
147 +instead of testing for a 'closed|exec|layer|newline|pipe|unopened' warning.
149 -Note, that warnings occuring at compile time,
150 -can only be catched in an eval block. So
151 +Note that compile-time warnings
152 +can only be caught in an eval block. So
154 warning_like {eval q/"$x"; $x;/}
155 [qw/void uninitialized/],
158 while it wouldn't work without the eval.
160 -Note, that it isn't possible yet,
161 -to test for own categories,
162 -created with warnings::register.
163 +Note also that it isn't yet possible
164 +to test for categories you created yourself with C<warnings::register>.
166 =item warnings_like BLOCK ARRAYREF, TEST_NAME
169 {carped => qr/bar warning/i},
172 - "I hope, you'll never have to write a test for so many warnings :-)";
173 + "I hope you'll never have to write a test for so many warnings :-)";
177 @@ -174,27 +175,28 @@
180 Please note that warnings with newlines inside are making a lot of trouble.
181 -The only sensful way to handle them is to use are the C<warning_like> or
182 -C<warnings_like> methods. Background for these problems is that there is no
183 -really secure way to distinguish between warnings with newlines and a tracing
184 +The only sensible way to handle them is to use the C<warning_like> or
185 +C<warnings_like> methods.
186 +The background for these problems is that there is no
187 +really secure way to distinguish between warnings with newlines and a trailing
190 -If a method has it's own warn handler,
191 +If a method has its own warn handler,
192 overwriting C<$SIG{__WARN__}>,
193 my test warning methods won't get these warnings.
195 -The C<warning_like BLOCK CATEGORY, TEST_NAME> method isn't extremely tested.
196 -Please use this calling style with higher attention and
197 -tell me if you find a bug.
198 +The C<warning_like BLOCK CATEGORY, TEST_NAME> method isn't fully tested.
199 +Please pay attention if you use this this calling style,
200 +and report any bugs you find.
204 Improve this documentation.
206 The code has some parts doubled - especially in the test scripts.
207 -This is really awkward and has to be changed.
208 +This is really awkward and must be changed.
210 -Please feel free to suggest me any improvements.
211 +Please feel free to suggest improvements.
216 $Tester->diag( "found warning: $_" );
219 - $Tester->diag( "didn't found a warning" ) unless @_;
220 + $Tester->diag( "didn't find a warning" ) unless @_;
223 sub _diag_exp_warning {
230 - : "didn't found a warning";
231 + : "didn't find a warning";
238 CARP_LINE) ) # Note the difference, that carp msg
239 - : "didn't found a warning"; # aren't finished by '.'
240 + : "didn't find a warning"; # aren't finished by '.'
244 --- a/t/warning_like.t
245 +++ b/t/warning_like.t
250 - : "didn't found a warning";
251 + : "didn't find a warning";
258 CARP_LINE) ) # Note the difference, that carp msg
259 - : "didn't found a warning"; # aren't finished by '.'
260 + : "didn't find a warning"; # aren't finished by '.'
264 --- a/t/warnings_are.t
265 +++ b/t/warnings_are.t
268 sub _found_warn_msg {
269 @_ ? map({"found warning: $_ at ". __FILE__ . " line " . WARN_LINE . "." } @_)
270 - : "didn't found a warning";
271 + : "didn't find a warning";
274 sub _found_carp_msg {
275 @_ ? map({"found carped warning: $_ at ". __FILE__ . " line " . CARP_LINE} @_)
276 - : "didn't found a warning";
277 + : "didn't find a warning";
281 --- a/t/warnings_like.t
282 +++ b/t/warnings_like.t
285 sub _found_warn_msg {
286 @_ ? map({"found warning: $_ at ". __FILE__ . " line " . WARN_LINE . "." } @_)
287 - : "didn't found a warning";
288 + : "didn't find a warning";
291 sub _found_carp_msg {
292 @_ ? map({"found carped warning: $_ at ". __FILE__ . " line " . CARP_LINE} @_)
293 - : "didn't found a warning";
294 + : "didn't find a warning";