1Check existing $^W functionality
2
3
4__END__
5
6# warnable code, warnings disabled
7$a =+ 3 ;
8EXPECT
9
10########
11-w
12# warnable code, warnings enabled via command line switch
13$c =+ 3 ;
14EXPECT
15Reversed += operator at - line 3.
16Name "main::c" used only once: possible typo at - line 3.
17########
18#! perl -w
19# warnable code, warnings enabled via #! line
20$c =+ 3 ;
21EXPECT
22Reversed += operator at - line 3.
23Name "main::c" used only once: possible typo at - line 3.
24########
25
26# warnable code, warnings enabled via compile time $^W
27BEGIN { $^W = 1 }
28$c =+ 3 ;
29EXPECT
30Reversed += operator at - line 4.
31Name "main::c" used only once: possible typo at - line 4.
32########
33-w
34# warnable code, warnings enabled via command line switch
35use utf8;
36use open qw( :utf8 :std );
37$Ằ =+ 3 ;
38EXPECT
39Reversed += operator at - line 5.
40Name "main::Ằ" used only once: possible typo at - line 5.
41########
42#! perl -w
43# warnable code, warnings enabled via #! line
44use utf8;
45use open qw( :utf8 :std );
46$Ằ =+ 3 ;
47EXPECT
48Reversed += operator at - line 5.
49Name "main::Ằ" used only once: possible typo at - line 5.
50########
51
52# warnable code, warnings enabled via compile time $^W
53BEGIN { $^W = 1 }
54use utf8;
55use open qw( :utf8 :std );
56$Ằ =+ 3 ;
57EXPECT
58Reversed += operator at - line 6.
59Name "main::Ằ" used only once: possible typo at - line 6.
60
61########
62
63# compile-time warnable code, warnings enabled via runtime $^W
64# so no warning printed.
65$^W = 1 ;
66$a =+ 3 ;
67EXPECT
68
69########
70
71# warnable code, warnings enabled via runtime $^W
72$^W = 1 ;
73my $b ; chop $b ;
74EXPECT
75Use of uninitialized value $b in scalar chop at - line 4.
76########
77
78# warnings enabled at compile time, disabled at run time
79BEGIN { $^W = 1 }
80$^W = 0 ;
81my $b ; chop $b ;
82EXPECT
83
84########
85
86# warnings disabled at compile time, enabled at run time
87BEGIN { $^W = 0 }
88$^W = 1 ;
89my $b ; chop $b ;
90EXPECT
91Use of uninitialized value $b in scalar chop at - line 5.
92########
93-w
94--FILE-- abcd
95my $b ; chop $b ;
961 ;
97--FILE--
98require "./abcd";
99EXPECT
100Use of uninitialized value $b in scalar chop at ./abcd line 1.
101########
102
103--FILE-- abcd
104my $b ; chop $b ;
1051 ;
106--FILE--
107#! perl -w
108require "./abcd";
109EXPECT
110Use of uninitialized value $b in scalar chop at ./abcd line 1.
111########
112
113--FILE-- abcd
114my $b ; chop $b ;
1151 ;
116--FILE--
117$^W =1 ;
118require "./abcd";
119EXPECT
120Use of uninitialized value $b in scalar chop at ./abcd line 1.
121########
122
123--FILE-- abcd
124$^W = 0;
125my $b ; chop $b ;
1261 ;
127--FILE--
128$^W =1 ;
129require "./abcd";
130EXPECT
131
132########
133
134--FILE-- abcd
135$^W = 1;
1361 ;
137--FILE--
138$^W =0 ;
139require "./abcd";
140my $b ; chop $b ;
141EXPECT
142Use of uninitialized value $b in scalar chop at - line 3.
143########
144
145$^W = 1;
146eval 'my $b ; chop $b ;' ;
147print $@ ;
148EXPECT
149Use of uninitialized value $b in scalar chop at (eval 1) line 1.
150########
151
152eval '$^W = 1;' ;
153print $@ ;
154my $b ; chop $b ;
155EXPECT
156Use of uninitialized value $b in scalar chop at - line 4.
157########
158
159eval {$^W = 1;} ;
160print $@ ;
161my $b ; chop $b ;
162EXPECT
163Use of uninitialized value $b in scalar chop at - line 4.
164########
165
166{
167    local ($^W) = 1;
168}
169my $b ; chop $b ;
170EXPECT
171
172########
173
174my $a ; chop $a ;
175{
176    local ($^W) = 1;
177    my $b ; chop $b ;
178}
179my $c ; chop $c ;
180EXPECT
181Use of uninitialized value $b in scalar chop at - line 5.
182########
183-w
184-e undef
185EXPECT
186Use of uninitialized value in -e at - line 2.
187########
188
189$^W = 1 + 2 ;
190EXPECT
191
192########
193
194$^W = $a ;
195EXPECT
196
197########
198
199sub fred {}
200$^W = fred() ;
201EXPECT
202
203########
204
205sub fred { my $b ; chop $b ;}
206{ local $^W = 0 ;
207  fred() ;
208}
209EXPECT
210
211########
212
213sub fred { my $b ; chop $b ;}
214{ local $^W = 1 ;
215  fred() ;
216}
217EXPECT
218Use of uninitialized value $b in scalar chop at - line 2.
219