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);
64 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, ($cusp + 1) % 8, "!\n";
70 Can't call method "go" on an undefined value at - line 1.
79 $x=0x0eabcd; print $x->ref;
81 Can't call method "ref" without a package or object reference at - line 1.
83 chop ($str .= <DATA>);
87 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
91 eval {sub bar {print "In bar";}}
93 system './perl -ne "print if eof" /dev/null'
98 sub new {my ($obj,$n)=@_; bless \$n}
107 Can't modify hash dereference in repeat (x) at - line 1, near "0;"
108 Execution of - aborted due to compilation errors.
111 printf(STDOUT "%s\n", $_);
123 sub sub {local($_) = @_;
126 Modification of a read-only value attempted at - line 3.
128 package FOO;sub new {bless {FOO => BAR}};
142 print scalar ("foo","bar")
146 sub by_number { $a <=> $b; };# inline function for sort below
148 @ordered_array=sort by_number keys(%as_ary);
153 my($m2) = $#Shells++;
154 $Shells[$m2]{HOST} = $Host;
163 &ShowShell(&NewShell(beach,Work,"+0+0"));
164 &ShowShell(&NewShell(beach,Work,"+0+0"));
165 &ShowShell(&NewShell(beach,Work,"+0+0"));
171 { print "TIEARRAY @_\n";
172 die "bomb out\n" unless $count ++ ;
175 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
176 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
177 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
180 eval 'tie @h, FAKEARRAY, fred' ;
181 tie @h, FAKEARRAY, fred ;
183 TIEARRAY FAKEARRAY fred
184 TIEARRAY FAKEARRAY fred
187 BEGIN { die "phooey\n" }
190 BEGIN failed--compilation aborted at - line 1.
194 Illegal division by zero at - line 1.
195 BEGIN failed--compilation aborted at - line 1.
199 Modification of a read-only value attempted at - line 1.
200 BEGIN failed--compilation aborted at - line 1.
206 print join(' ', reverse @_)."\n";
211 print sprintf($fmt, @_)."\n";
217 "Out of inspiration";
220 print "and destroyed as well\n";
224 print STDOUT "foo->can(READ)(@_)\n";
229 print STDOUT "Don't GETC, Get Perl\n";
236 print FOO "sentence.", "reversed", "a", "is", "This";
237 print "-- ", <FOO>, " --\n";
238 my($buf,$len,$offset);
240 $len = 10; $offset = 1;
241 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
242 getc(FOO) eq "a" or die "foo->GETC failed";
243 printf "%s is number %d\n", "Perl", 1;
246 This is a reversed sentence.
247 -- Out of inspiration --
248 foo->can(READ)(string 10 1)
251 and destroyed as well
253 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
257 @a = ($a, $b, $c, $d) = (5, 6);
259 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
263 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
267 print "ok\n" if ("\0" lt "\xFF");
271 open(H,'op/misc.t'); # must be in the 't' directory
273 print "ok\n" if (-e _ and -f _ and -r _);
277 sub thing { 0 || return qw(now is the time) }
284 { local $main::{ren} = *stimpy; print $ren, ' ' }
290 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
291 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
296 sub func { print 'really ' unless wantarray; 'p' }
297 sub groovy { 'groovy' }
299 print p::func()->groovy(), "\n"
303 @list = ([ 'one', 1 ], [ 'two', 2 ]);
304 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
305 print scalar(map &func($_), 1 .. 3), " ",
306 scalar(map scalar &func($_), 1 .. 3), "\n";
311 @{$h{$k}} = qw(1 2 4);
312 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
313 print "bogus\n" unless $s == 7;
316 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
317 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
325 eval 'sub foo { print "In foo2\n" }';
326 print "Exiting foo1\n";
332 Subroutine foo redefined at (eval 1) line 1.
337 map {#this newline here tickles the bug
339 print "eat flaming death\n" unless ($s == 7);
341 sub foo { local $_ = shift; split; @_ }
343 print "you die joe!\n" unless "@x" eq 'x y z';
345 /(?{"{"})/ # Check it outside of eval too
347 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
348 /(?{"{"})/: Sequence (?{...}) not terminated or not {}-balanced at - line 1.
350 /(?{"{"}})/ # Check it outside of eval too
352 Unmatched right curly bracket at (re_eval 1) line 1, at end of line
353 syntax error at (re_eval 1) line 1, near ""{"}"
354 Compilation failed in regexp at - line 1.
356 BEGIN { @ARGV = qw(a b c) }
357 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
358 END { print "end <",shift,">\nargv <@ARGV>\n" }
359 INIT { print "init <",shift,">\n" }
368 # fdopen from a system descriptor to a system descriptor used to close
370 open STDERR, '>&=STDOUT' or die $!;
371 select STDOUT; $| = 1; print fileno STDOUT;
372 select STDERR; $| = 1; print fileno STDERR;
378 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
380 Can't localize lexical variable $a at - line 2.
383 sub ascalar { my $r; bless \$r }
384 sub DESTROY { print "destroyed\n" };
391 sub anarray { bless [] }
392 sub DESTROY { print "destroyed\n" };
399 sub ahash { bless {} }
400 sub DESTROY { print "destroyed\n" };
407 sub aclosure { my $x; bless sub { ++$x } }
408 sub DESTROY { print "destroyed\n" };
416 my $f = "FH000"; # just to thwart any future optimisations
417 sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
418 sub DESTROY { print "destroyed\n" }
420 $x = any X; # to bump sv_objcount. IO objs aren't counted??
428 $SIG{__WARN__} = sub {
429 eval { print $_[0] };
437 BEGIN failed--compilation aborted at - line 8.
452 print "DESTROY", $self->foo;
459 return $self->{$var};
461 $self->{$var} = shift;
465 $AUTOLOAD =~ /::([^:]+)$/;
467 splice @_, 1, 0, $method;
478 new1new22DESTROY2new33DESTROY31DESTROY1
482 my $re = join '', eval 'qr/(?p{ $obj->method })/';
502 if (@ARGV) { print "" }
504 if ($x == 0) { print "" } else { print $x }
507 Use of uninitialized value at - line 4.