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