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 $cusp = ~0 ^ (~0 >> 1);
65 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
71 Can't call method "go" on an undefined value at - line 1.
80 $x=0x0eabcd; print $x->ref;
82 Can't call method "ref" without a package or object reference at - line 1.
84 chop ($str .= <DATA>);
88 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
92 eval {sub bar {print "In bar";}}
94 system './perl -ne "print if eof" /dev/null'
99 sub new {my ($obj,$n)=@_; bless \$n}
108 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
109 Execution of - aborted due to compilation errors.
112 printf(STDOUT "%s\n", $_);
124 sub sub {local($_) = @_;
127 Modification of a read-only value attempted at - line 3.
129 package FOO;sub new {bless {FOO => BAR}};
143 print scalar ("foo","bar")
147 sub by_number { $a <=> $b; };# inline function for sort below
149 @ordered_array=sort by_number keys(%as_ary);
154 my($m2) = $#Shells++;
155 $Shells[$m2]{HOST} = $Host;
164 &ShowShell(&NewShell(beach,Work,"+0+0"));
165 &ShowShell(&NewShell(beach,Work,"+0+0"));
166 &ShowShell(&NewShell(beach,Work,"+0+0"));
172 { print "TIEARRAY @_\n";
173 die "bomb out\n" unless $count ++ ;
176 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
177 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
178 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
181 eval 'tie @h, FAKEARRAY, fred' ;
182 tie @h, FAKEARRAY, fred ;
184 TIEARRAY FAKEARRAY fred
185 TIEARRAY FAKEARRAY fred
188 BEGIN { die "phooey\n" }
191 BEGIN failed--compilation aborted at - line 1.
195 Illegal division by zero at - line 1.
196 BEGIN failed--compilation aborted at - line 1.
200 Modification of a read-only value attempted at - line 1.
201 BEGIN failed--compilation aborted at - line 1.
207 print join(' ', reverse @_)."\n";
212 print sprintf($fmt, @_)."\n";
218 "Out of inspiration";
221 print "and destroyed as well\n";
225 print STDOUT "foo->can(READ)(@_)\n";
230 print STDOUT "Don't GETC, Get Perl\n";
237 print FOO "sentence.", "reversed", "a", "is", "This";
238 print "-- ", <FOO>, " --\n";
239 my($buf,$len,$offset);
241 $len = 10; $offset = 1;
242 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
243 getc(FOO) eq "a" or die "foo->GETC failed";
244 printf "%s is number %d\n", "Perl", 1;
247 This is a reversed sentence.
248 -- Out of inspiration --
249 foo->can(READ)(string 10 1)
252 and destroyed as well
254 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
258 @a = ($a, $b, $c, $d) = (5, 6);
260 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
264 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
268 print "ok\n" if ("\0" lt "\xFF");
272 open(H,'op/misc.t'); # must be in the 't' directory
274 print "ok\n" if (-e _ and -f _ and -r _);
278 sub thing { 0 || return qw(now is the time) }
285 { local $main::{ren} = *stimpy; print $ren, ' ' }
291 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
292 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
297 sub func { print 'really ' unless wantarray; 'p' }
298 sub groovy { 'groovy' }
300 print p::func()->groovy(), "\n"
304 @list = ([ 'one', 1 ], [ 'two', 2 ]);
305 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
306 print scalar(map &func($_), 1 .. 3), " ",
307 scalar(map scalar &func($_), 1 .. 3), "\n";
312 @{$h{$k}} = qw(1 2 4);
313 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
314 print "bogus\n" unless $s == 7;
317 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
318 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
326 eval 'sub foo { print "In foo2\n" }';
327 print "Exiting foo1\n";
333 Subroutine foo redefined at (eval 1) line 1.
338 map {#this newline here tickles the bug
340 print "eat flaming death\n" unless ($s == 7);
342 sub foo { local $_ = shift; split; @_ }
344 print "you die joe!\n" unless "@x" eq 'x y z';
346 /(?{"{"})/ # Check it outside of eval too
348 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
349 /(?{"{"})/: Sequence (?{...}) not terminated or not {}-balanced at - line 1.
351 /(?{"{"}})/ # Check it outside of eval too
353 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
354 syntax error at (re_eval 1) line 1, near ""{"}"
355 Compilation failed in regexp at - line 1.
357 BEGIN { @ARGV = qw(a b c d e) }
358 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
359 END { print "end <",shift,">\nargv <@ARGV>\n" }
360 INIT { print "init <",shift,">\n" }
361 CHECK { print "check <",shift,">\n" }
371 # fdopen from a system descriptor to a system descriptor used to close
373 open STDERR, '>&=STDOUT' or die $!;
374 select STDOUT; $| = 1; print fileno STDOUT;
375 select STDERR; $| = 1; print fileno STDERR;
381 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
383 Can't localize lexical variable $a at - line 2.
386 sub ascalar { my $r; bless \$r }
387 sub DESTROY { print "destroyed\n" };
394 sub anarray { bless [] }
395 sub DESTROY { print "destroyed\n" };
402 sub ahash { bless {} }
403 sub DESTROY { print "destroyed\n" };
410 sub aclosure { my $x; bless sub { ++$x } }
411 sub DESTROY { print "destroyed\n" };
419 my $f = "FH000"; # just to thwart any future optimisations
420 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
421 sub DESTROY { print "destroyed\n" }
423 $x = any X; # to bump sv_objcount. IO objs aren't counted??
431 $SIG{__WARN__} = sub {
432 eval { print $_[0] };
440 BEGIN failed--compilation aborted at - line 8.
455 print "DESTROY", $self->foo;
462 return $self->{$var};
464 $self->{$var} = shift;
468 $AUTOLOAD =~ /::([^:]+)$/;
470 splice @_, 1, 0, $method;
481 new1new22DESTROY2new33DESTROY31DESTROY1
485 my $re = join '', eval 'qr/(??{ $obj->method })/';
505 if (@ARGV) { print "" }
507 if ($x == 0) { print "" } else { print $x }
510 Use of uninitialized value in numeric eq (==) at - line 4.
514 sub foo { eval { return }; }
519 my @l = qw(hello.* world);
523 print "before - $x\n";
525 print "quotemeta - $x\n";
527 print "ucfirst - $x\n";
529 print "lcfirst - $x\n";
537 quotemeta - hello\.\*
549 sub f { my $a = 1; my $b = 2; my $c = 3; my $d = 4; next }
551 { f } continue { print $x, "\n" }