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