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