xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/lib/warnings/2use (revision 0:68f95e015346)
1Check lexical warnings functionality
2
3TODO
4  check that the warning hierarchy works.
5
6__END__
7
8#  check illegal category is caught
9use warnings 'this-should-never-be-a-warning-category' ;
10EXPECT
11Unknown warnings category 'this-should-never-be-a-warning-category' at - line 3
12BEGIN failed--compilation aborted at - line 3.
13########
14
15# Check compile time scope of pragma
16use warnings 'syntax' ;
17{
18    no warnings ;
19    my $a =+ 1 ;
20}
21my $a =+ 1 ;
22EXPECT
23Reversed += operator at - line 8.
24########
25
26# Check compile time scope of pragma
27no warnings;
28{
29    use warnings 'syntax' ;
30    my $a =+ 1 ;
31}
32my $a =+ 1 ;
33EXPECT
34Reversed += operator at - line 6.
35########
36
37# Check runtime scope of pragma
38use warnings 'uninitialized' ;
39{
40    no warnings ;
41    my $b ; chop $b ;
42}
43my $b ; chop $b ;
44EXPECT
45Use of uninitialized value in scalar chop at - line 8.
46########
47
48# Check runtime scope of pragma
49no warnings ;
50{
51    use warnings 'uninitialized' ;
52    my $b ; chop $b ;
53}
54my $b ; chop $b ;
55EXPECT
56Use of uninitialized value in scalar chop at - line 6.
57########
58
59# Check runtime scope of pragma
60no warnings ;
61{
62    use warnings 'uninitialized' ;
63    $a = sub { my $b ; chop $b ; }
64}
65&$a ;
66EXPECT
67Use of uninitialized value in scalar chop at - line 6.
68########
69
70use warnings 'syntax' ;
71my $a =+ 1 ;
72EXPECT
73Reversed += operator at - line 3.
74########
75
76--FILE-- abc
77my $a =+ 1 ;
781;
79--FILE--
80use warnings 'syntax' ;
81require "./abc";
82EXPECT
83
84########
85
86--FILE-- abc
87use warnings 'syntax' ;
881;
89--FILE--
90require "./abc";
91my $a =+ 1 ;
92EXPECT
93
94########
95
96--FILE-- abc
97use warnings 'syntax' ;
98my $a =+ 1 ;
991;
100--FILE--
101use warnings 'uninitialized' ;
102require "./abc";
103my $a ; chop $a ;
104EXPECT
105Reversed += operator at ./abc line 2.
106Use of uninitialized value in scalar chop at - line 3.
107########
108
109--FILE-- abc.pm
110use warnings 'syntax' ;
111my $a =+ 1 ;
1121;
113--FILE--
114use warnings 'uninitialized' ;
115use abc;
116my $a ; chop $a ;
117EXPECT
118Reversed += operator at abc.pm line 2.
119Use of uninitialized value in scalar chop at - line 3.
120########
121
122# Check scope of pragma with eval
123use warnings;
124{
125    no warnings ;
126    eval {
127        my $b ; chop $b ;
128    }; print STDERR $@ ;
129    my $b ; chop $b ;
130}
131EXPECT
132
133########
134
135# Check scope of pragma with eval
136use warnings;
137{
138    no warnings ;
139    eval {
140        use warnings 'uninitialized' ;
141        my $b ; chop $b ;
142    }; print STDERR $@ ;
143    my $b ; chop $b ;
144}
145EXPECT
146Use of uninitialized value in scalar chop at - line 8.
147########
148
149# Check scope of pragma with eval
150no warnings;
151{
152    use warnings 'uninitialized' ;
153    eval {
154        my $b ; chop $b ;
155    }; print STDERR $@ ;
156    my $b ; chop $b ;
157}
158EXPECT
159Use of uninitialized value in scalar chop at - line 7.
160Use of uninitialized value in scalar chop at - line 9.
161########
162
163# Check scope of pragma with eval
164no warnings;
165{
166    use warnings 'uninitialized' ;
167    eval {
168        no warnings ;
169        my $b ; chop $b ;
170    }; print STDERR $@ ;
171    my $b ; chop $b ;
172}
173EXPECT
174Use of uninitialized value in scalar chop at - line 10.
175########
176
177# Check scope of pragma with eval
178use warnings;
179{
180    no warnings ;
181    eval {
182        my $a =+ 1 ;
183    }; print STDERR $@ ;
184    my $a =+ 1 ;
185}
186EXPECT
187
188########
189
190# Check scope of pragma with eval
191use warnings;
192{
193    no warnings ;
194    eval {
195        use warnings 'syntax' ;
196        my $a =+ 1 ;
197    }; print STDERR $@ ;
198    my $a =+ 1 ;
199}
200EXPECT
201Reversed += operator at - line 8.
202########
203
204# Check scope of pragma with eval
205no warnings;
206{
207    use warnings 'syntax' ;
208    eval {
209        my $a =+ 1 ;
210    }; print STDERR $@ ;
211    my $a =+ 1 ;
212}
213EXPECT
214Reversed += operator at - line 7.
215Reversed += operator at - line 9.
216########
217
218# Check scope of pragma with eval
219no warnings;
220{
221    use warnings 'syntax' ;
222    eval {
223        no warnings ;
224        my $a =+ 1 ;
225    }; print STDERR $@ ;
226    my $a =+ 1 ;
227}
228EXPECT
229Reversed += operator at - line 10.
230########
231
232# Check scope of pragma with eval
233use warnings;
234{
235    no warnings ;
236    eval '
237        my $b ; chop $b ;
238    '; print STDERR $@ ;
239    my $b ; chop $b ;
240}
241EXPECT
242
243########
244
245# Check scope of pragma with eval
246use warnings;
247{
248    no warnings ;
249    eval q[
250        use warnings 'uninitialized' ;
251        my $b ; chop $b ;
252    ]; print STDERR $@;
253    my $b ; chop $b ;
254}
255EXPECT
256Use of uninitialized value in scalar chop at (eval 1) line 3.
257########
258
259# Check scope of pragma with eval
260no warnings;
261{
262    use warnings 'uninitialized' ;
263    eval '
264        my $b ; chop $b ;
265    '; print STDERR $@ ;
266    my $b ; chop $b ;
267}
268EXPECT
269Use of uninitialized value in scalar chop at (eval 1) line 2.
270Use of uninitialized value in scalar chop at - line 9.
271########
272
273# Check scope of pragma with eval
274no warnings;
275{
276    use warnings 'uninitialized' ;
277    eval '
278        no warnings ;
279        my $b ; chop $b ;
280    '; print STDERR $@ ;
281    my $b ; chop $b ;
282}
283EXPECT
284Use of uninitialized value in scalar chop at - line 10.
285########
286
287# Check scope of pragma with eval
288use warnings;
289{
290    no warnings ;
291    eval '
292        my $a =+ 1 ;
293    '; print STDERR $@ ;
294    my $a =+ 1 ;
295}
296EXPECT
297
298########
299
300# Check scope of pragma with eval
301use warnings;
302{
303    no warnings ;
304    eval q[
305        use warnings 'syntax' ;
306        my $a =+ 1 ;
307    ]; print STDERR $@;
308    my $a =+ 1 ;
309}
310EXPECT
311Reversed += operator at (eval 1) line 3.
312########
313
314# Check scope of pragma with eval
315no warnings;
316{
317    use warnings 'syntax' ;
318    eval '
319        my $a =+ 1 ;
320    '; print STDERR $@;
321    my $a =+ 1 ;
322}
323EXPECT
324Reversed += operator at - line 9.
325Reversed += operator at (eval 1) line 2.
326########
327
328# Check scope of pragma with eval
329no warnings;
330{
331    use warnings 'syntax' ;
332    eval '
333        no warnings ;
334        my $a =+ 1 ;
335    '; print STDERR $@;
336    my $a =+ 1 ;
337}
338EXPECT
339Reversed += operator at - line 10.
340########
341
342# Check the additive nature of the pragma
343my $a =+ 1 ;
344my $a ; chop $a ;
345use warnings 'syntax' ;
346$a =+ 1 ;
347my $b ; chop $b ;
348use warnings 'uninitialized' ;
349my $c ; chop $c ;
350no warnings 'syntax' ;
351$a =+ 1 ;
352EXPECT
353Reversed += operator at - line 6.
354Use of uninitialized value in scalar chop at - line 9.
355