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 used to abnormally cause segfaults, and other nasty
8 # errors that might kill the interpreter and for some reason you can't
14 require './test.pl'; # for which_perl() etc
19 my $Perl = which_perl();
25 if(m/^#{8,}\s*(.*)/) {
32 plan tests => scalar @prgs;
34 foreach my $prog (@prgs) {
35 my($raw_prog, $name) = @$prog;
38 if ($raw_prog =~ s/^\s*(-\w.*)//){
42 my($prog,$expected) = split(/\nEXPECT\n/, $raw_prog);
44 if ($prog =~ /^\# SKIP: (.+)/m) {
51 $expected =~ s/\n+$//;
53 fresh_perl_is($prog, $expected, { switches => [$switch] }, $name);
58 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
62 $cusp = ~0 ^ (~0 >> 1);
65 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
71 Can't call method "go" on an undefined value at - line 1.
80 $x=0x0eabcd; print $x->ref;
82 Can't call method "ref" without a package or object reference at - line 1.
84 chop ($str .= <DATA>);
88 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
92 eval 'sub bar {print "In bar"}';
94 system './perl -ne "print if eof" /dev/null' unless $^O eq 'MacOS'
99 sub new {my ($obj,$n)=@_; bless \$n}
107 printf(STDOUT "%s\n", $_);
119 sub sub {local($_) = @_;
122 Modification of a read-only value attempted at - line 3.
124 package FOO;sub new {bless {FOO => BAR}};
138 print scalar ("foo","bar")
142 sub by_number { $a <=> $b; };# inline function for sort below
144 @ordered_array=sort by_number keys(%as_ary);
149 my($m2) = $#Shells++;
150 $Shells[$m2]{HOST} = $Host;
159 &ShowShell(&NewShell(beach,Work,"+0+0"));
160 &ShowShell(&NewShell(beach,Work,"+0+0"));
161 &ShowShell(&NewShell(beach,Work,"+0+0"));
167 { print "TIEARRAY @_\n";
168 die "bomb out\n" unless $count ++ ;
171 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
172 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
173 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
176 eval 'tie @h, FAKEARRAY, fred' ;
177 tie @h, FAKEARRAY, fred ;
179 TIEARRAY FAKEARRAY fred
180 TIEARRAY FAKEARRAY fred
183 BEGIN { die "phooey\n" }
186 BEGIN failed--compilation aborted at - line 1.
190 Illegal division by zero at - line 1.
191 BEGIN failed--compilation aborted at - line 1.
195 Modification of a read-only value attempted at - line 1.
196 BEGIN failed--compilation aborted at - line 1.
202 print join(' ', reverse @_)."\n";
207 print sprintf($fmt, @_)."\n";
213 "Out of inspiration";
216 print "and destroyed as well\n";
220 print STDOUT "foo->can(READ)(@_)\n";
225 print STDOUT "Don't GETC, Get Perl\n";
232 print FOO "sentence.", "reversed", "a", "is", "This";
233 print "-- ", <FOO>, " --\n";
234 my($buf,$len,$offset);
236 $len = 10; $offset = 1;
237 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
238 getc(FOO) eq "a" or die "foo->GETC failed";
239 printf "%s is number %d\n", "Perl", 1;
242 This is a reversed sentence.
243 -- Out of inspiration --
244 foo->can(READ)(string 10 1)
247 and destroyed as well
249 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
253 # used to attach defelem magic to all immortal values,
254 # which made restore of local $_ fail.
256 sub foo { bar() for @_; }
257 sub bar { local $_; }
262 @a = ($a, $b, $c, $d) = (5, 6);
264 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
268 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
272 print "ok\n" if ("\0" lt "\xFF");
276 open(H,$^O eq 'MacOS' ? ':run:fresh_perl.t' : 'run/fresh_perl.t'); # must be in the 't' directory
278 print "ok\n" if (-e _ and -f _ and -r _);
282 sub thing { 0 || return qw(now is the time) }
289 { local $main::{ren} = *stimpy; print $ren, ' ' }
295 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
296 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
301 sub func { print 'really ' unless wantarray; 'p' }
302 sub groovy { 'groovy' }
304 print p::func()->groovy(), "\n"
308 @list = ([ 'one', 1 ], [ 'two', 2 ]);
309 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
310 print scalar(map &func($_), 1 .. 3), " ",
311 scalar(map scalar &func($_), 1 .. 3), "\n";
316 @{$h{$k}} = qw(1 2 4);
317 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
318 print "bogus\n" unless $s == 7;
321 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
322 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
330 eval 'sub foo { print "In foo2\n" }';
331 print "Exiting foo1\n";
337 Subroutine foo redefined at (eval 1) line 1.
342 map {#this newline here tickles the bug
344 print "eat flaming death\n" unless ($s == 7);
346 sub foo { local $_ = shift; split; @_ }
348 print "you die joe!\n" unless "@x" eq 'x y z';
350 /(?{"{"})/ # Check it outside of eval too
352 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
354 /(?{"{"}})/ # Check it outside of eval too
356 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
357 syntax error at (re_eval 1) line 1, near ""{"}"
358 Compilation failed in regexp at - line 1.
360 BEGIN { @ARGV = qw(a b c d e) }
361 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
362 END { print "end <",shift,">\nargv <@ARGV>\n" }
363 INIT { print "init <",shift,">\n" }
364 CHECK { print "check <",shift,">\n" }
374 # fdopen from a system descriptor to a system descriptor used to close
376 open STDERR, '>&=STDOUT' or die $!;
377 select STDOUT; $| = 1; print fileno STDOUT or die $!;
378 select STDERR; $| = 1; print fileno STDERR or die $!;
384 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
386 Can't localize lexical variable $a at - line 2.
389 sub ascalar { my $r; bless \$r }
390 sub DESTROY { print "destroyed\n" };
397 sub anarray { bless [] }
398 sub DESTROY { print "destroyed\n" };
405 sub ahash { bless {} }
406 sub DESTROY { print "destroyed\n" };
413 sub aclosure { my $x; bless sub { ++$x } }
414 sub DESTROY { print "destroyed\n" };
422 my $f = "FH000"; # just to thwart any future optimisations
423 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
424 sub DESTROY { print "destroyed\n" }
426 $x = any X; # to bump sv_objcount. IO objs aren't counted??
434 $SIG{__WARN__} = sub {
435 eval { print $_[0] };
443 BEGIN failed--compilation aborted at - line 8.
458 print "DESTROY", $self->foo;
465 return $self->{$var};
467 $self->{$var} = shift;
471 $AUTOLOAD =~ /::([^:]+)$/;
473 splice @_, 1, 0, $method;
484 new1new22DESTROY2new33DESTROY31DESTROY1
488 my $re = join '', eval 'qr/(??{ $obj->method })/';
508 if (@ARGV) { print "" }
510 if ($x == 0) { print "" } else { print $x }
513 Use of uninitialized value in numeric eq (==) at - line 4.
517 sub foo { eval { return }; }
525 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
527 { f } continue { print $x, "\n" }
536 Modification of a read-only value attempted at - line 2.
538 print qw(ab a\b a\\b);
542 # lexicals declared after the myeval() definition should not be visible
544 sub myeval { eval $_[0] }
546 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
554 # lexicals outside an eval"" should be visible inside subroutine definitions
556 eval <<'EOT'; die $@ if $@;
559 eval 'sub Y { print $X }'; die $@ if $@;
566 # This test is here instead of lib/locale.t because
567 # the bug depends on in the internal state of the locale
568 # settings and pragma/locale messes up that state pretty badly.
569 # We need a "fresh run".
571 eval { require POSIX };
573 exit(0); # running minitest?
577 my $have_setlocale = $Config{d_setlocale} eq 'define';
578 $have_setlocale = 0 if $@;
579 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
580 # and mingw32 uses said silly CRT
581 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
582 exit(0) unless $have_setlocale;
584 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
591 exit(0) unless @locales;
593 use POSIX qw(locale_h);
595 setlocale(LC_NUMERIC, $_) or next;
596 my $s = sprintf "%g %g", 3.1, 3.1;
597 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
602 # [ID 20001202.002] and change #8066 added 'at -e line 1';
603 # reversed again as a result of [perl #17763]
608 # 20001210.003 mjd@plover.com
609 format REMITOUT_TOP =
617 # This loop causes a segv in 5.6.0
618 for $lineno (1..61) {
642 return eval "sub {shift=~/$pm/}";
644 new_pmop "abcdef"; reset;
645 new_pmop "abcdef"; reset;
646 new_pmop "abcdef"; reset;
647 new_pmop "abcdef"; reset;
655 "x" =~ /(\G?x)?/; # core dump in 20000716.007
670 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
674 my $foo = Bar->new();
677 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
682 my Bar $self = bless [], Bar;
691 ######## (?{...}) compilation bounces on PL_rs
697 BEGIN { print "ok\n" }
700 ######## scalar ref to file test operator segfaults on 5.6.1 [ID 20011127.155]
701 # This only happens if the filename is 11 characters or less.
703 print "ok" if ref $foo && !$$foo;
706 ######## [ID 20011128.159] 'X' =~ /\X/ segfault in 5.6.1
707 print "ok" if 'X' =~ /\X/;
710 ######## segfault in 5.6.1 within peep()
712 @b = sort { @c = sort { @d = sort { 0 } @a; @d; } @a; } @a;
713 print join '', @a, "\n";
716 ######## [ID 20020104.007] "coredump on dbmclose"
718 eval { require AnyDBM_File }; # not all places have dbm* functions
726 my $class = ref($proto) || $proto;
730 dbmopen(%LT, "dbmtest", 0666) ||
731 die "Can't open dbmtest because of $!\n";
732 $self->{'LT'} = \%LT;
737 dbmclose(%{$self->{'LT'}});
738 1 while unlink 'dbmtest';
739 1 while unlink <dbmtest.*>;
743 $test = Foo->new(); # must be package var
746 ######## example from Camel 5, ch. 15, pp.406 (with my)
747 # SKIP: ord "A" == 193 # EBCDIC
750 my $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
751 $人++; # a child is born
755 ######## example from Camel 5, ch. 15, pp.406 (with our)
756 # SKIP: ord "A" == 193 # EBCDIC
759 our $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
760 $人++; # a child is born
764 ######## example from Camel 5, ch. 15, pp.406 (with package vars)
765 # SKIP: ord "A" == 193 # EBCDIC
767 $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
768 $人++; # a child is born
772 ######## example from Camel 5, ch. 15, pp.406 (with use vars)
773 # SKIP: ord "A" == 193 # EBCDIC
777 $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
778 $人++; # a child is born
783 # test that closures generated by eval"" hold on to the CV of the eval""
784 # for their entire lifetime
786 sub { eval '$x = "ok 1\n"'; }
792 ######## [ID 20020623.009] nested eval/sub segfaults
793 $eval = eval 'sub { eval "sub { %S }" }';
795 ######## [perl #17951] Strange UTF error
797 # From: "John Kodis" <kodis@mail630.gsfc.nasa.gov>
798 # Newsgroups: comp.lang.perl.moderated
799 # Subject: Strange UTF error
800 # Date: Fri, 11 Oct 2002 16:19:58 -0400
801 # Message-ID: <pan.2002.10.11.20.19.48.407190@mail630.gsfc.nasa.gov>
803 utf8::upgrade($_); # the original code used a UTF-8 locale (affects STDIN)
804 # matching is actually irrelevant: avoiding several dozen of these
805 # Illegal hexadecimal digit ' ' ignored at /usr/lib/perl5/5.8.0/utf8_heavy.pl line 152
809 ######## [perl #20667] unicode regex vs non-unicode regex
811 $toto =~ /\w/; # this line provokes the problem!
813 # utf8::upgrade($name) if @ARGV;
814 if ($name =~ /(\p{IsUpper}) (\p{IsUpper})/){
815 print "It's good! >$1< >$2<\n";
817 print "It's not good...\n";
821 ######## [perl #8760] strangness with utf8 and warn
822 $_="foo";utf8::upgrade($_);/bar/i,warn$_;