change#3397 needs test tweak
[p5sagit/p5-mst-13.2.git] / t / pragma / strict-vars
CommitLineData
8ebc5c01 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
2c4aebbd 43Global symbol "$fred" requires explicit package name at - line 4.
8ebc5c01 44Execution of - aborted due to compilation errors.
45########
46
47# strict vars - error
48use strict 'vars' ;
49$fred ;
50EXPECT
2c4aebbd 51Global symbol "$fred" requires explicit package name at - line 4.
8ebc5c01 52Execution of - aborted due to compilation errors.
53########
54
55# strict vars - error
56use strict 'vars' ;
57local $fred ;
58EXPECT
2c4aebbd 59Global symbol "$fred" requires explicit package name at - line 4.
8ebc5c01 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.
2c4aebbd 72Global symbol "$joe" requires explicit package name at - line 8.
8ebc5c01 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
2c4aebbd 84Global symbol "$joe" requires explicit package name at - line 6.
8ebc5c01 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.
2c4aebbd 117Global symbol "$joe" requires explicit package name at ./abc line 2.
7a2e2cd6 118Compilation failed in require at - line 2.
8ebc5c01 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.
2c4aebbd 130Global symbol "$joe" requires explicit package name at abc.pm line 2.
7a2e2cd6 131Compilation failed in require at - line 2.
8ebc5c01 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
2c4aebbd 155Global symbol "$joe" requires explicit package name at - line 6.
8ebc5c01 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
2c4aebbd 167Global symbol "$joe" requires explicit package name at - line 5.
8ebc5c01 168Execution of - aborted due to compilation errors.
169########
170
171# Check scope of pragma with eval
172use strict 'vars' ;
173eval {
174 no strict ;
175 $joe = 1 ;
176};
177print STDERR $@;
178$joe = 1 ;
179EXPECT
180Variable "$joe" is not imported at - line 9.
2c4aebbd 181Global symbol "$joe" requires explicit package name at - line 9.
8ebc5c01 182Execution of - aborted due to compilation errors.
183########
184
185# Check scope of pragma with eval
186no strict ;
187eval '
188 $joe = 1 ;
189'; print STDERR $@ ;
190$joe = 1 ;
191EXPECT
192
193########
194
195# Check scope of pragma with eval
196no strict ;
197eval q[
198 use strict 'vars' ;
199 $joe = 1 ;
200]; print STDERR $@;
201EXPECT
2c4aebbd 202Global symbol "$joe" requires explicit package name at (eval 1) line 3.
8ebc5c01 203########
204
205# Check scope of pragma with eval
206use strict 'vars' ;
207eval '
208 $joe = 1 ;
209'; print STDERR $@ ;
210EXPECT
2c4aebbd 211Global symbol "$joe" requires explicit package name at (eval 1) line 2.
8ebc5c01 212########
213
214# Check scope of pragma with eval
215use strict 'vars' ;
216eval '
217 no strict ;
218 $joe = 1 ;
219'; print STDERR $@;
220$joe = 1 ;
221EXPECT
2c4aebbd 222Global symbol "$joe" requires explicit package name at - line 8.
8ebc5c01 223Execution of - aborted due to compilation errors.