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`;
78 elsif ($^O eq 'MacOS') {
79 $results = `$^X -I::lib -MMac::err=unix $switch $tmpfile`;
82 $results = `./perl "-I../lib" $switch $tmpfile 2>&1`;
86 # Clean up the results into something a bit more predictable.
88 $results =~ s/at\s+misctmp\d+\s+line/at - line/g;
89 $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g;
91 # bison says 'parse error' instead of 'syntax error',
92 # various yaccs may or may not capitalize 'syntax'.
93 $results =~ s/^(syntax|parse) error/syntax error/mig;
96 # some tests will trigger VMS messages that won't be expected
97 $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
99 # pipes double these sometimes
100 $results =~ s/\n\n/\n/g;
103 $expected =~ s/\n+$//;
104 my $ok = $results eq $expected;
107 print STDERR "# PROG: $switch\n$prog\n";
108 print STDERR "# EXPECTED:\n$expected\n";
109 print STDERR "# GOT:\n$results\n";
111 printf "%sok %d%s\n", ($ok ? '' : "not "), $test,
112 length $name ? " - $name" : $name;
118 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
122 $cusp = ~0 ^ (~0 >> 1);
125 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
129 $foo=undef; $foo->go;
131 Can't call method "go" on an undefined value at - line 1.
140 $x=0x0eabcd; print $x->ref;
142 Can't call method "ref" without a package or object reference at - line 1.
144 chop ($str .= <DATA>);
148 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
152 eval {sub bar {print "In bar";}}
154 system './perl -ne "print if eof" /dev/null'
156 chop($file = <DATA>);
159 sub new {my ($obj,$n)=@_; bless \$n}
168 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
169 Execution of - aborted due to compilation errors.
172 printf(STDOUT "%s\n", $_);
184 sub sub {local($_) = @_;
187 Modification of a read-only value attempted at - line 3.
189 package FOO;sub new {bless {FOO => BAR}};
203 print scalar ("foo","bar")
207 sub by_number { $a <=> $b; };# inline function for sort below
209 @ordered_array=sort by_number keys(%as_ary);
214 my($m2) = $#Shells++;
215 $Shells[$m2]{HOST} = $Host;
224 &ShowShell(&NewShell(beach,Work,"+0+0"));
225 &ShowShell(&NewShell(beach,Work,"+0+0"));
226 &ShowShell(&NewShell(beach,Work,"+0+0"));
232 { print "TIEARRAY @_\n";
233 die "bomb out\n" unless $count ++ ;
236 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
237 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
238 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
241 eval 'tie @h, FAKEARRAY, fred' ;
242 tie @h, FAKEARRAY, fred ;
244 TIEARRAY FAKEARRAY fred
245 TIEARRAY FAKEARRAY fred
248 BEGIN { die "phooey\n" }
251 BEGIN failed--compilation aborted at - line 1.
255 Illegal division by zero at - line 1.
256 BEGIN failed--compilation aborted at - line 1.
260 Modification of a read-only value attempted at - line 1.
261 BEGIN failed--compilation aborted at - line 1.
267 print join(' ', reverse @_)."\n";
272 print sprintf($fmt, @_)."\n";
278 "Out of inspiration";
281 print "and destroyed as well\n";
285 print STDOUT "foo->can(READ)(@_)\n";
290 print STDOUT "Don't GETC, Get Perl\n";
297 print FOO "sentence.", "reversed", "a", "is", "This";
298 print "-- ", <FOO>, " --\n";
299 my($buf,$len,$offset);
301 $len = 10; $offset = 1;
302 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
303 getc(FOO) eq "a" or die "foo->GETC failed";
304 printf "%s is number %d\n", "Perl", 1;
307 This is a reversed sentence.
308 -- Out of inspiration --
309 foo->can(READ)(string 10 1)
312 and destroyed as well
314 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
318 # used to attach defelem magic to all immortal values,
319 # which made restore of local $_ fail.
321 sub foo { bar() for @_; }
322 sub bar { local $_; }
327 @a = ($a, $b, $c, $d) = (5, 6);
329 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
333 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
337 print "ok\n" if ("\0" lt "\xFF");
341 open(H,'run/kill_perl.t'); # must be in the 't' directory
343 print "ok\n" if (-e _ and -f _ and -r _);
347 sub thing { 0 || return qw(now is the time) }
354 { local $main::{ren} = *stimpy; print $ren, ' ' }
360 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
361 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
366 sub func { print 'really ' unless wantarray; 'p' }
367 sub groovy { 'groovy' }
369 print p::func()->groovy(), "\n"
373 @list = ([ 'one', 1 ], [ 'two', 2 ]);
374 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
375 print scalar(map &func($_), 1 .. 3), " ",
376 scalar(map scalar &func($_), 1 .. 3), "\n";
381 @{$h{$k}} = qw(1 2 4);
382 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
383 print "bogus\n" unless $s == 7;
386 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
387 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
395 eval 'sub foo { print "In foo2\n" }';
396 print "Exiting foo1\n";
402 Subroutine foo redefined at (eval 1) line 1.
407 map {#this newline here tickles the bug
409 print "eat flaming death\n" unless ($s == 7);
411 sub foo { local $_ = shift; split; @_ }
413 print "you die joe!\n" unless "@x" eq 'x y z';
415 /(?{"{"})/ # Check it outside of eval too
417 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
418 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
420 /(?{"{"}})/ # Check it outside of eval too
422 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
423 syntax error at (re_eval 1) line 1, near ""{"}"
424 Compilation failed in regexp at - line 1.
426 BEGIN { @ARGV = qw(a b c d e) }
427 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
428 END { print "end <",shift,">\nargv <@ARGV>\n" }
429 INIT { print "init <",shift,">\n" }
430 CHECK { print "check <",shift,">\n" }
440 # fdopen from a system descriptor to a system descriptor used to close
442 open STDERR, '>&=STDOUT' or die $!;
443 select STDOUT; $| = 1; print fileno STDOUT or die $!;
444 select STDERR; $| = 1; print fileno STDERR or die $!;
450 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
452 Can't localize lexical variable $a at - line 2.
455 sub ascalar { my $r; bless \$r }
456 sub DESTROY { print "destroyed\n" };
463 sub anarray { bless [] }
464 sub DESTROY { print "destroyed\n" };
471 sub ahash { bless {} }
472 sub DESTROY { print "destroyed\n" };
479 sub aclosure { my $x; bless sub { ++$x } }
480 sub DESTROY { print "destroyed\n" };
488 my $f = "FH000"; # just to thwart any future optimisations
489 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
490 sub DESTROY { print "destroyed\n" }
492 $x = any X; # to bump sv_objcount. IO objs aren't counted??
500 $SIG{__WARN__} = sub {
501 eval { print $_[0] };
509 BEGIN failed--compilation aborted at - line 8.
524 print "DESTROY", $self->foo;
531 return $self->{$var};
533 $self->{$var} = shift;
537 $AUTOLOAD =~ /::([^:]+)$/;
539 splice @_, 1, 0, $method;
550 new1new22DESTROY2new33DESTROY31DESTROY1
554 my $re = join '', eval 'qr/(??{ $obj->method })/';
574 if (@ARGV) { print "" }
576 if ($x == 0) { print "" } else { print $x }
579 Use of uninitialized value in numeric eq (==) at - line 4.
583 sub foo { eval { return }; }
591 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
593 { f } continue { print $x, "\n" }
602 Modification of a read-only value attempted at - line 2.
604 print qw(ab a\b a\\b);
608 # lexicals declared after the myeval() definition should not be visible
610 sub myeval { eval $_[0] }
612 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
620 # lexicals outside an eval"" should be visible inside subroutine definitions
622 eval <<'EOT'; die $@ if $@;
625 eval 'sub Y { print $X }'; die $@ if $@;
632 # This test is here instead of pragma/locale.t because
633 # the bug depends on in the internal state of the locale
634 # settings and pragma/locale messes up that state pretty badly.
635 # We need a "fresh run".
637 eval { require POSIX };
639 exit(0); # running minitest?
643 my $have_setlocale = $Config{d_setlocale} eq 'define';
644 $have_setlocale = 0 if $@;
645 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
646 # and mingw32 uses said silly CRT
647 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
648 exit(0) unless $have_setlocale;
650 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a|")) {
657 exit(0) unless @locales;
659 use POSIX qw(locale_h);
661 setlocale(LC_NUMERIC, $_) or next;
662 my $s = sprintf "%g %g", 3.1, 3.1;
663 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
670 (?-xism:x) at - line 1.
672 # 20001210.003 mjd@plover.com
673 format REMITOUT_TOP =
681 # This loop causes a segv in 5.6.0
682 for $lineno (1..61) {
706 return eval "sub {shift=~/$pm/}";
708 new_pmop "abcdef"; reset;
709 new_pmop "abcdef"; reset;
710 new_pmop "abcdef"; reset;
711 new_pmop "abcdef"; reset;
719 "x" =~ /(\G?x)?/; # core dump in 20000716.007
734 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
741 syntax error at - line 2, near "${}"
742 Execution of - aborted due to compilation errors.
747 Missing right brace on \x{} at - line 2, within string
748 Execution of - aborted due to compilation errors.
750 my $foo = Bar->new();
753 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
758 my Bar $self = bless [], Bar;
768 # 20010407.008 sprintf removes utf8-ness
769 $a = sprintf "\x{1234}";
770 printf "%x %d\n", unpack("U*", $a), length($a);
771 $a = sprintf "%s", "\x{5678}";
772 printf "%x %d\n", unpack("U*", $a), length($a);
773 $a = sprintf "\x{1234}%s", "\x{5678}";
774 printf "%x %x %d\n", unpack("U*", $a), length($a);
779 ######## found by Markov chain stress testing
780 eval "a.b.c.d.e.f;sub"
783 ######## perlbug ID 20010831.001
786 Can't modify constant item in list assignment at - line 1, near ");"
787 Execution of - aborted due to compilation errors.
788 ######## tying a bareword causes a segfault in 5.6.1
791 Can't modify constant item in tie at - line 1, near ""Foo";"
792 Execution of - aborted due to compilation errors.
793 ######## undefing constant causes a segfault in 5.6.1 [ID 20010906.019]
796 Can't modify constant item in undef operator at - line 1, near "foo;"
797 Execution of - aborted due to compilation errors.
798 ######## (?{...}) compilation bounces on PL_rs
804 BEGIN { print "ok\n" }
807 ######## read($var, FILE, 1) segfaults on 5.6.1 [ID 20011025.054]
810 Can't modify constant item in read at - line 1, near "1)"
811 Execution of - aborted due to compilation errors.