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