Commit | Line | Data |
a0d0e21e |
1 | #!./perl |
2 | |
c9beb3f5 |
3 | # This is for tests that will normally cause segfaults, and other nasty |
4 | # errors that might kill the interpreter and for some reason you can't |
5 | # use an eval(). |
6 | # |
7 | # New tests are added to the bottom. For example. |
8 | # |
9 | # ######## perlbug ID 20020831.001 |
10 | # ($a, b) = (1,2) |
11 | # EXPECT |
12 | # Can't modify constant item in list assignment - at line 1 |
13 | # |
14 | # to test that the code "($a, b) = (1,2)" causes the appropriate syntax |
15 | # error, rather than just segfaulting as reported in perlbug ID |
16 | # 20020831.001 |
17 | # |
18 | # |
19 | # NOTE: Please don't add tests to this file unless they *need* to be |
20 | # run in separate executable and can't simply use eval. |
fb73857a |
21 | |
c9beb3f5 |
22 | BEGIN { |
23 | chdir 't' if -d 't'; |
24 | @INC = '../lib'; |
25 | } |
26 | |
27 | use strict; |
a0d0e21e |
28 | |
29 | $|=1; |
30 | |
c9beb3f5 |
31 | my @prgs = (); |
32 | while(<DATA>) { |
33 | if(m/^#{8,}\s*(.*)/) { |
34 | push @prgs, ['', $1]; |
35 | } |
36 | else { |
37 | $prgs[-1][0] .= $_; |
38 | } |
39 | } |
a0d0e21e |
40 | print "1..", scalar @prgs, "\n"; |
41 | |
c9beb3f5 |
42 | my $tmpfile = "misctmp000"; |
a0d0e21e |
43 | 1 while -f ++$tmpfile; |
ed6b3797 |
44 | END { while($tmpfile && unlink $tmpfile){} } |
a0d0e21e |
45 | |
c9beb3f5 |
46 | my $test = 1; |
47 | foreach my $prog (@prgs) { |
48 | my($raw_prog, $name) = @$prog; |
68dc0745 |
49 | |
a0d0e21e |
50 | my $switch; |
c9beb3f5 |
51 | if ($raw_prog =~ s/^\s*(-\w.*)//){ |
fb73857a |
52 | $switch = $1; |
a0d0e21e |
53 | } |
c9beb3f5 |
54 | |
55 | my($prog,$expected) = split(/\nEXPECT\n/, $raw_prog); |
56 | |
648cac19 |
57 | open TEST, ">$tmpfile" or die "Cannot open $tmpfile: $!"; |
c9beb3f5 |
58 | |
59 | # VMS adjustments |
60 | if( $^O eq 'VMS' ) { |
61 | $prog =~ s#/dev/null#NL:#; |
62 | |
63 | # VMS file locking |
64 | $prog =~ s{if \(-e _ and -f _ and -r _\)} |
65 | {if (-e _ and -f _)} |
66 | } |
ed6b3797 |
67 | |
648cac19 |
68 | print TEST $prog, "\n"; |
69 | close TEST or die "Cannot close $tmpfile: $!"; |
70 | |
c9beb3f5 |
71 | my $results; |
68dc0745 |
72 | if ($^O eq 'MSWin32') { |
c9beb3f5 |
73 | $results = `.\\perl -I../lib $switch $tmpfile 2>&1`; |
68dc0745 |
74 | } |
c9beb3f5 |
75 | elsif ($^O eq 'NetWare') { |
76 | $results = `perl -I../lib $switch $tmpfile 2>&1`; |
2986a63f |
77 | } |
68dc0745 |
78 | else { |
c9beb3f5 |
79 | $results = `./perl -I../lib $switch $tmpfile 2>&1`; |
68dc0745 |
80 | } |
c9beb3f5 |
81 | my $status = $?; |
82 | |
83 | # Clean up the results into something a bit more predictable. |
a0d0e21e |
84 | $results =~ s/\n+$//; |
648cac19 |
85 | $results =~ s/at\s+misctmp\d+\s+line/at - line/g; |
86 | $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g; |
c9beb3f5 |
87 | |
88 | # bison says 'parse error' instead of 'syntax error', |
89 | # various yaccs may or may not capitalize 'syntax'. |
2a8ee232 |
90 | $results =~ s/^(syntax|parse) error/syntax error/mig; |
c9beb3f5 |
91 | |
c2f0b9b9 |
92 | $results =~ s/\n\n/\n/ if $^O eq 'VMS'; # pipes double these sometimes |
c9beb3f5 |
93 | |
a0d0e21e |
94 | $expected =~ s/\n+$//; |
c9beb3f5 |
95 | my $ok = $results eq $expected; |
96 | |
97 | unless( $ok ) { |
98 | print STDERR "# PROG: $switch\n$prog\n"; |
99 | print STDERR "# EXPECTED:\n$expected\n"; |
100 | print STDERR "# GOT:\n$results\n"; |
a0d0e21e |
101 | } |
c9beb3f5 |
102 | printf "%sok %d%s\n", ($ok ? '' : "not "), $test, |
103 | length $name ? " - $name" : $name; |
104 | $test++; |
a0d0e21e |
105 | } |
106 | |
107 | __END__ |
2ace3117 |
108 | ######## |
44a8e56a |
109 | $a = ":="; split /($a)/o, "a:=b:=c"; print "@_" |
110 | EXPECT |
111 | a := b := c |
112 | ######## |
36477c24 |
113 | $cusp = ~0 ^ (~0 >> 1); |
85e0ebd8 |
114 | use integer; |
36477c24 |
115 | $, = " "; |
85e0ebd8 |
116 | print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n"; |
36477c24 |
117 | EXPECT |
85e0ebd8 |
118 | 7 0 0 8 ! |
36477c24 |
119 | ######## |
a0d0e21e |
120 | $foo=undef; $foo->go; |
121 | EXPECT |
72b5445b |
122 | Can't call method "go" on an undefined value at - line 1. |
a0d0e21e |
123 | ######## |
124 | BEGIN |
125 | { |
126 | "foo"; |
127 | } |
128 | ######## |
a0d0e21e |
129 | $array[128]=1 |
130 | ######## |
131 | $x=0x0eabcd; print $x->ref; |
132 | EXPECT |
133 | Can't call method "ref" without a package or object reference at - line 1. |
134 | ######## |
648cac19 |
135 | chop ($str .= <DATA>); |
a0d0e21e |
136 | ######## |
137 | close ($banana); |
138 | ######## |
139 | $x=2;$y=3;$x<$y ? $x : $y += 23;print $x; |
140 | EXPECT |
141 | 25 |
142 | ######## |
143 | eval {sub bar {print "In bar";}} |
144 | ######## |
68dc0745 |
145 | system './perl -ne "print if eof" /dev/null' |
a0d0e21e |
146 | ######## |
648cac19 |
147 | chop($file = <DATA>); |
a0d0e21e |
148 | ######## |
149 | package N; |
150 | sub new {my ($obj,$n)=@_; bless \$n} |
151 | $aa=new N 1; |
152 | $aa=12345; |
153 | print $aa; |
154 | EXPECT |
155 | 12345 |
156 | ######## |
157 | %@x=0; |
158 | EXPECT |
f1612b5c |
159 | Can't modify hash dereference in repeat (x) at - line 1, near "0;" |
3fe9a6f1 |
160 | Execution of - aborted due to compilation errors. |
a0d0e21e |
161 | ######## |
162 | $_="foo"; |
163 | printf(STDOUT "%s\n", $_); |
164 | EXPECT |
165 | foo |
166 | ######## |
167 | push(@a, 1, 2, 3,) |
168 | ######## |
169 | quotemeta "" |
170 | ######## |
171 | for ("ABCDE") { |
172 | ⊂ |
173 | s/./&sub($&)/eg; |
174 | print;} |
175 | sub sub {local($_) = @_; |
176 | $_ x 4;} |
177 | EXPECT |
178 | Modification of a read-only value attempted at - line 3. |
179 | ######## |
180 | package FOO;sub new {bless {FOO => BAR}}; |
181 | package main; |
182 | use strict vars; |
183 | my $self = new FOO; |
184 | print $$self{FOO}; |
185 | EXPECT |
186 | BAR |
187 | ######## |
188 | $_="foo"; |
189 | s/.{1}//s; |
190 | print; |
191 | EXPECT |
192 | oo |
193 | ######## |
194 | print scalar ("foo","bar") |
195 | EXPECT |
196 | bar |
197 | ######## |
198 | sub by_number { $a <=> $b; };# inline function for sort below |
199 | $as_ary{0}="a0"; |
200 | @ordered_array=sort by_number keys(%as_ary); |
201 | ######## |
202 | sub NewShell |
203 | { |
204 | local($Host) = @_; |
205 | my($m2) = $#Shells++; |
206 | $Shells[$m2]{HOST} = $Host; |
207 | return $m2; |
208 | } |
209 | |
210 | sub ShowShell |
211 | { |
212 | local($i) = @_; |
213 | } |
214 | |
215 | &ShowShell(&NewShell(beach,Work,"+0+0")); |
216 | &ShowShell(&NewShell(beach,Work,"+0+0")); |
217 | &ShowShell(&NewShell(beach,Work,"+0+0")); |
218 | ######## |
219 | { |
220 | package FAKEARRAY; |
221 | |
222 | sub TIEARRAY |
223 | { print "TIEARRAY @_\n"; |
224 | die "bomb out\n" unless $count ++ ; |
225 | bless ['foo'] |
226 | } |
227 | sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] } |
228 | sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] } |
229 | sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; } |
230 | } |
231 | |
232 | eval 'tie @h, FAKEARRAY, fred' ; |
233 | tie @h, FAKEARRAY, fred ; |
234 | EXPECT |
235 | TIEARRAY FAKEARRAY fred |
236 | TIEARRAY FAKEARRAY fred |
237 | DESTROY |
238 | ######## |
239 | BEGIN { die "phooey\n" } |
240 | EXPECT |
241 | phooey |
242 | BEGIN failed--compilation aborted at - line 1. |
243 | ######## |
244 | BEGIN { 1/$zero } |
245 | EXPECT |
246 | Illegal division by zero at - line 1. |
247 | BEGIN failed--compilation aborted at - line 1. |
248 | ######## |
249 | BEGIN { undef = 0 } |
250 | EXPECT |
251 | Modification of a read-only value attempted at - line 1. |
252 | BEGIN failed--compilation aborted at - line 1. |
a7adf1f0 |
253 | ######## |
254 | { |
255 | package foo; |
256 | sub PRINT { |
257 | shift; |
258 | print join(' ', reverse @_)."\n"; |
259 | } |
46fc3d4c |
260 | sub PRINTF { |
261 | shift; |
262 | my $fmt = shift; |
263 | print sprintf($fmt, @_)."\n"; |
264 | } |
a7adf1f0 |
265 | sub TIEHANDLE { |
266 | bless {}, shift; |
267 | } |
58f51617 |
268 | sub READLINE { |
269 | "Out of inspiration"; |
270 | } |
a7adf1f0 |
271 | sub DESTROY { |
272 | print "and destroyed as well\n"; |
2ae324a7 |
273 | } |
274 | sub READ { |
275 | shift; |
276 | print STDOUT "foo->can(READ)(@_)\n"; |
277 | return 100; |
278 | } |
279 | sub GETC { |
280 | shift; |
281 | print STDOUT "Don't GETC, Get Perl\n"; |
282 | return "a"; |
283 | } |
a7adf1f0 |
284 | } |
285 | { |
286 | local(*FOO); |
287 | tie(*FOO,'foo'); |
288 | print FOO "sentence.", "reversed", "a", "is", "This"; |
58f51617 |
289 | print "-- ", <FOO>, " --\n"; |
2ae324a7 |
290 | my($buf,$len,$offset); |
291 | $buf = "string"; |
292 | $len = 10; $offset = 1; |
293 | read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed"; |
294 | getc(FOO) eq "a" or die "foo->GETC failed"; |
46fc3d4c |
295 | printf "%s is number %d\n", "Perl", 1; |
a7adf1f0 |
296 | } |
297 | EXPECT |
298 | This is a reversed sentence. |
58f51617 |
299 | -- Out of inspiration -- |
2ae324a7 |
300 | foo->can(READ)(string 10 1) |
301 | Don't GETC, Get Perl |
46fc3d4c |
302 | Perl is number 1 |
a7adf1f0 |
303 | and destroyed as well |
a6006777 |
304 | ######## |
305 | my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n" |
306 | EXPECT |
307 | 2 2 2 |
308 | ######## |
8ff950ac |
309 | # used to attach defelem magic to all immortal values, |
8b530633 |
310 | # which made restore of local $_ fail. |
311 | foo(2>1); |
312 | sub foo { bar() for @_; } |
313 | sub bar { local $_; } |
314 | print "ok\n"; |
315 | EXPECT |
316 | ok |
317 | ######## |
a6006777 |
318 | @a = ($a, $b, $c, $d) = (5, 6); |
319 | print "ok\n" |
320 | if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]); |
321 | EXPECT |
322 | ok |
323 | ######## |
324 | print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000); |
325 | EXPECT |
326 | ok |
327 | ######## |
8ebc5c01 |
328 | print "ok\n" if ("\0" lt "\xFF"); |
a6006777 |
329 | EXPECT |
330 | ok |
331 | ######## |
9731f9ce |
332 | open(H,'run/kill_perl.t'); # must be in the 't' directory |
a6006777 |
333 | stat(H); |
334 | print "ok\n" if (-e _ and -f _ and -r _); |
335 | EXPECT |
336 | ok |
337 | ######## |
338 | sub thing { 0 || return qw(now is the time) } |
339 | print thing(), "\n"; |
340 | EXPECT |
341 | nowisthetime |
342 | ######## |
343 | $ren = 'joy'; |
344 | $stimpy = 'happy'; |
345 | { local $main::{ren} = *stimpy; print $ren, ' ' } |
346 | print $ren, "\n"; |
347 | EXPECT |
348 | happy joy |
349 | ######## |
350 | $stimpy = 'happy'; |
351 | { local $main::{ren} = *stimpy; print ${'ren'}, ' ' } |
352 | print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n"; |
353 | EXPECT |
354 | happy joy |
355 | ######## |
356 | package p; |
357 | sub func { print 'really ' unless wantarray; 'p' } |
358 | sub groovy { 'groovy' } |
359 | package main; |
360 | print p::func()->groovy(), "\n" |
361 | EXPECT |
362 | really groovy |
363 | ######## |
d53f8f1c |
364 | @list = ([ 'one', 1 ], [ 'two', 2 ]); |
365 | sub func { $num = shift; (grep $_->[1] == $num, @list)[0] } |
366 | print scalar(map &func($_), 1 .. 3), " ", |
367 | scalar(map scalar &func($_), 1 .. 3), "\n"; |
368 | EXPECT |
369 | 2 3 |
370 | ######## |
44a8e56a |
371 | ($k, $s) = qw(x 0); |
372 | @{$h{$k}} = qw(1 2 4); |
373 | for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) } |
374 | print "bogus\n" unless $s == 7; |
375 | ######## |
376 | my $a = 'outer'; |
377 | eval q[ my $a = 'inner'; eval q[ print "$a " ] ]; |
378 | eval { my $x = 'peace'; eval q[ print "$x\n" ] } |
379 | EXPECT |
380 | inner peace |
774d564b |
381 | ######## |
382 | -w |
383 | $| = 1; |
384 | sub foo { |
385 | print "In foo1\n"; |
386 | eval 'sub foo { print "In foo2\n" }'; |
387 | print "Exiting foo1\n"; |
388 | } |
389 | foo; |
390 | foo; |
391 | EXPECT |
392 | In foo1 |
393 | Subroutine foo redefined at (eval 1) line 1. |
394 | Exiting foo1 |
395 | In foo2 |
396 | ######## |
397 | $s = 0; |
398 | map {#this newline here tickles the bug |
399 | $s += $_} (1,2,4); |
400 | print "eat flaming death\n" unless ($s == 7); |
1ca7b98a |
401 | ######## |
402 | sub foo { local $_ = shift; split; @_ } |
403 | @x = foo(' x y z '); |
404 | print "you die joe!\n" unless "@x" eq 'x y z'; |
c277df42 |
405 | ######## |
406 | /(?{"{"})/ # Check it outside of eval too |
407 | EXPECT |
2cd61cdb |
408 | Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern |
7253e4e3 |
409 | Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1. |
c277df42 |
410 | ######## |
411 | /(?{"{"}})/ # Check it outside of eval too |
412 | EXPECT |
d98d5fff |
413 | Unmatched right curly bracket at (re_eval 1) line 1, at end of line |
c277df42 |
414 | syntax error at (re_eval 1) line 1, near ""{"}" |
2cd61cdb |
415 | Compilation failed in regexp at - line 1. |
0da4822f |
416 | ######## |
ff689196 |
417 | BEGIN { @ARGV = qw(a b c d e) } |
0da4822f |
418 | BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" } |
419 | END { print "end <",shift,">\nargv <@ARGV>\n" } |
420 | INIT { print "init <",shift,">\n" } |
7d30b5c4 |
421 | CHECK { print "check <",shift,">\n" } |
0da4822f |
422 | EXPECT |
ff689196 |
423 | argv <a b c d e> |
0da4822f |
424 | begin <a> |
7d30b5c4 |
425 | check <b> |
ff689196 |
426 | init <c> |
427 | end <d> |
428 | argv <e> |
4599a1de |
429 | ######## |
3500f679 |
430 | -l |
431 | # fdopen from a system descriptor to a system descriptor used to close |
432 | # the former. |
433 | open STDERR, '>&=STDOUT' or die $!; |
75642110 |
434 | select STDOUT; $| = 1; print fileno STDOUT or die $!; |
435 | select STDERR; $| = 1; print fileno STDERR or die $!; |
3500f679 |
436 | EXPECT |
437 | 1 |
438 | 2 |
439 | ######## |
20408e3c |
440 | -w |
441 | sub testme { my $a = "test"; { local $a = "new test"; print $a }} |
442 | EXPECT |
443 | Can't localize lexical variable $a at - line 2. |
444 | ######## |
51ae5c03 |
445 | package X; |
446 | sub ascalar { my $r; bless \$r } |
447 | sub DESTROY { print "destroyed\n" }; |
448 | package main; |
449 | *s = ascalar X; |
450 | EXPECT |
451 | destroyed |
452 | ######## |
453 | package X; |
454 | sub anarray { bless [] } |
455 | sub DESTROY { print "destroyed\n" }; |
456 | package main; |
457 | *a = anarray X; |
458 | EXPECT |
459 | destroyed |
460 | ######## |
461 | package X; |
462 | sub ahash { bless {} } |
463 | sub DESTROY { print "destroyed\n" }; |
464 | package main; |
465 | *h = ahash X; |
466 | EXPECT |
467 | destroyed |
468 | ######## |
469 | package X; |
470 | sub aclosure { my $x; bless sub { ++$x } } |
471 | sub DESTROY { print "destroyed\n" }; |
472 | package main; |
473 | *c = aclosure X; |
474 | EXPECT |
475 | destroyed |
476 | ######## |
477 | package X; |
478 | sub any { bless {} } |
479 | my $f = "FH000"; # just to thwart any future optimisations |
ded8aa31 |
480 | sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r } |
51ae5c03 |
481 | sub DESTROY { print "destroyed\n" } |
482 | package main; |
483 | $x = any X; # to bump sv_objcount. IO objs aren't counted?? |
484 | *f = afh X; |
485 | EXPECT |
486 | destroyed |
487 | destroyed |
488 | ######## |
ebf99b04 |
489 | BEGIN { |
490 | $| = 1; |
491 | $SIG{__WARN__} = sub { |
492 | eval { print $_[0] }; |
493 | die "bar\n"; |
494 | }; |
495 | warn "foo\n"; |
496 | } |
497 | EXPECT |
498 | foo |
499 | bar |
500 | BEGIN failed--compilation aborted at - line 8. |
8feb4e9f |
501 | ######## |
502 | package X; |
503 | @ISA='Y'; |
504 | sub new { |
505 | my $class = shift; |
506 | my $self = { }; |
507 | bless $self, $class; |
508 | my $init = shift; |
509 | $self->foo($init); |
510 | print "new", $init; |
511 | return $self; |
512 | } |
513 | sub DESTROY { |
514 | my $self = shift; |
515 | print "DESTROY", $self->foo; |
516 | } |
517 | package Y; |
518 | sub attribute { |
519 | my $self = shift; |
520 | my $var = shift; |
521 | if (@_ == 0) { |
522 | return $self->{$var}; |
523 | } elsif (@_ == 1) { |
524 | $self->{$var} = shift; |
525 | } |
526 | } |
527 | sub AUTOLOAD { |
528 | $AUTOLOAD =~ /::([^:]+)$/; |
529 | my $method = $1; |
530 | splice @_, 1, 0, $method; |
531 | goto &attribute; |
532 | } |
533 | package main; |
534 | my $x = X->new(1); |
535 | for (2..3) { |
536 | my $y = X->new($_); |
537 | print $y->foo; |
538 | } |
539 | print $x->foo; |
540 | EXPECT |
541 | new1new22DESTROY2new33DESTROY31DESTROY1 |
dfad63ad |
542 | ######## |
543 | re(); |
544 | sub re { |
14455d6c |
545 | my $re = join '', eval 'qr/(??{ $obj->method })/'; |
dfad63ad |
546 | $re; |
547 | } |
548 | EXPECT |
1aff0e91 |
549 | ######## |
550 | use strict; |
551 | my $foo = "ZZZ\n"; |
552 | END { print $foo } |
553 | EXPECT |
554 | ZZZ |
555 | ######## |
556 | eval ' |
557 | use strict; |
558 | my $foo = "ZZZ\n"; |
559 | END { print $foo } |
560 | '; |
561 | EXPECT |
562 | ZZZ |
7399586d |
563 | ######## |
564 | -w |
565 | if (@ARGV) { print "" } |
566 | else { |
567 | if ($x == 0) { print "" } else { print $x } |
568 | } |
569 | EXPECT |
b89fed5f |
570 | Use of uninitialized value in numeric eq (==) at - line 4. |
1d76a5c3 |
571 | ######## |
572 | $x = sub {}; |
573 | foo(); |
574 | sub foo { eval { return }; } |
575 | print "ok\n"; |
576 | EXPECT |
577 | ok |
07447971 |
578 | ######## |
b0f2b690 |
579 | # moved to op/lc.t |
07447971 |
580 | EXPECT |
92d29cee |
581 | ######## |
582 | sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next } |
583 | my $x = "foo"; |
584 | { f } continue { print $x, "\n" } |
585 | EXPECT |
586 | foo |
6a7129a1 |
587 | ######## |
588 | sub C () { 1 } |
589 | sub M { $_[0] = 2; } |
590 | eval "C"; |
591 | M(C); |
592 | EXPECT |
593 | Modification of a read-only value attempted at - line 2. |
00c29ff8 |
594 | ######## |
595 | print qw(ab a\b a\\b); |
596 | EXPECT |
597 | aba\ba\b |
dd8482fc |
598 | ######## |
c71fccf1 |
599 | # lexicals declared after the myeval() definition should not be visible |
600 | # within it |
601 | sub myeval { eval $_[0] } |
602 | my $foo = "ok 2\n"; |
603 | myeval('sub foo { local $foo = "ok 1\n"; print $foo; }'); |
604 | die $@ if $@; |
605 | foo(); |
606 | print $foo; |
607 | EXPECT |
608 | ok 1 |
609 | ok 2 |
610 | ######## |
2090ab20 |
611 | # lexicals outside an eval"" should be visible inside subroutine definitions |
612 | # within it |
613 | eval <<'EOT'; die $@ if $@; |
614 | { |
615 | my $X = "ok\n"; |
616 | eval 'sub Y { print $X }'; die $@ if $@; |
617 | Y(); |
618 | } |
619 | EOT |
620 | EXPECT |
621 | ok |
622 | ######## |
c975facc |
623 | # test that closures generated by eval"" hold on to the CV of the eval"" |
624 | # for their entire lifetime |
625 | $code = eval q[ |
626 | sub { eval '$x = "ok 1\n"'; } |
627 | ]; |
628 | &{$code}(); |
629 | print $x; |
630 | EXPECT |
631 | ok 1 |
632 | ######## |
dd8482fc |
633 | # This test is here instead of pragma/locale.t because |
634 | # the bug depends on in the internal state of the locale |
635 | # settings and pragma/locale messes up that state pretty badly. |
636 | # We need a "fresh run". |
c9f931b8 |
637 | BEGIN { |
638 | eval { require POSIX }; |
639 | if ($@) { |
640 | exit(0); # running minitest? |
641 | } |
642 | } |
dd8482fc |
643 | use Config; |
644 | my $have_setlocale = $Config{d_setlocale} eq 'define'; |
dd8482fc |
645 | $have_setlocale = 0 if $@; |
646 | # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1" |
647 | # and mingw32 uses said silly CRT |
2986a63f |
648 | $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i); |
dd8482fc |
649 | exit(0) unless $have_setlocale; |
650 | my @locales; |
651 | if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a|")) { |
652 | while(<LOCALES>) { |
653 | chomp; |
654 | push(@locales, $_); |
655 | } |
656 | close(LOCALES); |
657 | } |
658 | exit(0) unless @locales; |
659 | for (@locales) { |
660 | use POSIX qw(locale_h); |
661 | use locale; |
88e7acd2 |
662 | setlocale(LC_NUMERIC, $_) or next; |
dd8482fc |
663 | my $s = sprintf "%g %g", 3.1, 3.1; |
664 | next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/; |
665 | print "$_ $s\n"; |
666 | } |
667 | EXPECT |
b927783e |
668 | ######## |
669 | die qr(x) |
670 | EXPECT |
671 | (?-xism:x) at - line 1. |
672 | ######## |
7ef822cd |
673 | # 20001210.003 mjd@plover.com |
674 | format REMITOUT_TOP = |
675 | FOO |
676 | . |
677 | |
678 | format REMITOUT = |
679 | BAR |
680 | . |
681 | |
682 | # This loop causes a segv in 5.6.0 |
683 | for $lineno (1..61) { |
684 | write REMITOUT; |
685 | } |
686 | |
687 | print "It's OK!"; |
688 | EXPECT |
689 | It's OK! |
cb55de95 |
690 | ######## |
691 | # Inaba Hiroto |
692 | reset; |
693 | if (0) { |
694 | if ("" =~ //) { |
695 | } |
696 | } |
697 | ######## |
698 | # Nicholas Clark |
699 | $ENV{TERM} = 0; |
700 | reset; |
701 | // if 0; |
702 | ######## |
703 | # Vadim Konovalov |
704 | use strict; |
705 | sub new_pmop($) { |
706 | my $pm = shift; |
707 | return eval "sub {shift=~/$pm/}"; |
708 | } |
709 | new_pmop "abcdef"; reset; |
710 | new_pmop "abcdef"; reset; |
711 | new_pmop "abcdef"; reset; |
712 | new_pmop "abcdef"; reset; |
880649cd |
713 | ######## |
714 | # David Dyck |
715 | # coredump in 5.7.1 |
716 | close STDERR; die; |
717 | EXPECT |
dba9804b |
718 | ######## |
99799961 |
719 | -w |
720 | "x" =~ /(\G?x)?/; # core dump in 20000716.007 |
721 | EXPECT |
722 | Quantifier unexpected on zero-length expression in regex; marked by <-- HERE in m/(\G?x)? <-- HERE / at - line 2. |
723 | ######## |
dba9804b |
724 | # Bug 20010515.004 |
725 | my @h = 1 .. 10; |
726 | bad(@h); |
727 | sub bad { |
728 | undef @h; |
729 | print "O"; |
730 | print for @_; |
731 | print "K"; |
732 | } |
733 | EXPECT |
734 | OK |
97b9a4cb |
735 | ######## |
736 | # Bug 20010506.041 |
737 | "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n"; |
738 | EXPECT |
739 | ok |
0b490c9c |
740 | ######## |
741 | # Bug 20010422.005 |
742 | {s//${}/; //} |
743 | EXPECT |
2172ddaf |
744 | syntax error at - line 2, near "${}" |
0b490c9c |
745 | Execution of - aborted due to compilation errors. |
585602fa |
746 | ######## |
747 | # Bug 20010528.007 |
748 | "\x{" |
749 | EXPECT |
750 | Missing right brace on \x{} at - line 2, within string |
751 | Execution of - aborted due to compilation errors. |
08b362fd |
752 | ######## |
753 | my $foo = Bar->new(); |
754 | my @dst; |
755 | END { |
756 | ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/; |
757 | print $_, "\n"; |
758 | } |
759 | package Bar; |
760 | sub new { |
761 | my Bar $self = bless [], Bar; |
762 | eval '$self'; |
763 | return $self; |
764 | } |
765 | sub DESTROY { |
766 | push @dst, "$_[0]"; |
767 | } |
768 | EXPECT |
769 | Bar=ARRAY(0x...) |
1f96ff2a |
770 | ######## |
6ee35fb7 |
771 | # 20010407.008 sprintf removes utf8-ness |
772 | $a = sprintf "\x{1234}"; |
773 | printf "%x %d\n", unpack("U*", $a), length($a); |
9efebafb |
774 | $a = sprintf "%s", "\x{5678}"; |
775 | printf "%x %d\n", unpack("U*", $a), length($a); |
6ee35fb7 |
776 | $a = sprintf "\x{1234}%s", "\x{5678}"; |
777 | printf "%x %x %d\n", unpack("U*", $a), length($a); |
778 | EXPECT |
779 | 1234 1 |
9efebafb |
780 | 5678 1 |
6ee35fb7 |
781 | 1234 5678 2 |
7c8c5f1c |
782 | ######## found by Markov chain stress testing |
1f96ff2a |
783 | eval "a.b.c.d.e.f;sub" |
784 | EXPECT |
c9beb3f5 |
785 | |
786 | ######## perlbug ID 20010831.001 |
787 | ($a, b) = (1, 2); |
788 | EXPECT |
789 | Can't modify constant item in list assignment at - line 1, near ");" |
790 | Execution of - aborted due to compilation errors. |