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 $results =~ s/\n\n/\n/ if $^O eq 'VMS'; # pipes double these sometimes
52 $expected =~ s/\n+$//;
53 if ( $results ne $expected ) {
54 print STDERR "PROG: $switch\n$prog\n";
55 print STDERR "EXPECTED:\n$expected\n";
56 print STDERR "GOT:\n$results\n";
59 print "ok ", ++$i, "\n";
65 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
69 $cusp = ~0 ^ (~0 >> 1);
72 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
78 Can't call method "go" on an undefined value at - line 1.
87 $x=0x0eabcd; print $x->ref;
89 Can't call method "ref" without a package or object reference at - line 1.
91 chop ($str .= <DATA>);
95 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
99 eval {sub bar {print "In bar";}}
101 system './perl -ne "print if eof" /dev/null'
103 chop($file = <DATA>);
106 sub new {my ($obj,$n)=@_; bless \$n}
115 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
116 Execution of - aborted due to compilation errors.
119 printf(STDOUT "%s\n", $_);
131 sub sub {local($_) = @_;
134 Modification of a read-only value attempted at - line 3.
136 package FOO;sub new {bless {FOO => BAR}};
150 print scalar ("foo","bar")
154 sub by_number { $a <=> $b; };# inline function for sort below
156 @ordered_array=sort by_number keys(%as_ary);
161 my($m2) = $#Shells++;
162 $Shells[$m2]{HOST} = $Host;
171 &ShowShell(&NewShell(beach,Work,"+0+0"));
172 &ShowShell(&NewShell(beach,Work,"+0+0"));
173 &ShowShell(&NewShell(beach,Work,"+0+0"));
179 { print "TIEARRAY @_\n";
180 die "bomb out\n" unless $count ++ ;
183 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
184 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
185 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
188 eval 'tie @h, FAKEARRAY, fred' ;
189 tie @h, FAKEARRAY, fred ;
191 TIEARRAY FAKEARRAY fred
192 TIEARRAY FAKEARRAY fred
195 BEGIN { die "phooey\n" }
198 BEGIN failed--compilation aborted at - line 1.
202 Illegal division by zero at - line 1.
203 BEGIN failed--compilation aborted at - line 1.
207 Modification of a read-only value attempted at - line 1.
208 BEGIN failed--compilation aborted at - line 1.
214 print join(' ', reverse @_)."\n";
219 print sprintf($fmt, @_)."\n";
225 "Out of inspiration";
228 print "and destroyed as well\n";
232 print STDOUT "foo->can(READ)(@_)\n";
237 print STDOUT "Don't GETC, Get Perl\n";
244 print FOO "sentence.", "reversed", "a", "is", "This";
245 print "-- ", <FOO>, " --\n";
246 my($buf,$len,$offset);
248 $len = 10; $offset = 1;
249 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
250 getc(FOO) eq "a" or die "foo->GETC failed";
251 printf "%s is number %d\n", "Perl", 1;
254 This is a reversed sentence.
255 -- Out of inspiration --
256 foo->can(READ)(string 10 1)
259 and destroyed as well
261 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
265 # used to attach defelem magic to all immortal values,
266 # which made restore of local $_ fail.
268 sub foo { bar() for @_; }
269 sub bar { local $_; }
274 @a = ($a, $b, $c, $d) = (5, 6);
276 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
280 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
284 print "ok\n" if ("\0" lt "\xFF");
288 open(H,'op/misc.t'); # must be in the 't' directory
290 print "ok\n" if (-e _ and -f _ and -r _);
294 sub thing { 0 || return qw(now is the time) }
301 { local $main::{ren} = *stimpy; print $ren, ' ' }
307 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
308 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
313 sub func { print 'really ' unless wantarray; 'p' }
314 sub groovy { 'groovy' }
316 print p::func()->groovy(), "\n"
320 @list = ([ 'one', 1 ], [ 'two', 2 ]);
321 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
322 print scalar(map &func($_), 1 .. 3), " ",
323 scalar(map scalar &func($_), 1 .. 3), "\n";
328 @{$h{$k}} = qw(1 2 4);
329 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
330 print "bogus\n" unless $s == 7;
333 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
334 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
342 eval 'sub foo { print "In foo2\n" }';
343 print "Exiting foo1\n";
349 Subroutine foo redefined at (eval 1) line 1.
354 map {#this newline here tickles the bug
356 print "eat flaming death\n" unless ($s == 7);
358 sub foo { local $_ = shift; split; @_ }
360 print "you die joe!\n" unless "@x" eq 'x y z';
362 /(?{"{"})/ # Check it outside of eval too
364 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
365 Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
367 /(?{"{"}})/ # Check it outside of eval too
369 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
370 syntax error at (re_eval 1) line 1, near ""{"}"
371 Compilation failed in regexp at - line 1.
373 BEGIN { @ARGV = qw(a b c d e) }
374 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
375 END { print "end <",shift,">\nargv <@ARGV>\n" }
376 INIT { print "init <",shift,">\n" }
377 CHECK { print "check <",shift,">\n" }
387 # fdopen from a system descriptor to a system descriptor used to close
389 open STDERR, '>&=STDOUT' or die $!;
390 select STDOUT; $| = 1; print fileno STDOUT or die $!;
391 select STDERR; $| = 1; print fileno STDERR or die $!;
397 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
399 Can't localize lexical variable $a at - line 2.
402 sub ascalar { my $r; bless \$r }
403 sub DESTROY { print "destroyed\n" };
410 sub anarray { bless [] }
411 sub DESTROY { print "destroyed\n" };
418 sub ahash { bless {} }
419 sub DESTROY { print "destroyed\n" };
426 sub aclosure { my $x; bless sub { ++$x } }
427 sub DESTROY { print "destroyed\n" };
435 my $f = "FH000"; # just to thwart any future optimisations
436 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
437 sub DESTROY { print "destroyed\n" }
439 $x = any X; # to bump sv_objcount. IO objs aren't counted??
447 $SIG{__WARN__} = sub {
448 eval { print $_[0] };
456 BEGIN failed--compilation aborted at - line 8.
471 print "DESTROY", $self->foo;
478 return $self->{$var};
480 $self->{$var} = shift;
484 $AUTOLOAD =~ /::([^:]+)$/;
486 splice @_, 1, 0, $method;
497 new1new22DESTROY2new33DESTROY31DESTROY1
501 my $re = join '', eval 'qr/(??{ $obj->method })/';
521 if (@ARGV) { print "" }
523 if ($x == 0) { print "" } else { print $x }
526 Use of uninitialized value in numeric eq (==) at - line 4.
530 sub foo { eval { return }; }
538 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
540 { f } continue { print $x, "\n" }
549 Modification of a read-only value attempted at - line 2.
551 print qw(ab a\b a\\b);
555 # lexicals declared after the myeval() definition should not be visible
557 sub myeval { eval $_[0] }
559 myeval('sub foo { local $foo = "ok 1\n"; print $foo; }');
567 # lexicals outside an eval"" should be visible inside subroutine definitions
569 eval <<'EOT'; die $@ if $@;
572 eval 'sub Y { print $X }'; die $@ if $@;
579 # test that closures generated by eval"" hold on to the CV of the eval""
580 # for their entire lifetime
582 sub { eval '$x = "ok 1\n"'; }
589 # This test is here instead of pragma/locale.t because
590 # the bug depends on in the internal state of the locale
591 # settings and pragma/locale messes up that state pretty badly.
592 # We need a "fresh run".
594 eval { require POSIX };
596 exit(0); # running minitest?
600 my $have_setlocale = $Config{d_setlocale} eq 'define';
601 $have_setlocale = 0 if $@;
602 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
603 # and mingw32 uses said silly CRT
604 $have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
605 exit(0) unless $have_setlocale;
607 if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a|")) {
614 exit(0) unless @locales;
616 use POSIX qw(locale_h);
618 setlocale(LC_NUMERIC, $_) or next;
619 my $s = sprintf "%g %g", 3.1, 3.1;
620 next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
627 (?-xism:x) at - line 1.
629 # 20001210.003 mjd@plover.com
630 format REMITOUT_TOP =
638 # This loop causes a segv in 5.6.0
639 for $lineno (1..61) {
663 return eval "sub {shift=~/$pm/}";
665 new_pmop "abcdef"; reset;
666 new_pmop "abcdef"; reset;
667 new_pmop "abcdef"; reset;
668 new_pmop "abcdef"; reset;
676 "x" =~ /(\G?x)?/; # core dump in 20000716.007
678 Quantifier unexpected on zero-length expression in regex; marked by <-- HERE in m/(\G?x)? <-- HERE / at - line 2.
693 "abcd\x{1234}" =~ /(a)(b[c])(d+)?/i and print "ok\n";
700 syntax error at - line 2, near "${}"
701 Execution of - aborted due to compilation errors.
706 Missing right brace on \x{} at - line 2, within string
707 Execution of - aborted due to compilation errors.
709 my $foo = Bar->new();
712 ($_ = "@dst") =~ s/\(0x.+?\)/(0x...)/;
717 my Bar $self = bless [], Bar;
727 eval "a.b.c.d.e.f;sub"