1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
|
Test no feature bareword_filehandles
todo:
print HANDLE
print HANDLE LIST
printf HANDLE
printf HANDLE LIST
say HANDLE
say HANDLE LIST
readline
<> / <HANDLE>
<<>> - has an implicit argument
truncate
stat
-X
lstat
open
close
eof
fileno
flock
getc
read
write ?
seek
tell
select
sysopen
sysread
syswrite
sysseek
pipe
socket
connect
bind
listen
recv
send
setsockopt
getsockopt
shutdown
socketpair
accept
getpeername
getsockname
binmode
ioctl
fcntl
chmod - doesn't accept bareword handles
chown - doesn't accept bareword handles
opendir
closedir
readdir
seekdir
telldir
rewinddir
chdir
also check
sort
map
grep
aren't modified
__END__
# NAME defaults and explicitly on
#!perl -c
use File::Temp qw(tempfile);
use Fcntl qw(SEEK_SET);
use Socket;
my ($fh, $name) = tempfile;
open FOO, ">", File::Spec->devnull;
print FOO;
print FOO "Hello";
printf FOO "Hello";
seek FOO, 0, SEEK_SET;
truncate FOO, 0;
print FOO "Something read\n";
close FOO;
<FOO>;
{
local *ARGV;
local *ARGVOUT;
@ARGV = $name;
<<>>;
<>;
}
pipe FH1, FH2;
socketpair S1, S2, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
shutdown S1, 0;
use feature "bareword_filehandles";
open FOO, ">", File::Spec->devnull;
print FOO;
print FOO "Hello";
printf FOO "Hello";
seek FOO, 0, SEEK_SET;
truncate FOO, 0;
print FOO "Something read\n";
close FOO;
<FOO>;
{
local *ARGV;
local *ARGVOUT;
@ARGV = $name;
<<>>;
<>;
}
pipe FH3, FH4;
socketpair S3, S4, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
shutdown S3, 0;
EXPECT
- syntax OK
########
# NAME check atan2() with a handle doesn't trigger bareword filehandle errors
no feature "bareword_filehandles", "indirect";
my $x = atan2(FOO 1, 2);
# my original approach to this hooked newGVREF(), which the parsing for most LOPs (as with
# atan2() above) could end up calling newGVREF(), producing an unexpected error message.
EXPECT
OPTIONS fatal
Number found where operator expected (Do you need to predeclare "FOO"?) at - line 2, near "FOO 1"
Missing comma after first argument to atan2 function at - line 2, near "2)"
Execution of - aborted due to compilation errors.
########
# NAME print HANDLE LIST, printf HANDLE LIST, print HANDLE, printf HANDLE
use File::Spec;
open FOO, ">", File::Spec->devnull or die $!;
$_ = "abc";
print FOO "test\n";
printf FOO "test\n";
print FOO;
printf FOO;
no feature "bareword_filehandles";
print FOO "test2\n";
printf FOO "test2\n";
print FOO;
printf FOO;
print STDERR;
print STDOUT;
print ARGV;
print ARGVOUT;
print DATA;
print STDIN;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 10.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 11.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 12.
Execution of - aborted due to compilation errors.
########
# NAME say HANDLE LIST, say HANDLE
use File::Spec;
use feature "say";
open FOO, ">", File::Spec->devnull or die $!;
$_ = "abc";
say FOO "test\n";
say FOO;
no feature "bareword_filehandles";
say FOO "test2\n";
say FOO;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Execution of - aborted due to compilation errors.
########
# NAME readline FOO, readline, <>, <FOO>
use File::Spec;
open FOO, "<", File::Spec->devnull or die $!;
my $x = readline FOO;
$x .= readline FOO; # rcatline
$x = readline(FOO); # parsed a little differently with ()
$x .= readline(FOO);
$x = <FOO>;
$x .= <FOO>;
no feature "bareword_filehandles";
$x = readline FOO;
$x .= readline FOO; # rcatline
$x = readline(FOO); # parsed a little differently with ()
$x .= readline(FOO);
$x = <FOO>;
$x .= <FOO>;
$x = readline STDIN;
$x = <STDIN>;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 10.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 11.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 12.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 13.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 14.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 15.
Execution of - aborted due to compilation errors.
########
# NAME truncate
use strict;
use warnings;
# if all goes well this doesn't run anyway
my $name = "bare$$.tmp";
END { unlink $name if $name; }
open FOO, ">", $name or die;
print FOO "Non-zero length data\n";
truncate FOO, 2;
no feature "bareword_filehandles";
truncate FOO, 1;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 10.
Execution of - aborted due to compilation errors.
########
# NAME stat, lstat, -X
use File::Spec;
open FOO, "<", File::Spec->devnull;
my @x = stat FOO;
@x = lstat FOO;
my $x = -s FOO;
no feature "bareword_filehandles";
@x = stat FOO;
@x = lstat FOO;
$x = -s FOO;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Execution of - aborted due to compilation errors.
########
# NAME open, close, eof, fileno
use File::Spec;
open FOO, "<", File::Spec->devnull;
my $x = eof FOO;
$x = fileno FOO;
close FOO;
no feature "bareword_filehandles";
open FOO, "<", File::Spec->devnull;
$x = eof FOO;
$x = fileno FOO;
close FOO;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 10.
Execution of - aborted due to compilation errors.
########
# NAME flock
use Fcntl ":flock";
open FOO, "<", $0 or die;
flock FOO, LOCK_SH;
no feature "bareword_filehandles";
flock FOO, LOCK_UN;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Execution of - aborted due to compilation errors.
########
# NAME getc, read, seek, tell
open FOO, "<", $0 or die;
my $x = getc FOO;
read(FOO, $x, 1);
$x = tell FOO;
seek FOO, 0, 0;
no feature "bareword_filehandles";
$x = getc FOO;
read(FOO, $x, 1);
$x = tell FOO;
seek FOO, 0, 0;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 10.
Execution of - aborted due to compilation errors.
########
# NAME select
open FOO, "<", $0 or die;
my $old = select FOO;
no feature "bareword_filehandles";
select FOO;
select $old;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 4.
Execution of - aborted due to compilation errors.
########
# NAME sysopen, sysread, syswrite, sysseek
use Fcntl;
use File::Spec;
sysopen FOO, File::Spec->devnull, O_RDWR or die;
sysread FOO, my $x, 10;
syswrite FOO, "Test";
my $y = sysseek FOO, 0, SEEK_CUR;
close FOO;
no feature "bareword_filehandles";
sysopen FOO, File::Spec->devnull, O_RDWR or die;
sysread FOO, my $x, 10;
syswrite FOO, "Test";
my $y = sysseek FOO, 0, SEEK_CUR;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 10.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 11.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 12.
Execution of - aborted due to compilation errors.
########
# NAME pipe
my $fh;
pipe IN, $fh;
pipe $fh, OUT;
pipe IN, OUT;
no feature "bareword_filehandles";
pipe IN, $fh;
pipe $fh, OUT;
pipe IN, OUT;
EXPECT
OPTIONS fatal
Bareword filehandle "IN" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "OUT" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "IN" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "OUT" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Execution of - aborted due to compilation errors.
########
# NAME socket, connect, bind, listen
my $fh;
# this won't run, just use dummy values for domain, type, protocol
socket(FOO, 0, 0,0);
connect(FOO, "abc");
bind(FOO, "abc");
listen(FOO, 5);
no feature "bareword_filehandles";
socket(FOO, 0, 0,0);
connect(FOO, "abc");
bind(FOO, "abc");
listen(FOO, 5);
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 10.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 11.
Execution of - aborted due to compilation errors.
########
# NAME accept
accept(FOO, CHILD);
accept($fh, CHILD);
accept(FOO, $fh);
no feature "bareword_filehandles";
accept(FOO, CHILD);
accept($fh, CHILD);
accept(FOO, $fh);
accept(*FOO, *CHILD);
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Bareword filehandle "CHILD" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Bareword filehandle "CHILD" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Execution of - aborted due to compilation errors.
########
# NAME accept some more
accept FOO, CHILD ;
accept $fh, CHILD ;
accept FOO, $fh ;
no feature "bareword_filehandles";
accept FOO, CHILD ;
accept $fh, CHILD ;
accept FOO, $fh;
package BAR {}
accept QUUX BAR, $fh;
sub BAR::QUUX { $fh }
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Bareword filehandle "CHILD" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Bareword filehandle "CHILD" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Execution of - aborted due to compilation errors.
########
# NAME send, recv, setsockopt, getsockopt
send FOO, "abc", 0;
recv FOO, my $x, 10, 0;
setsockopt FOO, 0, 0, 0;
my $y = getsockopt FOO, 0, 0;
no feature "bareword_filehandles";
send FOO, "abc", 0;
recv FOO, my $x, 10, 0;
setsockopt FOO, 0, 0, 0;
my $y = getsockopt FOO, 0, 0;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Execution of - aborted due to compilation errors.
########
# NAME shutdown, getsockname, getpeername
shutdown FOO, 0;
my $sockname = getsockname FOO;
my $peername = getpeername FOO;
no feature "bareword_filehandles";
shutdown FOO, 0;
$sockname = getsockname FOO;
$peername = getpeername FOO;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Execution of - aborted due to compilation errors.
########
# NAME socketpair
my $fh;
socketpair IN, $fh, 0, 0, 0;
socketpair $fh, OUT, 0, 0, 0;
socketpair IN, OUT, 0, 0, 0;
no feature "bareword_filehandles";
socketpair IN, $fh, 0, 0, 0;
socketpair $fh, OUT, 0, 0, 0;
socketpair IN, OUT, 0, 0, 0;
EXPECT
OPTIONS fatal
Bareword filehandle "IN" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "OUT" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "IN" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "OUT" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Execution of - aborted due to compilation errors.
########
# NAME binmode, ioctl, fcntl
binmode FOO;
binmode FOO, ":raw";
ioctl FOO, 0, 0;
fcntl FOO, 0, 0;
no feature "bareword_filehandles";
binmode FOO;
binmode FOO, ":raw";
ioctl FOO, 0, 0;
fcntl FOO, 0, 0;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Execution of - aborted due to compilation errors.
########
# NAME opendir, closedir, readdir
opendir FOO, ".";
my @x = readdir FOO;
chdir FOO;
closedir FOO;
no feature "bareword_filehandles";
opendir FOO, ".";
my @x = readdir FOO;
chdir FOO;
closedir FOO;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 9.
Execution of - aborted due to compilation errors.
########
# NAME seekdir, telldir, rewinddir
use strict;
my $x = telldir FOO;
seekdir FOO, $x;
rewinddir FOO;
no feature "bareword_filehandles";
my $x = telldir FOO;
seekdir FOO, $x;
rewinddir FOO;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 7.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 8.
Execution of - aborted due to compilation errors.
########
# NAME file tests
-T FOO;
-s FOO;
no feature "bareword_filehandles";
-T FOO;
-s FOO;
-s _;
EXPECT
OPTIONS fatal
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 4.
Bareword filehandle "FOO" not allowed under 'no feature "bareword_filehandles"' at - line 5.
Execution of - aborted due to compilation errors.
########
# NAME subroutine calls
use feature "say";
no feature "bareword_filehandles";
sub foo {}
print foo();
print foo;
say foo();
say foo;
-x foo();
-x foo;
EXPECT
########
# NAME method calls
# https://github.com/Perl/perl5/issues/19704
use feature "say";
no feature "bareword_filehandles";
sub foo {}
print main->foo();
print main->foo;
say main->foo();
say main->foo;
-x main->foo();
-x main->foo;
EXPECT
########
# NAME bareword method calls resolving to bareword filehandles
# https://github.com/Perl/perl5/issues/19426
use feature "say";
my $x = "Foo";
*Foo = *STDOUT; # make Foo an IO
sub Foo::say {
say ">", @_[1..$#_];
}
Foo->say("Hello"); # calls IO::File->say()
no feature "bareword_filehandles";
"Foo"->say("Alpha"); # calls IO::File::say();
$x->say("Beta"); # calls IO::File::say()
Foo->say("Goodbye"); # calls Foo->say(), Foo now in stash cache
"Foo"->say("Gamma"); # calls Foo->say()
STDOUT->say("stdout"); # calls IO::File->say
use feature "bareword_filehandles";
Foo->say("Delta"); # calls Foo->say()
$x->say("Epsilon"); # calls Foo->say()
EXPECT
Hello
Alpha
Beta
>Goodbye
>Gamma
stdout
>Delta
>Epsilon
########
# NAME bareword handle in open dup handle calls
use strict;
open BAREWORD, ">&", STDOUT;
open my $fh2, ">&", BAREWORD;
no feature "bareword_filehandles";
open my $fh3, ">&", STDOUT;
open my $fh4, ">&", BAREWORD;
EXPECT
OPTIONS fatal
Bareword filehandle "BAREWORD" not allowed under 'no feature "bareword_filehandles"' at - line 6.
Execution of - aborted due to compilation errors.
|