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;
93 # some tests will trigger VMS messages that won't be expected
94 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
96 # pipes double these sometimes
97 $results =~ s/\n\n/\n/g;
100 $expected =~ s/\n+$//;
101 my $ok = $results eq $expected;
104 print STDERR "# PROG: $switch\n$prog\n";
105 print STDERR "# EXPECTED:\n$expected\n";
106 print STDERR "# GOT:\n$results\n";
108 printf "%sok %d%s\n", ($ok ? '' : "not "), $test,
109 length $name ? " - $name" : $name;
115 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
119 $cusp = ~0 ^ (~0 >> 1);
122 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
126 $foo=undef; $foo->go;
128 Can't call method "go" on an undefined value at - line 1.
137 $x=0x0eabcd; print $x->ref;
139 Can't call method "ref" without a package or object reference at - line 1.
141 chop ($str .= <DATA>);
145 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
149 eval {sub bar {print "In bar";}}
151 system './perl -ne "print if eof" /dev/null'
153 chop($file = <DATA>);
156 sub new {my ($obj,$n)=@_; bless \$n}
165 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
166 Execution of - aborted due to compilation errors.
169 printf(STDOUT "%s\n", $_);
181 sub sub {local($_) = @_;
184 Modification of a read-only value attempted at - line 3.
186 package FOO;sub new {bless {FOO => BAR}};
200 print scalar ("foo","bar")
204 sub by_number { $a <=> $b; };# inline function for sort below
206 @ordered_array=sort by_number keys(%as_ary);
211 my($m2) = $#Shells++;
212 $Shells[$m2]{HOST} = $Host;
221 &ShowShell(&NewShell(beach,Work,"+0+0"));
222 &ShowShell(&NewShell(beach,Work,"+0+0"));
223 &ShowShell(&NewShell(beach,Work,"+0+0"));
229 { print "TIEARRAY @_\n";
230 die "bomb out\n" unless $count ++ ;
233 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
234 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
235 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
238 eval 'tie @h, FAKEARRAY, fred' ;
239 tie @h, FAKEARRAY, fred ;
241 TIEARRAY FAKEARRAY fred
242 TIEARRAY FAKEARRAY fred
245 BEGIN { die "phooey\n" }
248 BEGIN failed--compilation aborted at - line 1.
252 Illegal division by zero at - line 1.
253 BEGIN failed--compilation aborted at - line 1.
257 Modification of a read-only value attempted at - line 1.
258 BEGIN failed--compilation aborted at - line 1.
264 print join(' ', reverse @_)."\n";
269 print sprintf($fmt, @_)."\n";
275 "Out of inspiration";
278 print "and destroyed as well\n";
282 print STDOUT "foo->can(READ)(@_)\n";
287 print STDOUT "Don't GETC, Get Perl\n";
294 print FOO "sentence.", "reversed", "a", "is", "This";
295 print "-- ", <FOO>, " --\n";
296 my($buf,$len,$offset);
298 $len = 10; $offset = 1;
299 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
300 getc(FOO) eq "a" or die "foo->GETC failed";
301 printf "%s is number %d\n", "Perl", 1;
304 This is a reversed sentence.
305 -- Out of inspiration --
306 foo->can(READ)(string 10 1)
309 and destroyed as well
311 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
315 # used to attach defelem magic to all immortal values,
316 # which made restore of local $_ fail.
318 sub foo { bar() for @_; }
319 sub bar { local $_; }
324 @a = ($a, $b, $c, $d) = (5, 6);
326 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
330 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
334 print "ok\n" if ("\0" lt "\xFF");
338 open(H,'run/kill_perl.t'); # must be in the 't' directory
340 print "ok\n" if (-e _ and -f _ and -r _);
344 sub thing { 0 || return qw(now is the time) }
351 { local $main::{ren} = *stimpy; print $ren, ' ' }
357 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
358 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
363 sub func { print 'really ' unless wantarray; 'p' }
364 sub groovy { 'groovy' }
366 print p::func()->groovy(), "\n"
370 @list = ([ 'one', 1 ], [ 'two', 2 ]);
371 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
372 print scalar(map &func($_), 1 .. 3), " ",
373 scalar(map scalar &func($_), 1 .. 3), "\n";
378 @{$h{$k}} = qw(1 2 4);
379 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
380 print "bogus\n" unless $s == 7;
383 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
384 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
392 eval 'sub foo { print "In foo2\n" }';
393 print "Exiting foo1\n";
399 Subroutine foo redefined at (eval 1) line 1.
404 map {#this newline here tickles the bug
406 print "eat flaming death\n" unless ($s == 7);
408 sub foo { local $_ = shift; split; @_ }
410 print "you die joe!\n" unless "@x" eq 'x y z';
412 /(?{"{"})/ # Check it outside of eval too
414 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
415 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
417 /(?{"{"}})/ # Check it outside of eval too
419 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
420 syntax error at (re_eval 1) line 1, near ""{"}"
421 Compilation failed in regexp at - line 1.
423 BEGIN { @ARGV = qw(a b c d e) }
424 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
425 END { print "end <",shift,">\nargv <@ARGV>\n" }
426 INIT { print "init <",shift,">\n" }
427 CHECK { print "check <",shift,">\n" }
437 # fdopen from a system descriptor to a system descriptor used to close
439 open STDERR, '>&=STDOUT' or die $!;
440 select STDOUT; $| = 1; print fileno STDOUT or die $!;
441 select STDERR; $| = 1; print fileno STDERR or die $!;
447 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
449 Can't localize lexical variable $a at - line 2.
452 sub ascalar { my $r; bless \$r }
453 sub DESTROY { print "destroyed\n" };
460 sub anarray { bless [] }
461 sub DESTROY { print "destroyed\n" };
468 sub ahash { bless {} }
469 sub DESTROY { print "destroyed\n" };
476 sub aclosure { my $x; bless sub { ++$x } }
477 sub DESTROY { print "destroyed\n" };
485 my $f = "FH000"; # just to thwart any future optimisations
486 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
487 sub DESTROY { print "destroyed\n" }
489 $x = any X; # to bump sv_objcount. IO objs aren't counted??
497 $SIG{__WARN__} = sub {
498 eval { print $_[0] };
506 BEGIN failed--compilation aborted at - line 8.
521 print "DESTROY", $self->foo;
528 return $self->{$var};
530 $self->{$var} = shift;
534 $AUTOLOAD =~ /::([^:]+)$/;
536 splice @_, 1, 0, $method;
547 new1new22DESTROY2new33DESTROY31DESTROY1
551 my $re = join '', eval 'qr/(??{ $obj->method })/';
571 if (@ARGV) { print "" }
573 if ($x == 0) { print "" } else { print $x }
576 Use of uninitialized value in numeric eq (==) at - line 4.
580 sub foo { eval { return }; }
588 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
590 { f } continue { print $x, "\n" }
599 Modification of a read-only value attempted at - line 2.
601 print qw(ab a\b a\\b);
605 # lexicals declared after the myeval() definition should not be visible
607 sub myeval { eval $_[0] }
609 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
617 # lexicals outside an eval"" should be visible inside subroutine definitions
619 eval <<'EOT'; die $@ if $@;
622 eval 'sub Y { print $X }'; die $@ if $@;
629 # test that closures generated by eval"" hold on to the CV of the eval""
630 # for their entire lifetime
632 sub { eval '$x = "ok 1\n"'; }
639 # This test is here instead of pragma/locale.t because
640 # the bug depends on in the internal state of the locale
641 # settings and pragma/locale messes up that state pretty badly.
642 # We need a "fresh run".
644 eval { require POSIX };
646 exit(0); # running minitest?
650 my $have_setlocale = $Config{d_setlocale} eq 'define';
651 $have_setlocale = 0 if $@;
652 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
653 # and mingw32 uses said silly CRT
654 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
655 exit(0) unless $have_setlocale;
657 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a|")) {
664 exit(0) unless @locales;
666 use POSIX qw(locale_h);
668 setlocale(LC_NUMERIC, $_) or next;
669 my $s = sprintf "%g %g", 3.1, 3.1;
670 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
677 (?-xism:x) at - line 1.
679 # 20001210.003 mjd@plover.com
680 format REMITOUT_TOP =
688 # This loop causes a segv in 5.6.0
689 for $lineno (1..61) {
713 return eval "sub {shift=~/$pm/}";
715 new_pmop "abcdef"; reset;
716 new_pmop "abcdef"; reset;
717 new_pmop "abcdef"; reset;
718 new_pmop "abcdef"; reset;
726 "x" =~ /(\G?x)?/; # core dump in 20000716.007
741 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
748 syntax error at - line 2, near "${}"
749 Execution of - aborted due to compilation errors.
754 Missing right brace on \x{} at - line 2, within string
755 Execution of - aborted due to compilation errors.
757 my $foo = Bar->new();
760 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
765 my Bar $self = bless [], Bar;
775 # 20010407.008 sprintf removes utf8-ness
776 $a = sprintf "\x{1234}";
777 printf "%x %d\n", unpack("U*", $a), length($a);
778 $a = sprintf "%s", "\x{5678}";
779 printf "%x %d\n", unpack("U*", $a), length($a);
780 $a = sprintf "\x{1234}%s", "\x{5678}";
781 printf "%x %x %d\n", unpack("U*", $a), length($a);
786 ######## found by Markov chain stress testing
787 eval "a.b.c.d.e.f;sub"
790 ######## perlbug ID 20010831.001
793 Can't modify constant item in list assignment at - line 1, near ");"
794 Execution of - aborted due to compilation errors.
795 ######## tying a bareword causes a segfault in 5.6.1
798 Can't modify constant item in tie at - line 1, near ""Foo";"
799 Execution of - aborted due to compilation errors.
800 ######## undefing constant causes a segfault in 5.6.1 [ID 20010906.019]
803 Can't modify constant item in undef operator at - line 1, near "foo;"
804 Execution of - aborted due to compilation errors.