3 # ** DO NOT ADD ANY MORE TESTS HERE **
4 # Instead, put the test in the appropriate test file and use the
5 # fresh_perl_is()/fresh_perl_like() functions in t/test.pl.
7 # This is for tests that will normally cause segfaults, and other nasty
8 # errors that might kill the interpreter and for some reason you can't
11 # New tests are added to the bottom. For example.
13 # ######## perlbug ID 20020831.001
16 # Can't modify constant item in list assignment - at line 1
18 # to test that the code "($a, b) = (1,2)" causes the appropriate syntax
19 # error, rather than just segfaulting as reported in perlbug ID
25 require './test.pl'; # for which_perl() etc
30 my $Perl = which_perl();
36 if(m/^#{8,}\s*(.*)/) {
43 plan tests => scalar @prgs;
45 foreach my $prog (@prgs) {
46 my($raw_prog, $name) = @$prog;
49 if ($raw_prog =~ s/^\s*(-\w.*)//){
53 my($prog,$expected) = split(/\nEXPECT\n/, $raw_prog);
55 $expected =~ s/\n+$//;
57 fresh_perl_is($prog, $expected, { switches => [$switch] }, $name);
62 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
66 $cusp = ~0 ^ (~0 >> 1);
69 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
75 Can't call method "go" on an undefined value at - line 1.
84 $x=0x0eabcd; print $x->ref;
86 Can't call method "ref" without a package or object reference at - line 1.
88 chop ($str .= <DATA>);
92 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
96 eval {sub bar {print "In bar";}}
98 system './perl -ne "print if eof" /dev/null' unless $^O eq 'MacOS'
100 chop($file = <DATA>);
103 sub new {my ($obj,$n)=@_; bless \$n}
112 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
113 Execution of - aborted due to compilation errors.
116 printf(STDOUT "%s\n", $_);
128 sub sub {local($_) = @_;
131 Modification of a read-only value attempted at - line 3.
133 package FOO;sub new {bless {FOO => BAR}};
147 print scalar ("foo","bar")
151 sub by_number { $a <=> $b; };# inline function for sort below
153 @ordered_array=sort by_number keys(%as_ary);
158 my($m2) = $#Shells++;
159 $Shells[$m2]{HOST} = $Host;
168 &ShowShell(&NewShell(beach,Work,"+0+0"));
169 &ShowShell(&NewShell(beach,Work,"+0+0"));
170 &ShowShell(&NewShell(beach,Work,"+0+0"));
176 { print "TIEARRAY @_\n";
177 die "bomb out\n" unless $count ++ ;
180 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
181 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
182 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
185 eval 'tie @h, FAKEARRAY, fred' ;
186 tie @h, FAKEARRAY, fred ;
188 TIEARRAY FAKEARRAY fred
189 TIEARRAY FAKEARRAY fred
192 BEGIN { die "phooey\n" }
195 BEGIN failed--compilation aborted at - line 1.
199 Illegal division by zero at - line 1.
200 BEGIN failed--compilation aborted at - line 1.
204 Modification of a read-only value attempted at - line 1.
205 BEGIN failed--compilation aborted at - line 1.
211 print join(' ', reverse @_)."\n";
216 print sprintf($fmt, @_)."\n";
222 "Out of inspiration";
225 print "and destroyed as well\n";
229 print STDOUT "foo->can(READ)(@_)\n";
234 print STDOUT "Don't GETC, Get Perl\n";
241 print FOO "sentence.", "reversed", "a", "is", "This";
242 print "-- ", <FOO>, " --\n";
243 my($buf,$len,$offset);
245 $len = 10; $offset = 1;
246 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
247 getc(FOO) eq "a" or die "foo->GETC failed";
248 printf "%s is number %d\n", "Perl", 1;
251 This is a reversed sentence.
252 -- Out of inspiration --
253 foo->can(READ)(string 10 1)
256 and destroyed as well
258 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
262 # used to attach defelem magic to all immortal values,
263 # which made restore of local $_ fail.
265 sub foo { bar() for @_; }
266 sub bar { local $_; }
271 @a = ($a, $b, $c, $d) = (5, 6);
273 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
277 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
281 print "ok\n" if ("\0" lt "\xFF");
285 open(H,$^O eq 'MacOS' ? ':run:fresh_perl.t' : 'run/fresh_perl.t'); # must be in the 't' directory
287 print "ok\n" if (-e _ and -f _ and -r _);
291 sub thing { 0 || return qw(now is the time) }
298 { local $main::{ren} = *stimpy; print $ren, ' ' }
304 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
305 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
310 sub func { print 'really ' unless wantarray; 'p' }
311 sub groovy { 'groovy' }
313 print p::func()->groovy(), "\n"
317 @list = ([ 'one', 1 ], [ 'two', 2 ]);
318 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
319 print scalar(map &func($_), 1 .. 3), " ",
320 scalar(map scalar &func($_), 1 .. 3), "\n";
325 @{$h{$k}} = qw(1 2 4);
326 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
327 print "bogus\n" unless $s == 7;
330 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
331 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
339 eval 'sub foo { print "In foo2\n" }';
340 print "Exiting foo1\n";
346 Subroutine foo redefined at (eval 1) line 1.
351 map {#this newline here tickles the bug
353 print "eat flaming death\n" unless ($s == 7);
355 sub foo { local $_ = shift; split; @_ }
357 print "you die joe!\n" unless "@x" eq 'x y z';
359 /(?{"{"})/ # Check it outside of eval too
361 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
362 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
364 /(?{"{"}})/ # Check it outside of eval too
366 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
367 syntax error at (re_eval 1) line 1, near ""{"}"
368 Compilation failed in regexp at - line 1.
370 BEGIN { @ARGV = qw(a b c d e) }
371 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
372 END { print "end <",shift,">\nargv <@ARGV>\n" }
373 INIT { print "init <",shift,">\n" }
374 CHECK { print "check <",shift,">\n" }
384 # fdopen from a system descriptor to a system descriptor used to close
386 open STDERR, '>&=STDOUT' or die $!;
387 select STDOUT; $| = 1; print fileno STDOUT or die $!;
388 select STDERR; $| = 1; print fileno STDERR or die $!;
394 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
396 Can't localize lexical variable $a at - line 2.
399 sub ascalar { my $r; bless \$r }
400 sub DESTROY { print "destroyed\n" };
407 sub anarray { bless [] }
408 sub DESTROY { print "destroyed\n" };
415 sub ahash { bless {} }
416 sub DESTROY { print "destroyed\n" };
423 sub aclosure { my $x; bless sub { ++$x } }
424 sub DESTROY { print "destroyed\n" };
432 my $f = "FH000"; # just to thwart any future optimisations
433 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
434 sub DESTROY { print "destroyed\n" }
436 $x = any X; # to bump sv_objcount. IO objs aren't counted??
444 $SIG{__WARN__} = sub {
445 eval { print $_[0] };
453 BEGIN failed--compilation aborted at - line 8.
468 print "DESTROY", $self->foo;
475 return $self->{$var};
477 $self->{$var} = shift;
481 $AUTOLOAD =~ /::([^:]+)$/;
483 splice @_, 1, 0, $method;
494 new1new22DESTROY2new33DESTROY31DESTROY1
498 my $re = join '', eval 'qr/(??{ $obj->method })/';
518 if (@ARGV) { print "" }
520 if ($x == 0) { print "" } else { print $x }
523 Use of uninitialized value in numeric eq (==) at - line 4.
527 sub foo { eval { return }; }
535 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
537 { f } continue { print $x, "\n" }
546 Modification of a read-only value attempted at - line 2.
548 print qw(ab a\b a\\b);
552 # lexicals declared after the myeval() definition should not be visible
554 sub myeval { eval $_[0] }
556 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
564 # lexicals outside an eval"" should be visible inside subroutine definitions
566 eval <<'EOT'; die $@ if $@;
569 eval 'sub Y { print $X }'; die $@ if $@;
576 # This test is here instead of lib/locale.t because
577 # the bug depends on in the internal state of the locale
578 # settings and pragma/locale messes up that state pretty badly.
579 # We need a "fresh run".
581 eval { require POSIX };
583 exit(0); # running minitest?
587 my $have_setlocale = $Config{d_setlocale} eq 'define';
588 $have_setlocale = 0 if $@;
589 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
590 # and mingw32 uses said silly CRT
591 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
592 exit(0) unless $have_setlocale;
594 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
601 exit(0) unless @locales;
603 use POSIX qw(locale_h);
605 setlocale(LC_NUMERIC, $_) or next;
606 my $s = sprintf "%g %g", 3.1, 3.1;
607 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
614 (?-xism:x) at - line 1.
616 # 20001210.003 mjd@plover.com
617 format REMITOUT_TOP =
625 # This loop causes a segv in 5.6.0
626 for $lineno (1..61) {
650 return eval "sub {shift=~/$pm/}";
652 new_pmop "abcdef"; reset;
653 new_pmop "abcdef"; reset;
654 new_pmop "abcdef"; reset;
655 new_pmop "abcdef"; reset;
663 "x" =~ /(\G?x)?/; # core dump in 20000716.007
678 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
685 syntax error at - line 2, near "${}"
686 Execution of - aborted due to compilation errors.
691 Missing right brace on \x{} at - line 2, within string
692 Execution of - aborted due to compilation errors.
694 my $foo = Bar->new();
697 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
702 my Bar $self = bless [], Bar;
712 ######## found by Markov chain stress testing
713 eval "a.b.c.d.e.f;sub"
716 ######## perlbug ID 20010831.001
719 Can't modify constant item in list assignment at - line 1, near ");"
720 Execution of - aborted due to compilation errors.
721 ######## tying a bareword causes a segfault in 5.6.1
724 Can't modify constant item in tie at - line 1, near ""Foo";"
725 Execution of - aborted due to compilation errors.
726 ######## undefing constant causes a segfault in 5.6.1 [ID 20010906.019]
729 Can't modify constant item in undef operator at - line 1, near "foo;"
730 Execution of - aborted due to compilation errors.
731 ######## (?{...}) compilation bounces on PL_rs
737 BEGIN { print "ok\n" }
740 ######## read($var, FILE, 1) segfaults on 5.6.1 [ID 20011025.054]
743 Can't modify constant item in read at - line 1, near "1)"
744 Execution of - aborted due to compilation errors.
745 ######## scalar ref to file test operator segfaults on 5.6.1 [ID 20011127.155]
746 # This only happens if the filename is 11 characters or less.
748 print "ok" if ref $foo && !$$foo;
751 ######## [ID 20011128.159] 'X' =~ /\X/ segfault in 5.6.1
752 print "ok" if 'X' =~ /\X/;
755 ######## segfault in 5.6.1 within peep()
757 @b = sort { @c = sort { @d = sort { 0 } @a; @d; } @a; } @a;
758 print join '', @a, "\n";
761 ######## [ID 20020104.007] "coredump on dbmclose"
763 eval { require AnyDBM_File }; # not all places have dbm* functions
771 my $class = ref($proto) || $proto;
775 dbmopen(%LT, "dbmtest", 0666) ||
776 die "Can't open dbmtest because of $!\n";
777 $self->{'LT'} = \%LT;
782 dbmclose(%{$self->{'LT'}});
783 1 while unlink 'dbmtest';
784 1 while unlink <dbmtest.*>;
788 $test = Foo->new(); # must be package var
791 ######## example from Camel 5, ch. 15, pp.406 (with my)
794 my $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
795 $人++; # a child is born
799 ######## example from Camel 5, ch. 15, pp.406 (with our)
802 our $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
803 $人++; # a child is born
807 ######## example from Camel 5, ch. 15, pp.406 (with package vars)
809 $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
810 $人++; # a child is born
815 # TODO An attempt at lvalueable barewords broke this
818 Can't modify constant item in tie at - line 2, near "'main';"
819 Execution of - aborted due to compilation errors.