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