Move the locale/strict/warnings helper files back
[p5sagit/p5-mst-13.2.git] / t / lib / strict / subs
CommitLineData
8ebc5c01 1Check strict subs 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(refs vars);
15Fred ;
16EXPECT
17
18########
19
20use strict ;
21no strict 'subs' ;
22Fred ;
23EXPECT
24
25########
26
27# strict subs - error
28use strict 'subs' ;
29Fred ;
30EXPECT
31Bareword "Fred" not allowed while "strict subs" in use at - line 4.
32Execution of - aborted due to compilation errors.
33########
34
35# strict subs - error
7d4045d4 36use strict 'subs' ;
37my @a = (A..Z);
38EXPECT
39Bareword "Z" not allowed while "strict subs" in use at - line 4.
40Bareword "A" not allowed while "strict subs" in use at - line 4.
41Execution of - aborted due to compilation errors.
42########
43
44# strict subs - error
45use strict 'subs' ;
46my $a = (B..Y);
47EXPECT
48Bareword "Y" not allowed while "strict subs" in use at - line 4.
49Bareword "B" not allowed while "strict subs" in use at - line 4.
50Execution of - aborted due to compilation errors.
51########
52
53# strict subs - error
8ebc5c01 54use strict ;
55Fred ;
56EXPECT
57Bareword "Fred" not allowed while "strict subs" in use at - line 4.
58Execution of - aborted due to compilation errors.
59########
60
61# strict subs - no error
62use strict 'subs' ;
63sub Fred {}
64Fred ;
65EXPECT
66
67########
68
69# Check compile time scope of strict subs pragma
70use strict 'subs' ;
71{
72 no strict ;
73 my $a = Fred ;
74}
75my $a = Fred ;
76EXPECT
77Bareword "Fred" not allowed while "strict subs" in use at - line 8.
78Execution of - aborted due to compilation errors.
79########
80
81# Check compile time scope of strict subs pragma
82no strict;
83{
84 use strict 'subs' ;
85 my $a = Fred ;
86}
87my $a = Fred ;
88EXPECT
89Bareword "Fred" not allowed while "strict subs" in use at - line 6.
90Execution of - aborted due to compilation errors.
91########
92
93# Check compile time scope of strict vars pragma
94use strict 'vars' ;
95{
96 no strict ;
97 $joe = 1 ;
98}
99$joe = 1 ;
100EXPECT
101Variable "$joe" is not imported at - line 8.
2c4aebbd 102Global symbol "$joe" requires explicit package name at - line 8.
8ebc5c01 103Execution of - aborted due to compilation errors.
104########
105
106# Check compile time scope of strict vars pragma
107no strict;
108{
109 use strict 'vars' ;
110 $joe = 1 ;
111}
112$joe = 1 ;
113EXPECT
2c4aebbd 114Global symbol "$joe" requires explicit package name at - line 6.
8ebc5c01 115Execution of - aborted due to compilation errors.
116########
117
118# Check runtime scope of strict refs pragma
119use strict 'refs';
120my $fred ;
121my $b = "fred" ;
122{
123 no strict ;
124 my $a = $$b ;
125}
126my $a = $$b ;
127EXPECT
128Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10.
129########
130
131# Check runtime scope of strict refs pragma
132no strict ;
133my $fred ;
134my $b = "fred" ;
135{
136 use strict 'refs' ;
137 my $a = $$b ;
138}
139my $a = $$b ;
140EXPECT
141Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.
142########
143
144# Check runtime scope of strict refs pragma
145no strict ;
146my $fred ;
147my $b = "fred" ;
148{
149 use strict 'refs' ;
150 $a = sub { my $c = $$b ; }
151}
152&$a ;
153EXPECT
154Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.
155########
156
157use strict 'subs' ;
158my $a = Fred ;
159EXPECT
160Bareword "Fred" not allowed while "strict subs" in use at - line 3.
161Execution of - aborted due to compilation errors.
162########
163
164--FILE-- abc
165my $a = Fred ;
1661;
167--FILE--
168use strict 'subs' ;
169require "./abc";
170EXPECT
171
172########
173
174--FILE-- abc
175use strict 'subs' ;
1761;
177--FILE--
178require "./abc";
179my $a = Fred ;
180EXPECT
181
182########
183
184--FILE-- abc
185use strict 'subs' ;
186my $a = Fred ;
1871;
188--FILE--
189Fred ;
190require "./abc";
191EXPECT
192Bareword "Fred" not allowed while "strict subs" in use at ./abc line 2.
7a2e2cd6 193Compilation failed in require at - line 2.
8ebc5c01 194########
195
196--FILE-- abc.pm
197use strict 'subs' ;
198my $a = Fred ;
1991;
200--FILE--
201Fred ;
202use abc;
203EXPECT
204Bareword "Fred" not allowed while "strict subs" in use at abc.pm line 2.
7a2e2cd6 205Compilation failed in require at - line 2.
8ebc5c01 206BEGIN failed--compilation aborted at - line 2.
207########
208
209# Check scope of pragma with eval
210no strict ;
211eval {
212 my $a = Fred ;
213};
214print STDERR $@;
215my $a = Fred ;
216EXPECT
217
218########
219
220# Check scope of pragma with eval
221no strict ;
222eval {
223 use strict 'subs' ;
224 my $a = Fred ;
225};
226print STDERR $@;
227my $a = Fred ;
228EXPECT
229Bareword "Fred" not allowed while "strict subs" in use at - line 6.
230Execution of - aborted due to compilation errors.
231########
232
233# Check scope of pragma with eval
234use strict 'subs' ;
235eval {
236 my $a = Fred ;
237};
238print STDERR $@;
239my $a = Fred ;
240EXPECT
241Bareword "Fred" not allowed while "strict subs" in use at - line 5.
242Bareword "Fred" not allowed while "strict subs" in use at - line 8.
243Execution of - aborted due to compilation errors.
244########
245
246# Check scope of pragma with eval
247use strict 'subs' ;
248eval {
249 no strict ;
250 my $a = Fred ;
251};
252print STDERR $@;
253my $a = Fred ;
254EXPECT
255Bareword "Fred" not allowed while "strict subs" in use at - line 9.
256Execution of - aborted due to compilation errors.
257########
258
259# Check scope of pragma with eval
260no strict ;
261eval '
262 Fred ;
263'; print STDERR $@ ;
264Fred ;
265EXPECT
266
267########
268
269# Check scope of pragma with eval
270no strict ;
271eval q[
272 use strict 'subs' ;
273 Fred ;
274]; print STDERR $@;
275EXPECT
276Bareword "Fred" not allowed while "strict subs" in use at (eval 1) line 3.
277########
278
279# Check scope of pragma with eval
280use strict 'subs' ;
281eval '
282 Fred ;
283'; print STDERR $@ ;
284EXPECT
285Bareword "Fred" not allowed while "strict subs" in use at (eval 1) line 2.
286########
287
288# Check scope of pragma with eval
289use strict 'subs' ;
290eval '
291 no strict ;
292 my $a = Fred ;
293'; print STDERR $@;
294my $a = Fred ;
295EXPECT
296Bareword "Fred" not allowed while "strict subs" in use at - line 8.
297Execution of - aborted due to compilation errors.
58a40671 298########
299
300# see if Foo->Bar(...) etc work under strictures
301use strict;
302package Foo; sub Bar { print "@_\n" }
303Foo->Bar('a',1);
304Bar Foo ('b',2);
305Foo->Bar(qw/c 3/);
306Bar Foo (qw/d 4/);
307Foo::->Bar('A',1);
308Bar Foo:: ('B',2);
309Foo::->Bar(qw/C 3/);
310Bar Foo:: (qw/D 4/);
311EXPECT
312Foo a 1
313Foo b 2
314Foo c 3
315Foo d 4
316Foo A 1
317Foo B 2
318Foo C 3
319Foo D 4