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 <>"' : '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`;
39 $results = `./perl $switch $tmpfile 2>&1`;
43 $results =~ s/at\s+misctmp\d+\s+line/at - line/g;
44 $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g;
45 # bison says 'parse error' instead of 'syntax error',
46 # various yaccs may or may not capitalize 'syntax'.
47 $results =~ s/^(syntax|parse) error/syntax error/mig;
48 $expected =~ s/\n+$//;
49 if ( $results ne $expected ) {
50 print STDERR "PROG: $switch\n$prog\n";
51 print STDERR "EXPECTED:\n$expected\n";
52 print STDERR "GOT:\n$results\n";
55 print "ok ", ++$i, "\n";
61 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
65 $cusp = ~0 ^ (~0 >> 1);
68 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
74 Can't call method "go" on an undefined value at - line 1.
83 $x=0x0eabcd; print $x->ref;
85 Can't call method "ref" without a package or object reference at - line 1.
87 chop ($str .= <DATA>);
91 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
95 eval {sub bar {print "In bar";}}
97 system './perl -ne "print if eof" /dev/null'
102 sub new {my ($obj,$n)=@_; bless \$n}
111 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
112 Execution of - aborted due to compilation errors.
115 printf(STDOUT "%s\n", $_);
127 sub sub {local($_) = @_;
130 Modification of a read-only value attempted at - line 3.
132 package FOO;sub new {bless {FOO => BAR}};
146 print scalar ("foo","bar")
150 sub by_number { $a <=> $b; };# inline function for sort below
152 @ordered_array=sort by_number keys(%as_ary);
157 my($m2) = $#Shells++;
158 $Shells[$m2]{HOST} = $Host;
167 &ShowShell(&NewShell(beach,Work,"+0+0"));
168 &ShowShell(&NewShell(beach,Work,"+0+0"));
169 &ShowShell(&NewShell(beach,Work,"+0+0"));
175 { print "TIEARRAY @_\n";
176 die "bomb out\n" unless $count ++ ;
179 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
180 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
181 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
184 eval 'tie @h, FAKEARRAY, fred' ;
185 tie @h, FAKEARRAY, fred ;
187 TIEARRAY FAKEARRAY fred
188 TIEARRAY FAKEARRAY fred
191 BEGIN { die "phooey\n" }
194 BEGIN failed--compilation aborted at - line 1.
198 Illegal division by zero at - line 1.
199 BEGIN failed--compilation aborted at - line 1.
203 Modification of a read-only value attempted at - line 1.
204 BEGIN failed--compilation aborted at - line 1.
210 print join(' ', reverse @_)."\n";
215 print sprintf($fmt, @_)."\n";
221 "Out of inspiration";
224 print "and destroyed as well\n";
228 print STDOUT "foo->can(READ)(@_)\n";
233 print STDOUT "Don't GETC, Get Perl\n";
240 print FOO "sentence.", "reversed", "a", "is", "This";
241 print "-- ", <FOO>, " --\n";
242 my($buf,$len,$offset);
244 $len = 10; $offset = 1;
245 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
246 getc(FOO) eq "a" or die "foo->GETC failed";
247 printf "%s is number %d\n", "Perl", 1;
250 This is a reversed sentence.
251 -- Out of inspiration --
252 foo->can(READ)(string 10 1)
255 and destroyed as well
257 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
261 # used to attach defelem magic to all immortal values,
262 # which made restore of local $_ fail.
264 sub foo { bar() for @_; }
265 sub bar { local $_; }
270 @a = ($a, $b, $c, $d) = (5, 6);
272 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
276 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
280 print "ok\n" if ("\0" lt "\xFF");
284 open(H,'op/misc.t'); # must be in the 't' directory
286 print "ok\n" if (-e _ and -f _ and -r _);
290 sub thing { 0 || return qw(now is the time) }
297 { local $main::{ren} = *stimpy; print $ren, ' ' }
303 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
304 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
309 sub func { print 'really ' unless wantarray; 'p' }
310 sub groovy { 'groovy' }
312 print p::func()->groovy(), "\n"
316 @list = ([ 'one', 1 ], [ 'two', 2 ]);
317 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
318 print scalar(map &func($_), 1 .. 3), " ",
319 scalar(map scalar &func($_), 1 .. 3), "\n";
324 @{$h{$k}} = qw(1 2 4);
325 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
326 print "bogus\n" unless $s == 7;
329 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
330 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
338 eval 'sub foo { print "In foo2\n" }';
339 print "Exiting foo1\n";
345 Subroutine foo redefined at (eval 1) line 1.
350 map {#this newline here tickles the bug
352 print "eat flaming death\n" unless ($s == 7);
354 sub foo { local $_ = shift; split; @_ }
356 print "you die joe!\n" unless "@x" eq 'x y z';
358 /(?{"{"})/ # Check it outside of eval too
360 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
361 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
363 /(?{"{"}})/ # Check it outside of eval too
365 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
366 syntax error at (re_eval 1) line 1, near ""{"}"
367 Compilation failed in regexp at - line 1.
369 BEGIN { @ARGV = qw(a b c d e) }
370 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
371 END { print "end <",shift,">\nargv <@ARGV>\n" }
372 INIT { print "init <",shift,">\n" }
373 CHECK { print "check <",shift,">\n" }
383 # fdopen from a system descriptor to a system descriptor used to close
385 open STDERR, '>&=STDOUT' or die $!;
386 select STDOUT; $| = 1; print fileno STDOUT or die $!;
387 select STDERR; $| = 1; print fileno STDERR or die $!;
393 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
395 Can't localize lexical variable $a at - line 2.
398 sub ascalar { my $r; bless \$r }
399 sub DESTROY { print "destroyed\n" };
406 sub anarray { bless [] }
407 sub DESTROY { print "destroyed\n" };
414 sub ahash { bless {} }
415 sub DESTROY { print "destroyed\n" };
422 sub aclosure { my $x; bless sub { ++$x } }
423 sub DESTROY { print "destroyed\n" };
431 my $f = "FH000"; # just to thwart any future optimisations
432 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
433 sub DESTROY { print "destroyed\n" }
435 $x = any X; # to bump sv_objcount. IO objs aren't counted??
443 $SIG{__WARN__} = sub {
444 eval { print $_[0] };
452 BEGIN failed--compilation aborted at - line 8.
467 print "DESTROY", $self->foo;
474 return $self->{$var};
476 $self->{$var} = shift;
480 $AUTOLOAD =~ /::([^:]+)$/;
482 splice @_, 1, 0, $method;
493 new1new22DESTROY2new33DESTROY31DESTROY1
497 my $re = join '', eval 'qr/(??{ $obj->method })/';
517 if (@ARGV) { print "" }
519 if ($x == 0) { print "" } else { print $x }
522 Use of uninitialized value in numeric eq (==) at - line 4.
526 sub foo { eval { return }; }
531 my @l = qw(hello.* world);
535 print "before - $x\n";
537 print "quotemeta - $x\n";
539 print "ucfirst - $x\n";
541 print "lcfirst - $x\n";
549 quotemeta - hello\.\*
561 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
563 { f } continue { print $x, "\n" }
572 Modification of a read-only value attempted at - line 2.
574 print qw(ab a\b a\\b);
578 # lexicals declared after the myeval() definition should not be visible
580 sub myeval { eval $_[0] }
582 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
590 # lexicals outside an eval"" should be visible inside subroutine definitions
592 eval <<'EOT'; die $@ if $@;
595 eval 'sub Y { print $X }'; die $@ if $@;
602 # This test is here instead of pragma/locale.t because
603 # the bug depends on in the internal state of the locale
604 # settings and pragma/locale messes up that state pretty badly.
605 # We need a "fresh run".
607 eval { require POSIX };
609 exit(0); # running minitest?
613 my $have_setlocale = $Config{d_setlocale} eq 'define';
614 $have_setlocale = 0 if $@;
615 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
616 # and mingw32 uses said silly CRT
617 $have_setlocale = 0 if $^O eq 'MSWin32' && $Config{cc} =~ /^(cl|gcc)/i;
618 exit(0) unless $have_setlocale;
620 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a|")) {
627 exit(0) unless @locales;
629 use POSIX qw(locale_h);
631 setlocale(LC_NUMERIC, $_) or next;
632 my $s = sprintf "%g %g", 3.1, 3.1;
633 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
640 (?-xism:x) at - line 1.
642 # 20001210.003 mjd@plover.com
643 format REMITOUT_TOP =
651 # This loop causes a segv in 5.6.0
652 for $lineno (1..61) {
676 return eval "sub {shift=~/$pm/}";
678 new_pmop "abcdef"; reset;
679 new_pmop "abcdef"; reset;
680 new_pmop "abcdef"; reset;
681 new_pmop "abcdef"; reset;
689 "x" =~ /(\G?x)?/; # core dump in 20000716.007
691 Quantifier unexpected on zero-length expression in regex; marked by <-- HERE in m/(\G?x)? <-- HERE / at - line 2.
706 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
713 syntax error at - line 2, near "${}"
714 Execution of - aborted due to compilation errors.
719 Missing right brace on \x{} at - line 2, within string
720 Execution of - aborted due to compilation errors.
722 my $foo = Bar->new();
725 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
730 my Bar $self = bless [], Bar;
740 eval "a.b.c.d.e.f;sub"