[inseparable changes from patch from perl5.003_20 to perl5.003_21]
[p5sagit/p5-mst-13.2.git] / t / pragma / strict-refs
CommitLineData
8ebc5c01 1Check strict refs functionality
2
3__END__
4
5# no strict, should build & run ok.
6my $fred ;
7$b = "fred" ;
8$a = $$b ;
9$c = ${"def"} ;
10$c = @{"def"} ;
11$c = %{"def"} ;
12$c = *{"def"} ;
13$c = \&{"def"} ;
44a8e56a 14$c = def->[0];
15$c = def->{xyz};
8ebc5c01 16EXPECT
17
18########
19
20# strict refs - error
21use strict ;
22my $fred ;
23my $a = ${"fred"} ;
24EXPECT
25Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5.
26########
27
28# strict refs - error
29use strict 'refs' ;
30my $fred ;
31my $a = ${"fred"} ;
32EXPECT
33Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5.
34########
35
36# strict refs - error
37use strict 'refs' ;
38my $fred ;
39my $b = "fred" ;
40my $a = $$b ;
41EXPECT
42Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 6.
43########
44
45# strict refs - error
46use strict 'refs' ;
47my $b ;
48my $a = $$b ;
49EXPECT
50Can't use an undefined value as a SCALAR reference at - line 5.
51########
52
53# strict refs - error
54use strict 'refs' ;
55my $b ;
56my $a = @$b ;
57EXPECT
58Can't use an undefined value as an ARRAY reference at - line 5.
59########
60
61# strict refs - error
62use strict 'refs' ;
63my $b ;
64my $a = %$b ;
65EXPECT
66Can't use an undefined value as a HASH reference at - line 5.
67########
68
69# strict refs - error
70use strict 'refs' ;
71my $b ;
72my $a = *$b ;
73EXPECT
74Can't use an undefined value as a symbol reference at - line 5.
75########
76
44a8e56a 77# strict refs - error
78use strict 'refs' ;
79my $a = fred->[0] ;
80EXPECT
81Can't use bareword ("fred") as an ARRAY ref while "strict refs" in use at - line 4.
82########
83
84# strict refs - error
85use strict 'refs' ;
86my $a = fred->{barney} ;
87EXPECT
88Can't use bareword ("fred") as a HASH ref while "strict refs" in use at - line 4.
89########
90
8ebc5c01 91# strict refs - no error
92use strict ;
93no strict 'refs' ;
94my $fred ;
95my $b = "fred" ;
96my $a = $$b ;
97use strict 'refs' ;
98EXPECT
99
100########
101
102# strict refs - no error
103use strict qw(subs vars) ;
104my $fred ;
105my $b = "fred" ;
106my $a = $$b ;
107use strict 'refs' ;
108EXPECT
109
110########
111
112# strict refs - no error
113my $fred ;
114my $b = "fred" ;
115my $a = $$b ;
116use strict 'refs' ;
117EXPECT
118
119########
120
121# strict refs - no error
122use strict 'refs' ;
123my $fred ;
124my $b = \$fred ;
125my $a = $$b ;
126EXPECT
127
128########
129
130# Check runtime scope of strict refs pragma
131use strict 'refs';
132my $fred ;
133my $b = "fred" ;
134{
135 no strict ;
136 my $a = $$b ;
137}
138my $a = $$b ;
139EXPECT
140Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10.
141########
142
143# Check runtime scope of strict refs pragma
144no strict ;
145my $fred ;
146my $b = "fred" ;
147{
148 use strict 'refs' ;
149 my $a = $$b ;
150}
151my $a = $$b ;
152EXPECT
153Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.
154########
155
156# Check runtime scope of strict refs pragma
157no strict ;
158my $fred ;
159my $b = "fred" ;
160{
161 use strict 'refs' ;
162 $a = sub { my $c = $$b ; }
163}
164&$a ;
165EXPECT
166Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.
167########
168
169
170--FILE-- abc
171my $a = ${"Fred"} ;
1721;
173--FILE--
174use strict 'refs' ;
175require "./abc";
176EXPECT
177
178########
179
180--FILE-- abc
181use strict 'refs' ;
1821;
183--FILE--
184require "./abc";
185my $a = ${"Fred"} ;
186EXPECT
187
188########
189
190--FILE-- abc
191use strict 'refs' ;
192my $a = ${"Fred"} ;
1931;
194--FILE--
195${"Fred"} ;
196require "./abc";
197EXPECT
198Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at ./abc line 2.
199########
200
201--FILE-- abc.pm
202use strict 'refs' ;
203my $a = ${"Fred"} ;
2041;
205--FILE--
206my $a = ${"Fred"} ;
207use abc;
208EXPECT
209Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at abc.pm line 2.
210BEGIN failed--compilation aborted at - line 2.
211########
212
213# Check scope of pragma with eval
214no strict ;
215eval {
216 my $a = ${"Fred"} ;
217};
218print STDERR $@ ;
219my $a = ${"Fred"} ;
220EXPECT
221
222########
223
224# Check scope of pragma with eval
225no strict ;
226eval {
227 use strict 'refs' ;
228 my $a = ${"Fred"} ;
229};
230print STDERR $@ ;
231my $a = ${"Fred"} ;
232EXPECT
233Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 6.
234########
235
236# Check scope of pragma with eval
237use strict 'refs' ;
238eval {
239 my $a = ${"Fred"} ;
240};
241print STDERR $@ ;
242EXPECT
243Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 5.
244########
245
246# Check scope of pragma with eval
247use strict 'refs' ;
248eval {
249 no strict ;
250 my $a = ${"Fred"} ;
251};
252print STDERR $@ ;
253my $a = ${"Fred"} ;
254EXPECT
255Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 9.
256########
257
258# Check scope of pragma with eval
259no strict ;
260eval '
261 my $a = ${"Fred"} ;
262'; print STDERR $@ ;
263my $a = ${"Fred"} ;
264EXPECT
265
266########
267
268# Check scope of pragma with eval
269no strict ;
270eval q[
271 use strict 'refs' ;
272 my $a = ${"Fred"} ;
273]; print STDERR $@;
274EXPECT
275Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 3.
276########
277
278# Check scope of pragma with eval
279use strict 'refs' ;
280eval '
281 my $a = ${"Fred"} ;
282'; print STDERR $@ ;
283EXPECT
284Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 2.
285########
286
287# Check scope of pragma with eval
288use strict 'refs' ;
289eval '
290 no strict ;
291 my $a = ${"Fred"} ;
292'; print STDERR $@;
293my $a = ${"Fred"} ;
294EXPECT
295Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 8.