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 if ($^O eq 'MSWin32') {
29 open TEST, "| .\\perl -I../lib $switch >$tmpfile 2>&1";
32 open TEST, "| sh -c './perl $switch' >$tmpfile 2>&1";
34 print TEST $prog, "\n";
37 $results = `$CAT $tmpfile`;
39 # bison says 'parse error' instead of 'syntax error',
40 # various yaccs may or may not capitalize 'syntax'.
41 $results =~ s/^(syntax|parse) error/syntax error/mig;
42 $expected =~ s/\n+$//;
43 if ( $results ne $expected ) {
44 print STDERR "PROG: $switch\n$prog\n";
45 print STDERR "EXPECTED:\n$expected\n";
46 print STDERR "GOT:\n$results\n";
49 print "ok ", ++$i, "\n";
55 $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
59 $cusp = ~0 ^ (~0 >> 1);
61 print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, ($cusp + 1) % 8, "!\n";
67 Can't call method "go" on an undefined value at - line 1.
76 $x=0x0eabcd; print $x->ref;
78 Can't call method "ref" without a package or object reference at - line 1.
80 chop ($str .= <STDIN>);
84 $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
88 eval {sub bar {print "In bar";}}
90 system './perl -ne "print if eof" /dev/null'
95 sub new {my ($obj,$n)=@_; bless \$n}
104 Can't modify hash deref in repeat at - line 1, near "0;"
105 Execution of - aborted due to compilation errors.
108 printf(STDOUT "%s\n", $_);
120 sub sub {local($_) = @_;
123 Modification of a read-only value attempted at - line 3.
125 package FOO;sub new {bless {FOO => BAR}};
139 print scalar ("foo","bar")
143 sub by_number { $a <=> $b; };# inline function for sort below
145 @ordered_array=sort by_number keys(%as_ary);
150 my($m2) = $#Shells++;
151 $Shells[$m2]{HOST} = $Host;
160 &ShowShell(&NewShell(beach,Work,"+0+0"));
161 &ShowShell(&NewShell(beach,Work,"+0+0"));
162 &ShowShell(&NewShell(beach,Work,"+0+0"));
168 { print "TIEARRAY @_\n";
169 die "bomb out\n" unless $count ++ ;
172 sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
173 sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
174 sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
177 eval 'tie @h, FAKEARRAY, fred' ;
178 tie @h, FAKEARRAY, fred ;
180 TIEARRAY FAKEARRAY fred
181 TIEARRAY FAKEARRAY fred
184 BEGIN { die "phooey\n" }
187 BEGIN failed--compilation aborted at - line 1.
191 Illegal division by zero at - line 1.
192 BEGIN failed--compilation aborted at - line 1.
196 Modification of a read-only value attempted at - line 1.
197 BEGIN failed--compilation aborted at - line 1.
203 print join(' ', reverse @_)."\n";
208 print sprintf($fmt, @_)."\n";
214 "Out of inspiration";
217 print "and destroyed as well\n";
221 print STDOUT "foo->can(READ)(@_)\n";
226 print STDOUT "Don't GETC, Get Perl\n";
233 print FOO "sentence.", "reversed", "a", "is", "This";
234 print "-- ", <FOO>, " --\n";
235 my($buf,$len,$offset);
237 $len = 10; $offset = 1;
238 read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
239 getc(FOO) eq "a" or die "foo->GETC failed";
240 printf "%s is number %d\n", "Perl", 1;
243 This is a reversed sentence.
244 -- Out of inspiration --
245 foo->can(READ)(string 10 1)
248 and destroyed as well
250 my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
254 @a = ($a, $b, $c, $d) = (5, 6);
256 if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
260 print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
264 print "ok\n" if ("\0" lt "\xFF");
268 open(H,'op/misc.t'); # must be in the 't' directory
270 print "ok\n" if (-e _ and -f _ and -r _);
274 sub thing { 0 || return qw(now is the time) }
281 { local $main::{ren} = *stimpy; print $ren, ' ' }
287 { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
288 print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
293 sub func { print 'really ' unless wantarray; 'p' }
294 sub groovy { 'groovy' }
296 print p::func()->groovy(), "\n"
300 @list = ([ 'one', 1 ], [ 'two', 2 ]);
301 sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
302 print scalar(map &func($_), 1 .. 3), " ",
303 scalar(map scalar &func($_), 1 .. 3), "\n";
308 @{$h{$k}} = qw(1 2 4);
309 for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
310 print "bogus\n" unless $s == 7;
313 eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
314 eval { my $x = 'peace'; eval q[ print "$x\n" ] }
322 eval 'sub foo { print "In foo2\n" }';
323 print "Exiting foo1\n";
329 Subroutine foo redefined at (eval 1) line 1.
334 map {#this newline here tickles the bug
336 print "eat flaming death\n" unless ($s == 7);
338 sub foo { local $_ = shift; split; @_ }
340 print "you die joe!\n" unless "@x" eq 'x y z';
342 /(?{"{"})/ # Check it outside of eval too
344 Sequence (?{...}) not terminated or not {}-balanced at - line 1, within pattern
345 /(?{"{"})/: Sequence (?{...}) not terminated or not {}-balanced at - line 1.
347 /(?{"{"}})/ # Check it outside of eval too
349 Unmatched right bracket at (re_eval 1) line 1, at end of line
350 syntax error at (re_eval 1) line 1, near ""{"}"
351 Compilation failed in regexp at - line 1.
353 BEGIN { @ARGV = qw(a b c) }
354 BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
355 END { print "end <",shift,">\nargv <@ARGV>\n" }
356 INIT { print "init <",shift,">\n" }
365 # fdopen from a system descriptor to a system descriptor used to close
367 open STDERR, '>&=STDOUT' or die $!;
368 select STDOUT; $| = 1; print fileno STDOUT;
369 select STDERR; $| = 1; print fileno STDERR;
375 sub testme { my $a = "test"; { local $a = "new test"; print $a }}
377 Can't localize lexical variable $a at - line 2.
380 sub ascalar { my $r; bless \$r }
381 sub DESTROY { print "destroyed\n" };
388 sub anarray { bless [] }
389 sub DESTROY { print "destroyed\n" };
396 sub ahash { bless {} }
397 sub DESTROY { print "destroyed\n" };
404 sub aclosure { my $x; bless sub { ++$x } }
405 sub DESTROY { print "destroyed\n" };
413 my $f = "FH000"; # just to thwart any future optimisations
415 open(++$f, '>&STDOUT') or die;
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