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.
7 unshift @INC, "../lib";
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 { unlink $tmpfile if $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 print TEST $prog, "\n";
30 close TEST or die "Cannot close $tmpfile: $!";
32 if ($^O eq 'MSWin32') {
33 $results = `.\\perl -I../lib $switch $tmpfile 2>&1`;
36 $results = `./perl $switch $tmpfile 2>&1`;
40 $results =~ s/at\s+misctmp\d+\s+line/at - line/g;
41 $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g;
42 # bison says 'parse error' instead of 'syntax error',
43 # various yaccs may or may not capitalize 'syntax'.
44 $results =~ s/^(syntax|parse) error/syntax error/mig;
45 $expected =~ s/\n+$//;
46 if ( $results ne $expected ) {
47 print STDERR "PROG: $switch\n$prog\n";
48 print STDERR "EXPECTED:\n$expected\n";
49 print STDERR "GOT:\n$results\n";
52 print "ok ", ++$i, "\n";
58 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
62 eval { $q = pack "q", 0 };
64 $cusp = ~0 ^ (~0 >> 1);
66 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, ($cusp + 1) % 8, "!\n";
68 # We are on a 64-bit platform: fake it.
69 # (If we have long doubles we might not need to fake it.)
70 # Background: the $cusp will get converted from a UV into an NV because of
71 # the subtraction and addition. Taking away or adding 1 from such a large
72 # NV doesn't actually change the NV, so the modulo fails.
80 Can't call method "go" on an undefined value at - line 1.
89 $x=0x0eabcd; print $x->ref;
91 Can't call method "ref" without a package or object reference at - line 1.
93 chop ($str .= <DATA>);
97 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
101 eval {sub bar {print "In bar";}}
103 system './perl -ne "print if eof" /dev/null'
105 chop($file = <DATA>);
108 sub new {my ($obj,$n)=@_; bless \$n}
117 Can't modify hash deref in repeat at - line 1, near "0;"
118 Execution of - aborted due to compilation errors.
121 printf(STDOUT "%s\n", $_);
133 sub sub {local($_) = @_;
136 Modification of a read-only value attempted at - line 3.
138 package FOO;sub new {bless {FOO => BAR}};
152 print scalar ("foo","bar")
156 sub by_number { $a <=> $b; };# inline function for sort below
158 @ordered_array=sort by_number keys(%as_ary);
163 my($m2) = $#Shells++;
164 $Shells[$m2]{HOST} = $Host;
173 &ShowShell(&NewShell(beach,Work,"+0+0"));
174 &ShowShell(&NewShell(beach,Work,"+0+0"));
175 &ShowShell(&NewShell(beach,Work,"+0+0"));
181 { print "TIEARRAY @_\n";
182 die "bomb out\n" unless $count ++ ;
185 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
186 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
187 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
190 eval 'tie @h, FAKEARRAY, fred' ;
191 tie @h, FAKEARRAY, fred ;
193 TIEARRAY FAKEARRAY fred
194 TIEARRAY FAKEARRAY fred
197 BEGIN { die "phooey\n" }
200 BEGIN failed--compilation aborted at - line 1.
204 Illegal division by zero at - line 1.
205 BEGIN failed--compilation aborted at - line 1.
209 Modification of a read-only value attempted at - line 1.
210 BEGIN failed--compilation aborted at - line 1.
216 print join(' ', reverse @_)."\n";
221 print sprintf($fmt, @_)."\n";
227 "Out of inspiration";
230 print "and destroyed as well\n";
234 print STDOUT "foo->can(READ)(@_)\n";
239 print STDOUT "Don't GETC, Get Perl\n";
246 print FOO "sentence.", "reversed", "a", "is", "This";
247 print "-- ", <FOO>, " --\n";
248 my($buf,$len,$offset);
250 $len = 10; $offset = 1;
251 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
252 getc(FOO) eq "a" or die "foo->GETC failed";
253 printf "%s is number %d\n", "Perl", 1;
256 This is a reversed sentence.
257 -- Out of inspiration --
258 foo->can(READ)(string 10 1)
261 and destroyed as well
263 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
267 @a = ($a, $b, $c, $d) = (5, 6);
269 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
273 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
277 print "ok\n" if ("\0" lt "\xFF");
281 open(H,'op/misc.t'); # must be in the 't' directory
283 print "ok\n" if (-e _ and -f _ and -r _);
287 sub thing { 0 || return qw(now is the time) }
294 { local $main::{ren} = *stimpy; print $ren, ' ' }
300 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
301 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
306 sub func { print 'really ' unless wantarray; 'p' }
307 sub groovy { 'groovy' }
309 print p::func()->groovy(), "\n"
313 @list = ([ 'one', 1 ], [ 'two', 2 ]);
314 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
315 print scalar(map &func($_), 1 .. 3), " ",
316 scalar(map scalar &func($_), 1 .. 3), "\n";
321 @{$h{$k}} = qw(1 2 4);
322 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
323 print "bogus\n" unless $s == 7;
326 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
327 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
335 eval 'sub foo { print "In foo2\n" }';
336 print "Exiting foo1\n";
342 Subroutine foo redefined at (eval 1) line 1.
347 map {#this newline here tickles the bug
349 print "eat flaming death\n" unless ($s == 7);
351 sub foo { local $_ = shift; split; @_ }
353 print "you die joe!\n" unless "@x" eq 'x y z';
355 /(?{"{"})/ # Check it outside of eval too
357 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
358 /(?{"{"})/: Sequence (?{...}) not terminated or not {}-balanced at - line 1.
360 /(?{"{"}})/ # Check it outside of eval too
362 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
363 syntax error at (re_eval 1) line 1, near ""{"}"
364 Compilation failed in regexp at - line 1.
366 BEGIN { @ARGV = qw(a b c) }
367 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
368 END { print "end <",shift,">\nargv <@ARGV>\n" }
369 INIT { print "init <",shift,">\n" }
378 # fdopen from a system descriptor to a system descriptor used to close
380 open STDERR, '>&=STDOUT' or die $!;
381 select STDOUT; $| = 1; print fileno STDOUT;
382 select STDERR; $| = 1; print fileno STDERR;
388 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
390 Can't localize lexical variable $a at - line 2.
393 sub ascalar { my $r; bless \$r }
394 sub DESTROY { print "destroyed\n" };
401 sub anarray { bless [] }
402 sub DESTROY { print "destroyed\n" };
409 sub ahash { bless {} }
410 sub DESTROY { print "destroyed\n" };
417 sub aclosure { my $x; bless sub { ++$x } }
418 sub DESTROY { print "destroyed\n" };
426 my $f = "FH000"; # just to thwart any future optimisations
427 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
428 sub DESTROY { print "destroyed\n" }
430 $x = any X; # to bump sv_objcount. IO objs aren't counted??
438 $SIG{__WARN__} = sub {
439 eval { print $_[0] };
447 BEGIN failed--compilation aborted at - line 8.
462 print "DESTROY", $self->foo;
469 return $self->{$var};
471 $self->{$var} = shift;
475 $AUTOLOAD =~ /::([^:]+)$/;
477 splice @_, 1, 0, $method;
488 new1new22DESTROY2new33DESTROY31DESTROY1
492 my $re = join '', eval 'qr/(?p{ $obj->method })/';
512 if (@ARGV) { print "" }
514 if ($x == 0) { print "" } else { print $x }
517 Use of uninitialized value at - line 4.