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.*)\n//){
42 my($prog,$expected) = split(/\nEXPECT\n/, $raw_prog);
44 $expected = '' unless defined $expected;
46 if ($prog =~ /^\# SKIP: (.+)/m) {
53 $expected =~ s/\n+$//;
55 fresh_perl_is($prog, $expected, { switches => [$switch || ''] }, $name);
60 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
64 $cusp = ~0 ^ (~0 >> 1);
67 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
73 Can't call method "go" on an undefined value at - line 1.
82 $x=0x0eabcd; print $x->ref;
84 Can't call method "ref" without a package or object reference at - line 1.
86 chop ($str .= <DATA>);
90 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
94 eval 'sub bar {print "In bar"}';
96 system './perl -ne "print if eof" /dev/null' unless $^O eq 'MacOS'
101 sub new {my ($obj,$n)=@_; bless \$n}
109 printf(STDOUT "%s\n", $_);
121 sub sub {local($_) = @_;
124 Modification of a read-only value attempted at - line 3.
126 package FOO;sub new {bless {FOO => BAR}};
140 print scalar ("foo","bar")
144 sub by_number { $a <=> $b; };# inline function for sort below
146 @ordered_array=sort by_number keys(%as_ary);
151 my($m2) = $#Shells++;
152 $Shells[$m2]{HOST} = $Host;
161 &ShowShell(&NewShell(beach,Work,"+0+0"));
162 &ShowShell(&NewShell(beach,Work,"+0+0"));
163 &ShowShell(&NewShell(beach,Work,"+0+0"));
169 { print "TIEARRAY @_\n";
170 die "bomb out\n" unless $count ++ ;
173 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
174 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
175 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
178 eval 'tie @h, FAKEARRAY, fred' ;
179 tie @h, FAKEARRAY, fred ;
181 TIEARRAY FAKEARRAY fred
182 TIEARRAY FAKEARRAY fred
185 BEGIN { die "phooey\n" }
188 BEGIN failed--compilation aborted at - line 1.
192 Illegal division by zero at - line 1.
193 BEGIN failed--compilation aborted at - line 1.
197 Modification of a read-only value attempted at - line 1.
198 BEGIN failed--compilation aborted at - line 1.
204 print join(' ', reverse @_)."\n";
209 print sprintf($fmt, @_)."\n";
215 "Out of inspiration";
218 print "and destroyed as well\n";
222 print STDOUT "foo->can(READ)(@_)\n";
227 print STDOUT "Don't GETC, Get Perl\n";
234 print FOO "sentence.", "reversed", "a", "is", "This";
235 print "-- ", <FOO>, " --\n";
236 my($buf,$len,$offset);
238 $len = 10; $offset = 1;
239 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
240 getc(FOO) eq "a" or die "foo->GETC failed";
241 printf "%s is number %d\n", "Perl", 1;
244 This is a reversed sentence.
245 -- Out of inspiration --
246 foo->can(READ)(string 10 1)
249 and destroyed as well
251 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
255 # used to attach defelem magic to all immortal values,
256 # which made restore of local $_ fail.
258 sub foo { bar() for @_; }
259 sub bar { local $_; }
264 @a = ($a, $b, $c, $d) = (5, 6);
266 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
270 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
274 print "ok\n" if ("\0" lt "\xFF");
278 open(H,$^O eq 'MacOS' ? ':run:fresh_perl.t' : 'run/fresh_perl.t'); # must be in the 't' directory
280 print "ok\n" if (-e _ and -f _ and -r _);
284 sub thing { 0 || return qw(now is the time) }
291 { local $main::{ren} = *stimpy; print $ren, ' ' }
297 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
298 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
303 sub func { print 'really ' unless wantarray; 'p' }
304 sub groovy { 'groovy' }
306 print p::func()->groovy(), "\n"
310 @list = ([ 'one', 1 ], [ 'two', 2 ]);
311 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
312 print scalar(map &func($_), 1 .. 3), " ",
313 scalar(map scalar &func($_), 1 .. 3), "\n";
318 @{$h{$k}} = qw(1 2 4);
319 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
320 print "bogus\n" unless $s == 7;
323 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
324 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
332 eval 'sub foo { print "In foo2\n" }';
333 print "Exiting foo1\n";
339 Subroutine foo redefined at (eval 1) line 1.
344 map {#this newline here tickles the bug
346 print "eat flaming death\n" unless ($s == 7);
348 sub foo { local $_ = shift; split; @_ }
350 print "you die joe!\n" unless "@x" eq 'x y z';
352 /(?{"{"})/ # Check it outside of eval too
354 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
356 /(?{"{"}})/ # Check it outside of eval too
358 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
359 syntax error at (re_eval 1) line 1, near ""{"}"
360 Compilation failed in regexp at - line 1.
362 BEGIN { @ARGV = qw(a b c d e) }
363 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
364 END { print "end <",shift,">\nargv <@ARGV>\n" }
365 INIT { print "init <",shift,">\n" }
366 CHECK { print "check <",shift,">\n" }
376 # fdopen from a system descriptor to a system descriptor used to close
378 open STDERR, '>&=STDOUT' or die $!;
379 select STDOUT; $| = 1; print fileno STDOUT or die $!;
380 select STDERR; $| = 1; print fileno STDERR or die $!;
386 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
388 Can't localize lexical variable $a at - line 1.
391 sub ascalar { my $r; bless \$r }
392 sub DESTROY { print "destroyed\n" };
399 sub anarray { bless [] }
400 sub DESTROY { print "destroyed\n" };
407 sub ahash { bless {} }
408 sub DESTROY { print "destroyed\n" };
415 sub aclosure { my $x; bless sub { ++$x } }
416 sub DESTROY { print "destroyed\n" };
424 my $f = "FH000"; # just to thwart any future optimisations
425 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
426 sub DESTROY { print "destroyed\n" }
428 $x = any X; # to bump sv_objcount. IO objs aren't counted??
436 $SIG{__WARN__} = sub {
437 eval { print $_[0] };
445 BEGIN failed--compilation aborted at - line 8.
460 print "DESTROY", $self->foo;
467 return $self->{$var};
469 $self->{$var} = shift;
473 $AUTOLOAD =~ /::([^:]+)$/;
475 splice @_, 1, 0, $method;
486 new1new22DESTROY2new33DESTROY31DESTROY1
490 my $re = join '', eval 'qr/(??{ $obj->method })/';
510 if (@ARGV) { print "" }
512 if ($x == 0) { print "" } else { print $x }
515 Use of uninitialized value $x in numeric eq (==) at - line 3.
519 sub foo { eval { return }; }
527 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
529 { f } continue { print $x, "\n" }
538 Modification of a read-only value attempted at - line 2.
540 print qw(ab a\b a\\b);
544 # lexicals declared after the myeval() definition should not be visible
546 sub myeval { eval $_[0] }
548 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
556 # lexicals outside an eval"" should be visible inside subroutine definitions
558 eval <<'EOT'; die $@ if $@;
561 eval 'sub Y { print $X }'; die $@ if $@;
568 # This test is here instead of lib/locale.t because
569 # the bug depends on in the internal state of the locale
570 # settings and pragma/locale messes up that state pretty badly.
571 # We need a "fresh run".
573 eval { require POSIX };
575 exit(0); # running minitest?
579 my $have_setlocale = $Config{d_setlocale} eq 'define';
580 $have_setlocale = 0 if $@;
581 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
582 # and mingw32 uses said silly CRT
583 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
584 exit(0) unless $have_setlocale;
586 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
593 exit(0) unless @locales;
595 use POSIX qw(locale_h);
597 setlocale(LC_NUMERIC, $_) or next;
598 my $s = sprintf "%g %g", 3.1, 3.1;
599 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
604 # [ID 20001202.002] and change #8066 added 'at -e line 1';
605 # reversed again as a result of [perl #17763]
610 # 20001210.003 mjd@plover.com
611 format REMITOUT_TOP =
619 # This loop causes a segv in 5.6.0
620 for $lineno (1..61) {
644 return eval "sub {shift=~/$pm/}";
646 new_pmop "abcdef"; reset;
647 new_pmop "abcdef"; reset;
648 new_pmop "abcdef"; reset;
649 new_pmop "abcdef"; reset;
656 # core dump in 20000716.007
673 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
677 my $foo = Bar->new();
680 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
685 my Bar $self = bless [], Bar;
694 ######## (?{...}) compilation bounces on PL_rs
700 BEGIN { print "ok\n" }
703 ######## scalar ref to file test operator segfaults on 5.6.1 [ID 20011127.155]
704 # This only happens if the filename is 11 characters or less.
706 print "ok" if ref $foo && !$$foo;
709 ######## [ID 20011128.159] 'X' =~ /\X/ segfault in 5.6.1
710 print "ok" if 'X' =~ /\X/;
713 ######## segfault in 5.6.1 within peep()
715 @b = sort { @c = sort { @d = sort { 0 } @a; @d; } @a; } @a;
716 print join '', @a, "\n";
719 ######## [ID 20020104.007] "coredump on dbmclose"
721 eval { require AnyDBM_File }; # not all places have dbm* functions
729 my $class = ref($proto) || $proto;
733 dbmopen(%LT, "dbmtest", 0666) ||
734 die "Can't open dbmtest because of $!\n";
735 $self->{'LT'} = \%LT;
740 dbmclose(%{$self->{'LT'}});
741 1 while unlink 'dbmtest';
742 1 while unlink <dbmtest.*>;
746 $test = Foo->new(); # must be package var
749 ######## example from Camel 5, ch. 15, pp.406 (with my)
750 # SKIP: ord "A" == 193 # EBCDIC
753 my $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
754 $人++; # a child is born
758 ######## example from Camel 5, ch. 15, pp.406 (with our)
759 # SKIP: ord "A" == 193 # EBCDIC
762 our $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
763 $人++; # a child is born
767 ######## example from Camel 5, ch. 15, pp.406 (with package vars)
768 # SKIP: ord "A" == 193 # EBCDIC
770 $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
771 $人++; # a child is born
775 ######## example from Camel 5, ch. 15, pp.406 (with use vars)
776 # SKIP: ord "A" == 193 # EBCDIC
780 $人 = 2; # 0xe4 0xba 0xba: U+4eba, "human" in CJK ideograph
781 $人++; # a child is born
786 # test that closures generated by eval"" hold on to the CV of the eval""
787 # for their entire lifetime
789 sub { eval '$x = "ok 1\n"'; }
795 ######## [ID 20020623.009] nested eval/sub segfaults
796 $eval = eval 'sub { eval "sub { %S }" }';
798 ######## [perl #17951] Strange UTF error
800 # From: "John Kodis" <kodis@mail630.gsfc.nasa.gov>
801 # Newsgroups: comp.lang.perl.moderated
802 # Subject: Strange UTF error
803 # Date: Fri, 11 Oct 2002 16:19:58 -0400
804 # Message-ID: <pan.2002.10.11.20.19.48.407190@mail630.gsfc.nasa.gov>
806 utf8::upgrade($_); # the original code used a UTF-8 locale (affects STDIN)
807 # matching is actually irrelevant: avoiding several dozen of these
808 # Illegal hexadecimal digit ' ' ignored at /usr/lib/perl5/5.8.0/utf8_heavy.pl line 152
812 ######## [perl #20667] unicode regex vs non-unicode regex
814 $toto =~ /\w/; # this line provokes the problem!
816 # utf8::upgrade($name) if @ARGV;
817 if ($name =~ /(\p{IsUpper}) (\p{IsUpper})/){
818 print "It's good! >$1< >$2<\n";
820 print "It's not good...\n";
824 ######## [perl #8760] strangness with utf8 and warn
825 $_="foo";utf8::upgrade($_);/bar/i,warn$_;
828 ######## glob() bug Mon, 01 Sep 2003 02:25:41 -0700 <200309010925.h819Pf0X011457@smtp3.ActiveState.com>
831 if ($^O eq 'os390') {
833 import File::Glob ':glob';
837 eval 'require Fcntl';
838 if ($@) { print qq[./"TEST"\n./"TEST"\n]; exit 0 } # running minitest?
840 if ($^O eq 'VMS') { # VMS is not *that* kind of a glob.
841 print qq[./"TEST"\n./"TEST"\n];
843 print glob(q(./"TEST"));
845 print glob(q(./"TEST"));
850 ######## glob() bug Mon, 01 Sep 2003 02:25:41 -0700 <200309010925.h819Pf0X011457@smtp3.ActiveState.com>
853 if ($^O eq 'os390') {
855 import File::Glob ':glob';
859 eval 'require Fcntl';
860 if ($@) { print qq[./"TEST"\n./"TEST"\n]; exit 0 } # running minitest?
862 if ($^O eq 'VMS') { # VMS is not *that* kind of a glob.
863 print qq[./"TEST"\n./"TEST"\n];
866 print glob(q(./"TEST"));
868 print glob(q(./"TEST"));
873 ######## "Segfault using HTML::Entities", Richard Jolly <richardjolly@mac.com>, <A3C7D27E-C9F4-11D8-B294-003065AE00B6@mac.com> in perl-unicode@perl.org
875 # SKIP: use Config; $ENV{PERL_CORE_MINITEST} or " $Config::Config{'extensions'} " !~ m[ Encode ] # Perl configured without Encode module
877 eval 'require Encode';
878 if ($@) { exit 0 } # running minitest?
880 # Test case cut down by jhi
881 $SIG{__WARN__} = sub { $@ = shift };
883 my $t = ord('A') == 193 ? "\xEA" : "\xE9";
884 Encode::_utf8_on($t);
889 Malformed UTF-8 character (unexpected end of string) in substitution (s///) at