Commit | Line | Data |
8ebc5c01 |
1 | Check strict vars functionality |
2 | |
3 | __END__ |
4 | |
5 | # no strict, should build & run ok. |
6 | Fred ; |
7 | my $fred ; |
8 | $b = "fred" ; |
9 | $a = $$b ; |
10 | EXPECT |
11 | |
12 | ######## |
13 | |
14 | use strict qw(subs refs) ; |
15 | $fred ; |
16 | EXPECT |
17 | |
18 | ######## |
19 | |
20 | use strict ; |
21 | no strict 'vars' ; |
22 | $fred ; |
23 | EXPECT |
24 | |
25 | ######## |
26 | |
27 | # strict vars - no error |
28 | use strict 'vars' ; |
29 | use vars qw( $freddy) ; |
30 | local $abc::joe ; |
31 | my $fred ; |
32 | my $b = \$fred ; |
33 | $Fred::ABC = 1 ; |
34 | $freddy = 2 ; |
35 | EXPECT |
36 | |
37 | ######## |
38 | |
39 | # strict vars - error |
40 | use strict ; |
41 | $fred ; |
42 | EXPECT |
2c4aebbd |
43 | Global symbol "$fred" requires explicit package name at - line 4. |
8ebc5c01 |
44 | Execution of - aborted due to compilation errors. |
45 | ######## |
46 | |
47 | # strict vars - error |
48 | use strict 'vars' ; |
49 | $fred ; |
50 | EXPECT |
2c4aebbd |
51 | Global symbol "$fred" requires explicit package name at - line 4. |
8ebc5c01 |
52 | Execution of - aborted due to compilation errors. |
53 | ######## |
54 | |
55 | # strict vars - error |
56 | use strict 'vars' ; |
57 | local $fred ; |
58 | EXPECT |
2c4aebbd |
59 | Global symbol "$fred" requires explicit package name at - line 4. |
8ebc5c01 |
60 | Execution of - aborted due to compilation errors. |
61 | ######## |
62 | |
63 | # Check compile time scope of strict vars pragma |
64 | use strict 'vars' ; |
65 | { |
66 | no strict ; |
67 | $joe = 1 ; |
68 | } |
69 | $joe = 1 ; |
70 | EXPECT |
71 | Variable "$joe" is not imported at - line 8. |
2c4aebbd |
72 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 |
73 | Execution of - aborted due to compilation errors. |
74 | ######## |
75 | |
76 | # Check compile time scope of strict vars pragma |
77 | no strict; |
78 | { |
79 | use strict 'vars' ; |
80 | $joe = 1 ; |
81 | } |
82 | $joe = 1 ; |
83 | EXPECT |
2c4aebbd |
84 | Global symbol "$joe" requires explicit package name at - line 6. |
8ebc5c01 |
85 | Execution of - aborted due to compilation errors. |
86 | ######## |
87 | |
88 | --FILE-- abc |
89 | $joe = 1 ; |
90 | 1; |
91 | --FILE-- |
92 | use strict 'vars' ; |
93 | require "./abc"; |
94 | EXPECT |
95 | |
96 | ######## |
97 | |
98 | --FILE-- abc |
99 | use strict 'vars' ; |
100 | 1; |
101 | --FILE-- |
102 | require "./abc"; |
103 | $joe = 1 ; |
104 | EXPECT |
105 | |
106 | ######## |
107 | |
108 | --FILE-- abc |
109 | use strict 'vars' ; |
110 | $joe = 1 ; |
111 | 1; |
112 | --FILE-- |
113 | $joe = 1 ; |
114 | require "./abc"; |
115 | EXPECT |
116 | Variable "$joe" is not imported at ./abc line 2. |
2c4aebbd |
117 | Global symbol "$joe" requires explicit package name at ./abc line 2. |
7a2e2cd6 |
118 | Compilation failed in require at - line 2. |
8ebc5c01 |
119 | ######## |
120 | |
121 | --FILE-- abc.pm |
122 | use strict 'vars' ; |
123 | $joe = 1 ; |
124 | 1; |
125 | --FILE-- |
126 | $joe = 1 ; |
127 | use abc; |
128 | EXPECT |
129 | Variable "$joe" is not imported at abc.pm line 2. |
2c4aebbd |
130 | Global symbol "$joe" requires explicit package name at abc.pm line 2. |
7a2e2cd6 |
131 | Compilation failed in require at - line 2. |
8ebc5c01 |
132 | BEGIN failed--compilation aborted at - line 2. |
133 | ######## |
134 | |
135 | # Check scope of pragma with eval |
136 | no strict ; |
137 | eval { |
138 | $joe = 1 ; |
139 | }; |
140 | print STDERR $@; |
141 | $joe = 1 ; |
142 | EXPECT |
143 | |
144 | ######## |
145 | |
146 | # Check scope of pragma with eval |
147 | no strict ; |
148 | eval { |
149 | use strict 'vars' ; |
150 | $joe = 1 ; |
151 | }; |
152 | print STDERR $@; |
153 | $joe = 1 ; |
154 | EXPECT |
2c4aebbd |
155 | Global symbol "$joe" requires explicit package name at - line 6. |
8ebc5c01 |
156 | Execution of - aborted due to compilation errors. |
157 | ######## |
158 | |
159 | # Check scope of pragma with eval |
160 | use strict 'vars' ; |
161 | eval { |
162 | $joe = 1 ; |
163 | }; |
164 | print STDERR $@; |
165 | $joe = 1 ; |
166 | EXPECT |
2c4aebbd |
167 | Global symbol "$joe" requires explicit package name at - line 5. |
5a844595 |
168 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 |
169 | Execution of - aborted due to compilation errors. |
170 | ######## |
171 | |
172 | # Check scope of pragma with eval |
173 | use strict 'vars' ; |
174 | eval { |
175 | no strict ; |
176 | $joe = 1 ; |
177 | }; |
178 | print STDERR $@; |
179 | $joe = 1 ; |
180 | EXPECT |
181 | Variable "$joe" is not imported at - line 9. |
2c4aebbd |
182 | Global symbol "$joe" requires explicit package name at - line 9. |
8ebc5c01 |
183 | Execution of - aborted due to compilation errors. |
184 | ######## |
185 | |
186 | # Check scope of pragma with eval |
187 | no strict ; |
188 | eval ' |
189 | $joe = 1 ; |
190 | '; print STDERR $@ ; |
191 | $joe = 1 ; |
192 | EXPECT |
193 | |
194 | ######## |
195 | |
196 | # Check scope of pragma with eval |
197 | no strict ; |
198 | eval q[ |
199 | use strict 'vars' ; |
200 | $joe = 1 ; |
201 | ]; print STDERR $@; |
202 | EXPECT |
2c4aebbd |
203 | Global symbol "$joe" requires explicit package name at (eval 1) line 3. |
8ebc5c01 |
204 | ######## |
205 | |
206 | # Check scope of pragma with eval |
207 | use strict 'vars' ; |
208 | eval ' |
209 | $joe = 1 ; |
210 | '; print STDERR $@ ; |
211 | EXPECT |
2c4aebbd |
212 | Global symbol "$joe" requires explicit package name at (eval 1) line 2. |
8ebc5c01 |
213 | ######## |
214 | |
215 | # Check scope of pragma with eval |
216 | use strict 'vars' ; |
217 | eval ' |
218 | no strict ; |
219 | $joe = 1 ; |
220 | '; print STDERR $@; |
221 | $joe = 1 ; |
222 | EXPECT |
2c4aebbd |
223 | Global symbol "$joe" requires explicit package name at - line 8. |
8ebc5c01 |
224 | Execution of - aborted due to compilation errors. |
5a844595 |
225 | ######## |
226 | |
227 | # Check if multiple evals produce same errors |
228 | use strict 'vars'; |
229 | my $ret = eval q{ print $x; }; |
230 | print $@; |
231 | print "ok 1\n" unless defined $ret; |
232 | $ret = eval q{ print $x; }; |
233 | print $@; |
234 | print "ok 2\n" unless defined $ret; |
235 | EXPECT |
236 | Global symbol "$x" requires explicit package name at (eval 1) line 1. |
237 | ok 1 |
238 | Global symbol "$x" requires explicit package name at (eval 2) line 1. |
239 | ok 2 |