3 # NOTE: Please don't add tests to this file unless they *need* to be run in
4 # separate executable and can't simply use eval.
8 $ENV{PERL5LIB} = "../lib";
13 @prgs = split "\n########\n", <DATA>;
14 print "1..", scalar @prgs, "\n";
16 $tmpfile = "misctmp000";
17 1 while -f ++$tmpfile;
18 END { while($tmpfile && unlink $tmpfile){} }
20 $CAT = (($^O eq 'MSWin32') ? '.\perl -e "print <>"' : (($^O eq 'NetWare') ? 'perl -e "print <>"' : 'cat'));
27 my($prog,$expected) = split(/\nEXPECT\n/, $_);
28 open TEST, ">$tmpfile" or die "Cannot open $tmpfile: $!";
29 $prog =~ s#/dev/null#NL:# if $^O eq 'VMS';
30 $prog =~ s#if \(-e _ and -f _ and -r _\)#if (-e _ and -f _)# if $^O eq 'VMS'; # VMS file locking
32 print TEST $prog, "\n";
33 close TEST or die "Cannot close $tmpfile: $!";
35 if ($^O eq 'MSWin32') {
36 $results = `.\\perl -I../lib $switch $tmpfile 2>&1`;
38 elsif ($^O eq 'NetWare') {
39 $results = `perl -I../lib $switch $tmpfile 2>&1`;
42 $results = `./perl $switch $tmpfile 2>&1`;
46 $results =~ s/at\s+misctmp\d+\s+line/at - line/g;
47 $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g;
48 # bison says 'parse error' instead of 'syntax error',
49 # various yaccs may or may not capitalize 'syntax'.
50 $results =~ s/^(syntax|parse) error/syntax error/mig;
51 $expected =~ s/\n+$//;
52 if ( $results ne $expected ) {
53 print STDERR "PROG: $switch\n$prog\n";
54 print STDERR "EXPECTED:\n$expected\n";
55 print STDERR "GOT:\n$results\n";
58 print "ok ", ++$i, "\n";
64 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
68 $cusp = ~0 ^ (~0 >> 1);
71 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
77 Can't call method "go" on an undefined value at - line 1.
86 $x=0x0eabcd; print $x->ref;
88 Can't call method "ref" without a package or object reference at - line 1.
90 chop ($str .= <DATA>);
94 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
98 eval {sub bar {print "In bar";}}
100 system './perl -ne "print if eof" /dev/null'
102 chop($file = <DATA>);
105 sub new {my ($obj,$n)=@_; bless \$n}
114 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
115 Execution of - aborted due to compilation errors.
118 printf(STDOUT "%s\n", $_);
130 sub sub {local($_) = @_;
133 Modification of a read-only value attempted at - line 3.
135 package FOO;sub new {bless {FOO => BAR}};
149 print scalar ("foo","bar")
153 sub by_number { $a <=> $b; };# inline function for sort below
155 @ordered_array=sort by_number keys(%as_ary);
160 my($m2) = $#Shells++;
161 $Shells[$m2]{HOST} = $Host;
170 &ShowShell(&NewShell(beach,Work,"+0+0"));
171 &ShowShell(&NewShell(beach,Work,"+0+0"));
172 &ShowShell(&NewShell(beach,Work,"+0+0"));
178 { print "TIEARRAY @_\n";
179 die "bomb out\n" unless $count ++ ;
182 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
183 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
184 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
187 eval 'tie @h, FAKEARRAY, fred' ;
188 tie @h, FAKEARRAY, fred ;
190 TIEARRAY FAKEARRAY fred
191 TIEARRAY FAKEARRAY fred
194 BEGIN { die "phooey\n" }
197 BEGIN failed--compilation aborted at - line 1.
201 Illegal division by zero at - line 1.
202 BEGIN failed--compilation aborted at - line 1.
206 Modification of a read-only value attempted at - line 1.
207 BEGIN failed--compilation aborted at - line 1.
213 print join(' ', reverse @_)."\n";
218 print sprintf($fmt, @_)."\n";
224 "Out of inspiration";
227 print "and destroyed as well\n";
231 print STDOUT "foo->can(READ)(@_)\n";
236 print STDOUT "Don't GETC, Get Perl\n";
243 print FOO "sentence.", "reversed", "a", "is", "This";
244 print "-- ", <FOO>, " --\n";
245 my($buf,$len,$offset);
247 $len = 10; $offset = 1;
248 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
249 getc(FOO) eq "a" or die "foo->GETC failed";
250 printf "%s is number %d\n", "Perl", 1;
253 This is a reversed sentence.
254 -- Out of inspiration --
255 foo->can(READ)(string 10 1)
258 and destroyed as well
260 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
264 # used to attach defelem magic to all immortal values,
265 # which made restore of local $_ fail.
267 sub foo { bar() for @_; }
268 sub bar { local $_; }
273 @a = ($a, $b, $c, $d) = (5, 6);
275 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
279 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
283 print "ok\n" if ("\0" lt "\xFF");
287 open(H,'op/misc.t'); # must be in the 't' directory
289 print "ok\n" if (-e _ and -f _ and -r _);
293 sub thing { 0 || return qw(now is the time) }
300 { local $main::{ren} = *stimpy; print $ren, ' ' }
306 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
307 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
312 sub func { print 'really ' unless wantarray; 'p' }
313 sub groovy { 'groovy' }
315 print p::func()->groovy(), "\n"
319 @list = ([ 'one', 1 ], [ 'two', 2 ]);
320 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
321 print scalar(map &func($_), 1 .. 3), " ",
322 scalar(map scalar &func($_), 1 .. 3), "\n";
327 @{$h{$k}} = qw(1 2 4);
328 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
329 print "bogus\n" unless $s == 7;
332 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
333 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
341 eval 'sub foo { print "In foo2\n" }';
342 print "Exiting foo1\n";
348 Subroutine foo redefined at (eval 1) line 1.
353 map {#this newline here tickles the bug
355 print "eat flaming death\n" unless ($s == 7);
357 sub foo { local $_ = shift; split; @_ }
359 print "you die joe!\n" unless "@x" eq 'x y z';
361 /(?{"{"})/ # Check it outside of eval too
363 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
364 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
366 /(?{"{"}})/ # Check it outside of eval too
368 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
369 syntax error at (re_eval 1) line 1, near ""{"}"
370 Compilation failed in regexp at - line 1.
372 BEGIN { @ARGV = qw(a b c d e) }
373 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
374 END { print "end <",shift,">\nargv <@ARGV>\n" }
375 INIT { print "init <",shift,">\n" }
376 CHECK { print "check <",shift,">\n" }
386 # fdopen from a system descriptor to a system descriptor used to close
388 open STDERR, '>&=STDOUT' or die $!;
389 select STDOUT; $| = 1; print fileno STDOUT or die $!;
390 select STDERR; $| = 1; print fileno STDERR or die $!;
396 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
398 Can't localize lexical variable $a at - line 2.
401 sub ascalar { my $r; bless \$r }
402 sub DESTROY { print "destroyed\n" };
409 sub anarray { bless [] }
410 sub DESTROY { print "destroyed\n" };
417 sub ahash { bless {} }
418 sub DESTROY { print "destroyed\n" };
425 sub aclosure { my $x; bless sub { ++$x } }
426 sub DESTROY { print "destroyed\n" };
434 my $f = "FH000"; # just to thwart any future optimisations
435 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
436 sub DESTROY { print "destroyed\n" }
438 $x = any X; # to bump sv_objcount. IO objs aren't counted??
446 $SIG{__WARN__} = sub {
447 eval { print $_[0] };
455 BEGIN failed--compilation aborted at - line 8.
470 print "DESTROY", $self->foo;
477 return $self->{$var};
479 $self->{$var} = shift;
483 $AUTOLOAD =~ /::([^:]+)$/;
485 splice @_, 1, 0, $method;
496 new1new22DESTROY2new33DESTROY31DESTROY1
500 my $re = join '', eval 'qr/(??{ $obj->method })/';
520 if (@ARGV) { print "" }
522 if ($x == 0) { print "" } else { print $x }
525 Use of uninitialized value in numeric eq (==) at - line 4.
529 sub foo { eval { return }; }
534 my @l = qw(hello.* world);
538 print "before - $x\n";
540 print "quotemeta - $x\n";
542 print "ucfirst - $x\n";
544 print "lcfirst - $x\n";
552 quotemeta - hello\.\*
564 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
566 { f } continue { print $x, "\n" }
575 Modification of a read-only value attempted at - line 2.
577 print qw(ab a\b a\\b);
581 # lexicals declared after the myeval() definition should not be visible
583 sub myeval { eval $_[0] }
585 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
593 # lexicals outside an eval"" should be visible inside subroutine definitions
595 eval <<'EOT'; die $@ if $@;
598 eval 'sub Y { print $X }'; die $@ if $@;
605 # test that closures generated by eval"" hold on to the CV of the eval""
606 # for their entire lifetime
608 sub { eval '$x = "ok 1\n"'; }
615 # This test is here instead of pragma/locale.t because
616 # the bug depends on in the internal state of the locale
617 # settings and pragma/locale messes up that state pretty badly.
618 # We need a "fresh run".
620 eval { require POSIX };
622 exit(0); # running minitest?
626 my $have_setlocale = $Config{d_setlocale} eq 'define';
627 $have_setlocale = 0 if $@;
628 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
629 # and mingw32 uses said silly CRT
630 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
631 exit(0) unless $have_setlocale;
633 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a|")) {
640 exit(0) unless @locales;
642 use POSIX qw(locale_h);
644 setlocale(LC_NUMERIC, $_) or next;
645 my $s = sprintf "%g %g", 3.1, 3.1;
646 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
653 (?-xism:x) at - line 1.
655 # 20001210.003 mjd@plover.com
656 format REMITOUT_TOP =
664 # This loop causes a segv in 5.6.0
665 for $lineno (1..61) {
689 return eval "sub {shift=~/$pm/}";
691 new_pmop "abcdef"; reset;
692 new_pmop "abcdef"; reset;
693 new_pmop "abcdef"; reset;
694 new_pmop "abcdef"; reset;
702 "x" =~ /(\G?x)?/; # core dump in 20000716.007
704 Quantifier unexpected on zero-length expression in regex; marked by <-- HERE in m/(\G?x)? <-- HERE / at - line 2.
719 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
726 syntax error at - line 2, near "${}"
727 Execution of - aborted due to compilation errors.
732 Missing right brace on \x{} at - line 2, within string
733 Execution of - aborted due to compilation errors.
735 my $foo = Bar->new();
738 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
743 my Bar $self = bless [], Bar;
753 eval "a.b.c.d.e.f;sub"