| 1 | #!./perl
|
|---|
| 2 |
|
|---|
| 3 | # ** DO NOT ADD ANY MORE TESTS HERE **
|
|---|
| 4 | # Instead, put the test in the appropriate test file and use the
|
|---|
| 5 | # fresh_perl_is()/fresh_perl_like() functions in t/test.pl.
|
|---|
| 6 |
|
|---|
| 7 | # This is for tests that used to abnormally cause segfaults, and other nasty
|
|---|
| 8 | # errors that might kill the interpreter and for some reason you can't
|
|---|
| 9 | # use an eval().
|
|---|
| 10 |
|
|---|
| 11 | BEGIN {
|
|---|
| 12 | chdir 't' if -d 't';
|
|---|
| 13 | @INC = '../lib';
|
|---|
| 14 | require './test.pl'; # for which_perl() etc
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | use strict;
|
|---|
| 18 |
|
|---|
| 19 | my $Perl = which_perl();
|
|---|
| 20 |
|
|---|
| 21 | $|=1;
|
|---|
| 22 |
|
|---|
| 23 | my @prgs = ();
|
|---|
| 24 | while(<DATA>) {
|
|---|
| 25 | if(m/^#{8,}\s*(.*)/) {
|
|---|
| 26 | push @prgs, ['', $1];
|
|---|
| 27 | }
|
|---|
| 28 | else {
|
|---|
| 29 | $prgs[-1][0] .= $_;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | plan tests => scalar @prgs;
|
|---|
| 33 |
|
|---|
| 34 | foreach my $prog (@prgs) {
|
|---|
| 35 | my($raw_prog, $name) = @$prog;
|
|---|
| 36 |
|
|---|
| 37 | my $switch;
|
|---|
| 38 | if ($raw_prog =~ s/^\s*(-\w.*)\n//){
|
|---|
| 39 | $switch = $1;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | my($prog,$expected) = split(/\nEXPECT\n/, $raw_prog);
|
|---|
| 43 | $prog .= "\n";
|
|---|
| 44 | $expected = '' unless defined $expected;
|
|---|
| 45 |
|
|---|
| 46 | if ($prog =~ /^\# SKIP: (.+)/m) {
|
|---|
| 47 | if (eval $1) {
|
|---|
| 48 | ok(1, "Skip: $1");
|
|---|
| 49 | next;
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | $expected =~ s/\n+$//;
|
|---|
| 54 |
|
|---|
| 55 | fresh_perl_is($prog, $expected, { switches => [$switch || ''] }, $name);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | __END__
|
|---|
| 59 | ########
|
|---|
| 60 | $a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
|
|---|
| 61 | EXPECT
|
|---|
| 62 | a := b := c
|
|---|
| 63 | ########
|
|---|
| 64 | $cusp = ~0 ^ (~0 >> 1);
|
|---|
| 65 | use integer;
|
|---|
| 66 | $, = " ";
|
|---|
| 67 | print +($cusp - 1) % 8, $cusp % 8, -$cusp % 8, 8 | (($cusp + 1) % 8 + 7), "!\n";
|
|---|
| 68 | EXPECT
|
|---|
| 69 | 7 0 0 8 !
|
|---|
| 70 | ########
|
|---|
| 71 | $foo=undef; $foo->go;
|
|---|
| 72 | EXPECT
|
|---|
| 73 | Can't call method "go" on an undefined value at - line 1.
|
|---|
| 74 | ########
|
|---|
| 75 | BEGIN
|
|---|
| 76 | {
|
|---|
| 77 | "foo";
|
|---|
| 78 | }
|
|---|
| 79 | ########
|
|---|
| 80 | $array[128]=1
|
|---|
| 81 | ########
|
|---|
| 82 | $x=0x0eabcd; print $x->ref;
|
|---|
| 83 | EXPECT
|
|---|
| 84 | Can't call method "ref" without a package or object reference at - line 1.
|
|---|
| 85 | ########
|
|---|
| 86 | chop ($str .= <DATA>);
|
|---|
| 87 | ########
|
|---|
| 88 | close ($banana);
|
|---|
| 89 | ########
|
|---|
| 90 | $x=2;$y=3;$x<$y ? $x : $y += 23;print $x;
|
|---|
| 91 | EXPECT
|
|---|
| 92 | 25
|
|---|
| 93 | ########
|
|---|
| 94 | eval 'sub bar {print "In bar"}';
|
|---|
| 95 | ########
|
|---|
| 96 | system './perl -ne "print if eof" /dev/null' unless $^O eq 'MacOS'
|
|---|
| 97 | ########
|
|---|
| 98 | chop($file = <DATA>);
|
|---|
| 99 | ########
|
|---|
| 100 | package N;
|
|---|
| 101 | sub new {my ($obj,$n)=@_; bless \$n}
|
|---|
| 102 | $aa=new N 1;
|
|---|
| 103 | $aa=12345;
|
|---|
| 104 | print $aa;
|
|---|
| 105 | EXPECT
|
|---|
| 106 | 12345
|
|---|
| 107 | ########
|
|---|
| 108 | $_="foo";
|
|---|
| 109 | printf(STDOUT "%s\n", $_);
|
|---|
| 110 | EXPECT
|
|---|
| 111 | foo
|
|---|
| 112 | ########
|
|---|
| 113 | push(@a, 1, 2, 3,)
|
|---|
| 114 | ########
|
|---|
| 115 | quotemeta ""
|
|---|
| 116 | ########
|
|---|
| 117 | for ("ABCDE") {
|
|---|
| 118 | ⊂
|
|---|
| 119 | s/./&sub($&)/eg;
|
|---|
| 120 | print;}
|
|---|
| 121 | sub sub {local($_) = @_;
|
|---|
| 122 | $_ x 4;}
|
|---|
| 123 | EXPECT
|
|---|
| 124 | Modification of a read-only value attempted at - line 3.
|
|---|
| 125 | ########
|
|---|
| 126 | package FOO;sub new {bless {FOO => BAR}};
|
|---|
| 127 | package main;
|
|---|
| 128 | use strict vars;
|
|---|
| 129 | my $self = new FOO;
|
|---|
| 130 | print $$self{FOO};
|
|---|
| 131 | EXPECT
|
|---|
| 132 | BAR
|
|---|
| 133 | ########
|
|---|
| 134 | $_="foo";
|
|---|
| 135 | s/.{1}//s;
|
|---|
| 136 | print;
|
|---|
| 137 | EXPECT
|
|---|
| 138 | oo
|
|---|
| 139 | ########
|
|---|
| 140 | print scalar ("foo","bar")
|
|---|
| 141 | EXPECT
|
|---|
| 142 | bar
|
|---|
| 143 | ########
|
|---|
| 144 | sub by_number { $a <=> $b; };# inline function for sort below
|
|---|
| 145 | $as_ary{0}="a0";
|
|---|
| 146 | @ordered_array=sort by_number keys(%as_ary);
|
|---|
| 147 | ########
|
|---|
| 148 | sub NewShell
|
|---|
| 149 | {
|
|---|
| 150 | local($Host) = @_;
|
|---|
| 151 | my($m2) = $#Shells++;
|
|---|
| 152 | $Shells[$m2]{HOST} = $Host;
|
|---|
| 153 | return $m2;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | sub ShowShell
|
|---|
| 157 | {
|
|---|
| 158 | local($i) = @_;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | &ShowShell(&NewShell(beach,Work,"+0+0"));
|
|---|
| 162 | &ShowShell(&NewShell(beach,Work,"+0+0"));
|
|---|
| 163 | &ShowShell(&NewShell(beach,Work,"+0+0"));
|
|---|
| 164 | ########
|
|---|
| 165 | {
|
|---|
| 166 | package FAKEARRAY;
|
|---|
| 167 |
|
|---|
| 168 | sub TIEARRAY
|
|---|
| 169 | { print "TIEARRAY @_\n";
|
|---|
| 170 | die "bomb out\n" unless $count ++ ;
|
|---|
| 171 | bless ['foo']
|
|---|
| 172 | }
|
|---|
| 173 | sub FETCH { print "fetch @_\n"; $_[0]->[$_[1]] }
|
|---|
| 174 | sub STORE { print "store @_\n"; $_[0]->[$_[1]] = $_[2] }
|
|---|
| 175 | sub DESTROY { print "DESTROY \n"; undef @{$_[0]}; }
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | eval 'tie @h, FAKEARRAY, fred' ;
|
|---|
| 179 | tie @h, FAKEARRAY, fred ;
|
|---|
| 180 | EXPECT
|
|---|
| 181 | TIEARRAY FAKEARRAY fred
|
|---|
| 182 | TIEARRAY FAKEARRAY fred
|
|---|
| 183 | DESTROY
|
|---|
| 184 | ########
|
|---|
| 185 | BEGIN { die "phooey\n" }
|
|---|
| 186 | EXPECT
|
|---|
| 187 | phooey
|
|---|
| 188 | BEGIN failed--compilation aborted at - line 1.
|
|---|
| 189 | ########
|
|---|
| 190 | BEGIN { 1/$zero }
|
|---|
| 191 | EXPECT
|
|---|
| 192 | Illegal division by zero at - line 1.
|
|---|
| 193 | BEGIN failed--compilation aborted at - line 1.
|
|---|
| 194 | ########
|
|---|
| 195 | BEGIN { undef = 0 }
|
|---|
| 196 | EXPECT
|
|---|
| 197 | Modification of a read-only value attempted at - line 1.
|
|---|
| 198 | BEGIN failed--compilation aborted at - line 1.
|
|---|
| 199 | ########
|
|---|
| 200 | {
|
|---|
| 201 | package foo;
|
|---|
| 202 | sub PRINT {
|
|---|
| 203 | shift;
|
|---|
| 204 | print join(' ', reverse @_)."\n";
|
|---|
| 205 | }
|
|---|
| 206 | sub PRINTF {
|
|---|
| 207 | shift;
|
|---|
| 208 | my $fmt = shift;
|
|---|
| 209 | print sprintf($fmt, @_)."\n";
|
|---|
| 210 | }
|
|---|
| 211 | sub TIEHANDLE {
|
|---|
| 212 | bless {}, shift;
|
|---|
| 213 | }
|
|---|
| 214 | sub READLINE {
|
|---|
| 215 | "Out of inspiration";
|
|---|
| 216 | }
|
|---|
| 217 | sub DESTROY {
|
|---|
| 218 | print "and destroyed as well\n";
|
|---|
| 219 | }
|
|---|
| 220 | sub READ {
|
|---|
| 221 | shift;
|
|---|
| 222 | print STDOUT "foo->can(READ)(@_)\n";
|
|---|
| 223 | return 100;
|
|---|
| 224 | }
|
|---|
| 225 | sub GETC {
|
|---|
| 226 | shift;
|
|---|
| 227 | print STDOUT "Don't GETC, Get Perl\n";
|
|---|
| 228 | return "a";
|
|---|
| 229 | }
|
|---|
| 230 | }
|
|---|
| 231 | {
|
|---|
| 232 | local(*FOO);
|
|---|
| 233 | tie(*FOO,'foo');
|
|---|
| 234 | print FOO "sentence.", "reversed", "a", "is", "This";
|
|---|
| 235 | print "-- ", <FOO>, " --\n";
|
|---|
| 236 | my($buf,$len,$offset);
|
|---|
| 237 | $buf = "string";
|
|---|
| 238 | $len = 10; $offset = 1;
|
|---|
| 239 | read(FOO, $buf, $len, $offset) == 100 or die "foo->READ failed";
|
|---|
| 240 | getc(FOO) eq "a" or die "foo->GETC failed";
|
|---|
| 241 | printf "%s is number %d\n", "Perl", 1;
|
|---|
| 242 | }
|
|---|
| 243 | EXPECT
|
|---|
| 244 | This is a reversed sentence.
|
|---|
| 245 | -- Out of inspiration --
|
|---|
| 246 | foo->can(READ)(string 10 1)
|
|---|
| 247 | Don't GETC, Get Perl
|
|---|
| 248 | Perl is number 1
|
|---|
| 249 | and destroyed as well
|
|---|
| 250 | ########
|
|---|
| 251 | my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n"
|
|---|
| 252 | EXPECT
|
|---|
| 253 | 2 2 2
|
|---|
| 254 | ########
|
|---|
| 255 | # used to attach defelem magic to all immortal values,
|
|---|
| 256 | # which made restore of local $_ fail.
|
|---|
| 257 | foo(2>1);
|
|---|
| 258 | sub foo { bar() for @_; }
|
|---|
| 259 | sub bar { local $_; }
|
|---|
| 260 | print "ok\n";
|
|---|
| 261 | EXPECT
|
|---|
| 262 | ok
|
|---|
| 263 | ########
|
|---|
| 264 | @a = ($a, $b, $c, $d) = (5, 6);
|
|---|
| 265 | print "ok\n"
|
|---|
| 266 | if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);
|
|---|
| 267 | EXPECT
|
|---|
| 268 | ok
|
|---|
| 269 | ########
|
|---|
| 270 | print "ok\n" if (1E2<<1 == 200 and 3E4<<3 == 240000);
|
|---|
| 271 | EXPECT
|
|---|
| 272 | ok
|
|---|
| 273 | ########
|
|---|
| 274 | print "ok\n" if ("\0" lt "\xFF");
|
|---|
| 275 | EXPECT
|
|---|
| 276 | ok
|
|---|
| 277 | ########
|
|---|
| 278 | open(H,$^O eq 'MacOS' ? ':run:fresh_perl.t' : 'run/fresh_perl.t'); # must be in the 't' directory
|
|---|
| 279 | stat(H);
|
|---|
| 280 | print "ok\n" if (-e _ and -f _ and -r _);
|
|---|
| 281 | EXPECT
|
|---|
| 282 | ok
|
|---|
| 283 | ########
|
|---|
| 284 | sub thing { 0 || return qw(now is the time) }
|
|---|
| 285 | print thing(), "\n";
|
|---|
| 286 | EXPECT
|
|---|
| 287 | nowisthetime
|
|---|
| 288 | ########
|
|---|
| 289 | $ren = 'joy';
|
|---|
| 290 | $stimpy = 'happy';
|
|---|
| 291 | { local $main::{ren} = *stimpy; print $ren, ' ' }
|
|---|
| 292 | print $ren, "\n";
|
|---|
| 293 | EXPECT
|
|---|
| 294 | happy joy
|
|---|
| 295 | ########
|
|---|
| 296 | $stimpy = 'happy';
|
|---|
| 297 | { local $main::{ren} = *stimpy; print ${'ren'}, ' ' }
|
|---|
| 298 | print +(defined(${'ren'}) ? 'oops' : 'joy'), "\n";
|
|---|
| 299 | EXPECT
|
|---|
| 300 | happy joy
|
|---|
| 301 | ########
|
|---|
| 302 | package p;
|
|---|
| 303 | sub func { print 'really ' unless wantarray; 'p' }
|
|---|
| 304 | sub groovy { 'groovy' }
|
|---|
| 305 | package main;
|
|---|
| 306 | print p::func()->groovy(), "\n"
|
|---|
| 307 | EXPECT
|
|---|
| 308 | really groovy
|
|---|
| 309 | ########
|
|---|
| 310 | @list = ([ 'one', 1 ], [ 'two', 2 ]);
|
|---|
| 311 | sub func { $num = shift; (grep $_->[1] == $num, @list)[0] }
|
|---|
| 312 | print scalar(map &func($_), 1 .. 3), " ",
|
|---|
| 313 | scalar(map scalar &func($_), 1 .. 3), "\n";
|
|---|
| 314 | EXPECT
|
|---|
| 315 | 2 3
|
|---|
| 316 | ########
|
|---|
| 317 | ($k, $s) = qw(x 0);
|
|---|
| 318 | @{$h{$k}} = qw(1 2 4);
|
|---|
| 319 | for (@{$h{$k}}) { $s += $_; delete $h{$k} if ($_ == 2) }
|
|---|
| 320 | print "bogus\n" unless $s == 7;
|
|---|
| 321 | ########
|
|---|
| 322 | my $a = 'outer';
|
|---|
| 323 | eval q[ my $a = 'inner'; eval q[ print "$a " ] ];
|
|---|
| 324 | eval { my $x = 'peace'; eval q[ print "$x\n" ] }
|
|---|
| 325 | EXPECT
|
|---|
| 326 | inner peace
|
|---|
| 327 | ########
|
|---|
| 328 | -w
|
|---|
| 329 | $| = 1;
|
|---|
| 330 | sub foo {
|
|---|
| 331 | print "In foo1\n";
|
|---|
| 332 | eval 'sub foo { print "In foo2\n" }';
|
|---|
| 333 | print "Exiting foo1\n";
|
|---|
| 334 | }
|
|---|
| 335 | foo;
|
|---|
| 336 | foo;
|
|---|
| 337 | EXPECT
|
|---|
| 338 | In foo1
|
|---|
| 339 | Subroutine foo redefined at (eval 1) line 1.
|
|---|
| 340 | Exiting foo1
|
|---|
| 341 | In foo2
|
|---|
| 342 | ########
|
|---|
| 343 | $s = 0;
|
|---|
| 344 | map {#this newline here tickles the bug
|
|---|
| 345 | $s += $_} (1,2,4);
|
|---|
| 346 | print "eat flaming death\n" unless ($s == 7);
|
|---|
| 347 | ########
|
|---|
| 348 | sub foo { local $_ = shift; split; @_ }
|
|---|
| 349 | @x = foo(' x y z ');
|
|---|
| 350 | print "you die joe!\n" unless "@x" eq 'x y z';
|
|---|
| 351 | ########
|
|---|
| 352 | /(?{"{"})/ # Check it outside of eval too
|
|---|
| 353 | EXPECT
|
|---|
| 354 | Sequence (?{...}) not terminated or not {}-balanced in regex; marked by <-- HERE in m/(?{ <-- HERE "{"})/ at - line 1.
|
|---|
| 355 | ########
|
|---|
| 356 | /(?{"{"}})/ # Check it outside of eval too
|
|---|
| 357 | EXPECT
|
|---|
| 358 | Unmatched right curly bracket at (re_eval 1) line 1, at end of line
|
|---|
| 359 | syntax error at (re_eval 1) line 1, near ""{"}"
|
|---|
| 360 | Compilation failed in regexp at - line 1.
|
|---|
| 361 | ########
|
|---|
| 362 | BEGIN { @ARGV = qw(a b c d e) }
|
|---|
| 363 | BEGIN { print "argv <@ARGV>\nbegin <",shift,">\n" }
|
|---|
| 364 | END { print "end <",shift,">\nargv <@ARGV>\n" }
|
|---|
| 365 | INIT { print "init <",shift,">\n" }
|
|---|
| 366 | CHECK { print "check <",shift,">\n" }
|
|---|
| 367 | EXPECT
|
|---|
| 368 | argv <a b c d e>
|
|---|
| 369 | begin <a>
|
|---|
| 370 | check <b>
|
|---|
| 371 | init <c>
|
|---|
| 372 | end <d>
|
|---|
| 373 | argv <e>
|
|---|
| 374 | ########
|
|---|
| 375 | -l
|
|---|
| 376 | # fdopen from a system descriptor to a system descriptor used to close
|
|---|
| 377 | # the former.
|
|---|
| 378 | open STDERR, '>&=STDOUT' or die $!;
|
|---|
| 379 | select STDOUT; $| = 1; print fileno STDOUT or die $!;
|
|---|
| 380 | select STDERR; $| = 1; print fileno STDERR or die $!;
|
|---|
| 381 | EXPECT
|
|---|
| 382 | 1
|
|---|
| 383 | 2
|
|---|
| 384 | ########
|
|---|
| 385 | -w
|
|---|
| 386 | sub testme { my $a = "test"; { local $a = "new test"; print $a }}
|
|---|
| 387 | EXPECT
|
|---|
| 388 | Can't localize lexical variable $a at - line 1.
|
|---|
| 389 | ########
|
|---|
| 390 | package X;
|
|---|
| 391 | sub ascalar { my $r; bless \$r }
|
|---|
| 392 | sub DESTROY { print "destroyed\n" };
|
|---|
| 393 | package main;
|
|---|
| 394 | *s = ascalar X;
|
|---|
| 395 | EXPECT
|
|---|
| 396 | destroyed
|
|---|
| 397 | ########
|
|---|
| 398 | package X;
|
|---|
| 399 | sub anarray { bless [] }
|
|---|
| 400 | sub DESTROY { print "destroyed\n" };
|
|---|
| 401 | package main;
|
|---|
| 402 | *a = anarray X;
|
|---|
| 403 | EXPECT
|
|---|
| 404 | destroyed
|
|---|
| 405 | ########
|
|---|
| 406 | package X;
|
|---|
| 407 | sub ahash { bless {} }
|
|---|
| 408 | sub DESTROY { print "destroyed\n" };
|
|---|
| 409 | package main;
|
|---|
| 410 | *h = ahash X;
|
|---|
| 411 | EXPECT
|
|---|
| 412 | destroyed
|
|---|
| 413 | ########
|
|---|
| 414 | package X;
|
|---|
| 415 | sub aclosure { my $x; bless sub { ++$x } }
|
|---|
| 416 | sub DESTROY { print "destroyed\n" };
|
|---|
| 417 | package main;
|
|---|
| 418 | *c = aclosure X;
|
|---|
| 419 | EXPECT
|
|---|
| 420 | destroyed
|
|---|
| 421 | ########
|
|---|
| 422 | package X;
|
|---|
| 423 | sub any { bless {} }
|
|---|
| 424 | my $f = "FH000"; # just to thwart any future optimisations
|
|---|
| 425 | sub afh { select select ++$f; my $r = *{$f}{IO}; delete $X::{$f}; bless $r }
|
|---|
| 426 | sub DESTROY { print "destroyed\n" }
|
|---|
| 427 | package main;
|
|---|
| 428 | $x = any X; # to bump sv_objcount. IO objs aren't counted??
|
|---|
| 429 | *f = afh X;
|
|---|
| 430 | EXPECT
|
|---|
| 431 | destroyed
|
|---|
| 432 | destroyed
|
|---|
| 433 | ########
|
|---|
| 434 | BEGIN {
|
|---|
| 435 | $| = 1;
|
|---|
| 436 | $SIG{__WARN__} = sub {
|
|---|
| 437 | eval { print $_[0] };
|
|---|
| 438 | die "bar\n";
|
|---|
| 439 | };
|
|---|
| 440 | warn "foo\n";
|
|---|
| 441 | }
|
|---|
| 442 | EXPECT
|
|---|
|
|---|