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
7 # New tests are added to the bottom. For example.
9 # ######## perlbug ID 20020831.001
12 # Can't modify constant item in list assignment - at line 1
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
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.
33 if(m/^#{8,}\s*(.*)/) {
40 print "1..", scalar @prgs, "\n";
42 my $tmpfile = "misctmp000";
43 1 while -f ++$tmpfile;
44 END { while($tmpfile && unlink $tmpfile){} }
47 foreach my $prog (@prgs) {
48 my($raw_prog, $name) = @$prog;
51 if ($raw_prog =~ s/^\s*(-\w.*)//){
55 my($prog,$expected) = split(/\nEXPECT\n/, $raw_prog);
57 open TEST, ">$tmpfile" or die "Cannot open $tmpfile: $!";
61 $prog =~ s#/dev/null#NL:#;
64 $prog =~ s{if \(-e _ and -f _ and -r _\)}
68 print TEST $prog, "\n";
69 close TEST or die "Cannot close $tmpfile: $!";
72 if ($^O eq 'MSWin32') {
73 $results = `.\\perl -I../lib $switch $tmpfile 2>&1`;
75 elsif ($^O eq 'NetWare') {
76 $results = `perl -I../lib $switch $tmpfile 2>&1`;
79 $results = `./perl -I../lib $switch $tmpfile 2>&1`;
83 # Clean up the results into something a bit more predictable.
85 $results =~ s/at\s+misctmp\d+\s+line/at - line/g;
86 $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g;
88 # bison says 'parse error' instead of 'syntax error',
89 # various yaccs may or may not capitalize 'syntax'.
90 $results =~ s/^(syntax|parse) error/syntax error/mig;
92 $results =~ s/\n\n/\n/ if $^O eq 'VMS'; # pipes double these sometimes
94 $expected =~ s/\n+$//;
95 my $ok = $results eq $expected;
98 print STDERR "# PROG: $switch\n$prog\n";
99 print STDERR "# EXPECTED:\n$expected\n";
100 print STDERR "# GOT:\n$results\n";
102 printf "%sok %d%s\n", ($ok ? '' : "not "), $test,
103 length $name ? " - $name" : $name;
109 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
113 $cusp = ~0 ^ (~0 >> 1);
116 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
120 $foo=undef; $foo->go;
122 Can't call method "go" on an undefined value at - line 1.
131 $x=0x0eabcd; print $x->ref;
133 Can't call method "ref" without a package or object reference at - line 1.
135 chop ($str .= <DATA>);
139 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
143 eval {sub bar {print "In bar";}}
145 system './perl -ne "print if eof" /dev/null'
147 chop($file = <DATA>);
150 sub new {my ($obj,$n)=@_; bless \$n}
159 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
160 Execution of - aborted due to compilation errors.
163 printf(STDOUT "%s\n", $_);
175 sub sub {local($_) = @_;
178 Modification of a read-only value attempted at - line 3.
180 package FOO;sub new {bless {FOO => BAR}};
194 print scalar ("foo","bar")
198 sub by_number { $a <=> $b; };# inline function for sort below
200 @ordered_array=sort by_number keys(%as_ary);
205 my($m2) = $#Shells++;
206 $Shells[$m2]{HOST} = $Host;
215 &ShowShell(&NewShell(beach,Work,"+0+0"));
216 &ShowShell(&NewShell(beach,Work,"+0+0"));
217 &ShowShell(&NewShell(beach,Work,"+0+0"));
223 { print "TIEARRAY @_\n";
224 die "bomb out\n" unless $count ++ ;
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]}; }
232 eval 'tie @h, FAKEARRAY, fred' ;
233 tie @h, FAKEARRAY, fred ;
235 TIEARRAY FAKEARRAY fred
236 TIEARRAY FAKEARRAY fred
239 BEGIN { die "phooey\n" }
242 BEGIN failed--compilation aborted at - line 1.
246 Illegal division by zero at - line 1.
247 BEGIN failed--compilation aborted at - line 1.
251 Modification of a read-only value attempted at - line 1.
252 BEGIN failed--compilation aborted at - line 1.
258 print join(' ', reverse @_)."\n";
263 print sprintf($fmt, @_)."\n";
269 "Out of inspiration";
272 print "and destroyed as well\n";
276 print STDOUT "foo->can(READ)(@_)\n";
281 print STDOUT "Don't GETC, Get Perl\n";
288 print FOO "sentence.", "reversed", "a", "is", "This";
289 print "-- ", <FOO>, " --\n";
290 my($buf,$len,$offset);
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";
295 printf "%s is number %d\n", "Perl", 1;
298 This is a reversed sentence.
299 -- Out of inspiration --
300 foo->can(READ)(string 10 1)
303 and destroyed as well
305 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
309 # used to attach defelem magic to all immortal values,
310 # which made restore of local $_ fail.
312 sub foo { bar() for @_; }
313 sub bar { local $_; }
318 @a = ($a, $b, $c, $d) = (5, 6);
320 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
324 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
328 print "ok\n" if ("\0" lt "\xFF");
332 open(H,'run/kill_perl.t'); # must be in the 't' directory
334 print "ok\n" if (-e _ and -f _ and -r _);
338 sub thing { 0 || return qw(now is the time) }
345 { local $main::{ren} = *stimpy; print $ren, ' ' }
351 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
352 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
357 sub func { print 'really ' unless wantarray; 'p' }
358 sub groovy { 'groovy' }
360 print p::func()->groovy(), "\n"
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";
372 @{$h{$k}} = qw(1 2 4);
373 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
374 print "bogus\n" unless $s == 7;
377 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
378 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
386 eval 'sub foo { print "In foo2\n" }';
387 print "Exiting foo1\n";
393 Subroutine foo redefined at (eval 1) line 1.
398 map {#this newline here tickles the bug
400 print "eat flaming death\n" unless ($s == 7);
402 sub foo { local $_ = shift; split; @_ }
404 print "you die joe!\n" unless "@x" eq 'x y z';
406 /(?{"{"})/ # Check it outside of eval too
408 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
409 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
411 /(?{"{"}})/ # Check it outside of eval too
413 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
414 syntax error at (re_eval 1) line 1, near ""{"}"
415 Compilation failed in regexp at - line 1.
417 BEGIN { @ARGV = qw(a b c d e) }
418 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
419 END { print "end <",shift,">\nargv <@ARGV>\n" }
420 INIT { print "init <",shift,">\n" }
421 CHECK { print "check <",shift,">\n" }
431 # fdopen from a system descriptor to a system descriptor used to close
433 open STDERR, '>&=STDOUT' or die $!;
434 select STDOUT; $| = 1; print fileno STDOUT or die $!;
435 select STDERR; $| = 1; print fileno STDERR or die $!;
441 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
443 Can't localize lexical variable $a at - line 2.
446 sub ascalar { my $r; bless \$r }
447 sub DESTROY { print "destroyed\n" };
454 sub anarray { bless [] }
455 sub DESTROY { print "destroyed\n" };
462 sub ahash { bless {} }
463 sub DESTROY { print "destroyed\n" };
470 sub aclosure { my $x; bless sub { ++$x } }
471 sub DESTROY { print "destroyed\n" };
479 my $f = "FH000"; # just to thwart any future optimisations
480 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
481 sub DESTROY { print "destroyed\n" }
483 $x = any X; # to bump sv_objcount. IO objs aren't counted??
491 $SIG{__WARN__} = sub {
492 eval { print $_[0] };
500 BEGIN failed--compilation aborted at - line 8.
515 print "DESTROY", $self->foo;
522 return $self->{$var};
524 $self->{$var} = shift;
528 $AUTOLOAD =~ /::([^:]+)$/;
530 splice @_, 1, 0, $method;
541 new1new22DESTROY2new33DESTROY31DESTROY1
545 my $re = join '', eval 'qr/(??{ $obj->method })/';
565 if (@ARGV) { print "" }
567 if ($x == 0) { print "" } else { print $x }
570 Use of uninitialized value in numeric eq (==) at - line 4.
574 sub foo { eval { return }; }
582 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
584 { f } continue { print $x, "\n" }
593 Modification of a read-only value attempted at - line 2.
595 print qw(ab a\b a\\b);
599 # lexicals declared after the myeval() definition should not be visible
601 sub myeval { eval $_[0] }
603 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
611 # lexicals outside an eval"" should be visible inside subroutine definitions
613 eval <<'EOT'; die $@ if $@;
616 eval 'sub Y { print $X }'; die $@ if $@;
623 # test that closures generated by eval"" hold on to the CV of the eval""
624 # for their entire lifetime
626 sub { eval '$x = "ok 1\n"'; }
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".
638 eval { require POSIX };
640 exit(0); # running minitest?
644 my $have_setlocale = $Config{d_setlocale} eq 'define';
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
648 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
649 exit(0) unless $have_setlocale;
651 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a|")) {
658 exit(0) unless @locales;
660 use POSIX qw(locale_h);
662 setlocale(LC_NUMERIC, $_) or next;
663 my $s = sprintf "%g %g", 3.1, 3.1;
664 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
671 (?-xism:x) at - line 1.
673 # 20001210.003 mjd@plover.com
674 format REMITOUT_TOP =
682 # This loop causes a segv in 5.6.0
683 for $lineno (1..61) {
707 return eval "sub {shift=~/$pm/}";
709 new_pmop "abcdef"; reset;
710 new_pmop "abcdef"; reset;
711 new_pmop "abcdef"; reset;
712 new_pmop "abcdef"; reset;
720 "x" =~ /(\G?x)?/; # core dump in 20000716.007
722 Quantifier unexpected on zero-length expression in regex; marked by <-- HERE in m/(\G?x)? <-- HERE / at - line 2.
737 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
744 syntax error at - line 2, near "${}"
745 Execution of - aborted due to compilation errors.
750 Missing right brace on \x{} at - line 2, within string
751 Execution of - aborted due to compilation errors.
753 my $foo = Bar->new();
756 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
761 my Bar $self = bless [], Bar;
771 # 20010407.008 sprintf removes utf8-ness
772 $a = sprintf "\x{1234}";
773 printf "%x %d\n", unpack("U*", $a), length($a);
774 $a = sprintf "%s", "\x{5678}";
775 printf "%x %d\n", unpack("U*", $a), length($a);
776 $a = sprintf "\x{1234}%s", "\x{5678}";
777 printf "%x %x %d\n", unpack("U*", $a), length($a);
782 ######## found by Markov chain stress testing
783 eval "a.b.c.d.e.f;sub"
786 ######## perlbug ID 20010831.001
789 Can't modify constant item in list assignment at - line 1, near ");"
790 Execution of - aborted due to compilation errors.
791 ######## tying a bareword causes a segfault in 5.6.1
794 Can't modify constant item in tie at - line 1, near ""Foo";"
795 Execution of - aborted due to compilation errors.