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 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
|
use strict;
use warnings;
use Test::More;
if ( $ENV{RELEASE_TESTING} || $ENV{AUTHOR_TESTING} || $ENV{AUTHOR_TESTS} )
{ # the tests in this file have a higher probability
plan tests => 68; # of failing in the wild, and so are reserved for
# the author/maintainers as release tests
CORE::eval # hide the eval...
'
use Test::NoWarnings;
'; # ...from dist parsers
}
else
{
plan skip_all => 'these tests are for testing by the author';
}
use lib './lib';
use File::Util qw( SL NL existent );
my $f = File::Util->new( fatals_as_errmsg => 1 );
# start testing failure sequence
# 1
like(
$f->_throw(
'no such file' =>
{
filename => __FILE__,
fatals_as_errmsg => 1,
diag => 1,
}
), qr/inaccessible or does not exist/,
'no such file (diagnostic mode)'
);
# 1.5
like(
$f->_throw(
'no such file' =>
{
filename => __FILE__,
fatals_as_errmsg => 1,
}
), qr/inaccessible or does not exist/,
'no such file'
);
# 2
like(
$f->_throw(
'bad flock rules' => {
bad => __FILE__,
all => [ $f->flock_rules() ],
diag => 1,
}
),
qr/Invalid file locking policy/,
'bad flock rules (diagnostic mode)'
);
is $f->diagnostic( 1 ), 1,
'manually toggle on diagnostic mode for entire object';
# 2.25
like(
$f->_throw(
'bad flock rules' => {
bad => __FILE__,
all => [ $f->flock_rules() ],
}
),
qr/Invalid file locking policy/,
'bad flock rules (diagnostic mode) after manual object-wide diag toggle'
);
# 2.5
like(
$f->_throw(
'bad flock rules' => {
bad => __FILE__,
all => [ $f->flock_rules() ],
}
),
qr/(?sm)^Invalid file locking policy/,
'bad flock rules'
);
is $f->diagnostic( 0 ), 0,
'manually toggle off diagnostic mode for entire object';
# 3
like(
$f->_throw(
'cant fread' => {
filename => __FILE__,
dirname => '.',
diag => 1,
}
),
qr/Permissions conflict\..+?can't read the contents of this file:/,
'cant fread (diagnostic mode)'
);
# 3.5
like(
$f->_throw(
'cant fread' => {
filename => __FILE__,
dirname => '.',
}
),
qr/(?sm)^Permissions conflict\. Can't read:/,
'cant fread'
);
# 4
like(
$f->_throw( 'cant fread not found' => { diag => 1, filename => __FILE__ } ),
qr/File not found\. .+?can't read the contents of this file\:/,
'cant fread no exists (diagnostic mode)'
);
# 4.5
like(
$f->_throw( 'cant fread not found' => { filename => __FILE__ } ),
qr/(?sm)^File not found:/,
'cant fread no exists'
);
# 5
like(
$f->_throw(
'cant fcreate' => {
filename => __FILE__,
dirname => '.',
diag => 1,
}
),
qr/Permissions conflict\..+?can't create this file:/,
'cant fcreate (diagnostic mode)'
);
# 5.5
like(
$f->_throw(
'cant fcreate' => {
filename => __FILE__,
dirname => '.',
}
),
qr/(?sm)^Permissions conflict\. Can't create:/,
'cant fcreate'
);
# 6
like( $f->_throw( 'cant write_file on a dir' => { diag => 1, filename => __FILE__ } ),
qr/can't write to the specified file/,
'cant write_file on a dir (diagnostic mode)'
);
# 6.5
like( $f->_throw( 'cant write_file on a dir' => { filename => __FILE__ } ),
qr/(?sm)^File already exists as directory:/,
'cant write_file on a dir'
);
# 7
like(
$f->_throw(
'cant fwrite' => {
filename => __FILE__,
dirname => '.',
diag => 1,
}
),
qr/Permissions conflict\..+?can't write to this file:/,
'cant fwrite (diagnostic mode)'
);
# 7.5
like(
$f->_throw(
'cant fwrite' => {
filename => __FILE__,
dirname => '.',
}
),
qr/(?sm)^Permissions conflict\. Can't write to:/,
'cant fwrite'
);
# 8
like(
$f->_throw(
'bad openmode popen' => {
filename => __FILE__,
badmode => 'illegal',
meth => 'anonymous',
diag => 1,
}
),
qr/Illegal mode specified for file open\./,
'bad openmode popen (diagnostic mode)'
);
# 8.5
like(
$f->_throw(
'bad openmode popen' => {
filename => __FILE__,
badmode => 'illegal',
meth => 'anonymous',
}
),
qr/(?sm)^Illegal mode specified for file open:/,
'bad openmode popen'
);
# 9
like(
$f->_throw(
'bad openmode sysopen' => {
filename => __FILE__,
badmode => 'illegal',
meth => 'anonymous',
diag => 1,
}
),
qr/Illegal mode specified for file sysopen/,
'bad openmode sysopen (diagnostic mode)'
);
# 9.5
like(
$f->_throw(
'bad openmode sysopen' => {
filename => __FILE__,
badmode => 'illegal',
meth => 'anonymous',
}
),
qr/(?sm)^Illegal mode specified for sysopen:/,
'bad openmode sysopen'
);
# 10
like( $f->_throw( 'cant dread' => { diag => 1, dirname => '.' } ),
qr/Permissions conflict\..+?can't list the contents of this/,
'cant dread (diagnostic mode)'
);
# 10.5
like( $f->_throw( 'cant dread' => { dirname => '.' } ),
qr/(?sm)^Permissions conflict\. Can't list directory:/,
'cant dread'
);
# 11
like(
$f->_throw(
'cant dcreate' => {
dirname => '.',
parentd => '..',
diag => 1,
}
),
qr/Permissions conflict\..+?can't create:/,
'cant dcreate (diagnostic mode)'
);
# 11.5
like(
$f->_throw(
'cant dcreate' => {
dirname => '.',
parentd => '..',
}
),
qr/(?sm)^Permissions conflict\. Can't create directory:/,
'cant dcreate'
);
# 12
like(
$f->_throw(
'make_dir target exists' => {
dirname => '.',
filetype => [ $f->file_type('.') ],
diag => '.',
}
),
qr/make_dir target already exists\./,
'make_dir target exists (diagnostic mode)'
);
# 12.5
like(
$f->_throw(
'make_dir target exists' => {
dirname => '.',
filetype => [ $f->file_type('.') ],
}
),
qr/(?sm)^make_dir target already exists:/,
'make_dir target exists'
);
# 13
like(
$f->_throw(
'bad open' => {
mode => 'illegal mode',
filename => __FILE__,
exception => 'dummy',
cmd => 'illegal cmd',
diag => 1,
}
),
qr/can't open this file for.+?illegal mode/,
'bad open (diagnostic mode)'
);
# 13.5
like(
$f->_throw(
'bad open' => {
mode => 'illegal mode',
filename => __FILE__,
exception => 'dummy',
cmd => 'illegal cmd',
}
),
qr/(?sm)^Can't open:/,
'bad open'
);
# 14
like(
$f->_throw(
'bad close' => {
mode => 'illegal mode',
filename => __FILE__,
exception => 'dummy',
diag => 1,
}
),
qr/couldn't close this file after.+?illegal mode/,
'bad close (diagnostic mode)'
);
# 14.5
like(
$f->_throw(
'bad close' => {
mode => 'illegal mode',
filename => __FILE__,
exception => 'dummy',
}
),
qr/(?sm)^Couldn't close:/,
'bad close'
);
# 15
like(
$f->_throw(
'bad systrunc' => {
filename => __FILE__,
exception => 'dummy',
diag => 1,
}
),
qr/couldn't truncate\(\) on.+?after having/,
'bad systrunc (diagnostic mode)'
);
# 15.5
like(
$f->_throw(
'bad systrunc' => {
filename => __FILE__,
exception => 'dummy',
}
),
qr/(?sm)^Couldn't truncate\(\) on/,
'bad systrunc'
);
# 16
like(
$f->_throw(
'bad flock' => {
filename => __FILE__,
exception => 'illegal',
diag => 1
}
),
qr/can't get a lock on the file/,
'bad flock (diagnostic mode)'
);
# 16.5
like(
$f->_throw(
'bad flock' => {
filename => __FILE__,
exception => 'illegal',
}
),
qr/(?sm)^Can't get a lock on the file:/,
'bad flock'
);
# 17
like( $f->_throw( 'called open on a dir' => { diag => 1, filename => __FILE__ } ),
qr/can't call open\(\) on this file because it is a directory/,
'called open on a dir (diagnostic mode)'
);
# 17.5
like( $f->_throw( 'called open on a dir' => { filename => __FILE__ } ),
qr/(?sm)^Can't call open\(\) on a directory:/,
'called open on a dir'
);
# 18
like( $f->_throw( 'called opendir on a file' => { diag => 1, filename => __FILE__ } ),
qr/can't opendir\(\) on this file because it is not a directory/,
'called opendir on a file (diagnostic mode)'
);
# 18.5
like( $f->_throw( 'called opendir on a file' => { filename => __FILE__ } ),
qr/(?sm)^Can't opendir\(\) on non-directory:/,
'called opendir on a file'
);
# 19
like( $f->_throw( 'called mkdir on a file' => { diag => 1, filename => __FILE__ } ),
qr/can't auto-create a directory for this path name because/,
'called mkdir on a file (diagnostic mode)'
);
# 19.5
like( $f->_throw( 'called mkdir on a file' => { filename => __FILE__ } ),
qr/(?sm)^Can't make directory; already exists as a file\./,
'called mkdir on a file'
);
# 20
like( $f->_throw( 'bad read_limit' => { read_limit => 42, diag => 1 } ),
qr/Bad call to .+?\:\:read_limit\(\)\. This method can only be/,
'bad read_limit (diagnostic mode)'
);
# 20.5
like( $f->_throw( 'bad read_limit' => { read_limit => 42 } ),
qr/(?sm)^Bad input provided to read_limit\(\)/,
'bad read_limit'
);
# 21
like(
$f->_throw(
'read_limit exceeded' => {
filename => __FILE__,
size => 'testtesttest',
read_limit => 42,
diag => 1,
}
),
qr/(?sm)can't load file.+?into memory because its size exceeds/,
'read_limit exceeded (diagnostic mode)'
);
# 21.5
like(
$f->_throw(
'read_limit exceeded' => {
filename => __FILE__,
size => 'testtesttest',
read_limit => 42,
}
),
qr/(?sm)^Stopped reading:.+?Read limit exceeded:/,
'read_limit exceeded'
);
# 22
like( $f->_throw( 'bad abort_depth' => { diag => 1 } ),
qr/Bad call to .+?\:\:abort_depth\(\)\. This method can only be/,
'bad abort_depth (diagnostic mode)'
);
# 22.5
like( $f->_throw( 'bad abort_depth' => { } ),
qr/(?sm)^Bad input provided to abort_depth\(\)/,
'bad abort_depth'
);
# 23
like( $f->_throw( 'abort_depth exceeded' => { diag => 1 } ),
qr/Recursion limit reached at .+?dives\. The maximum level of/,
'abort_depth exceeded (diagnostic mode)'
);
# 23.5
like( $f->_throw( 'abort_depth exceeded' => { } ),
qr/(?sm)^Recursion limit exceeded at/,
'abort_depth exceeded'
);
# 24
like(
$f->_throw(
'bad opendir' => {
dirname => '.',
exception => 'illegal',
diag => 1,
}
),
qr/can't opendir on directory\:/,
'bad opendir (diagnostic mode)'
);
# 24.5
like(
$f->_throw(
'bad opendir' => {
dirname => '.',
exception => 'illegal',
}
),
qr/(?sm)^Can't opendir on directory:/,
'bad opendir'
);
# 25
like(
$f->_throw(
'bad make_dir' => {
dirname => '.',
bitmask => 0777,
exception => 'illegal',
meth => 'anonymous',
diag => 1,
}
),
qr/had a problem with the system while attempting to create/,
'bad make_dir (diagnostic mode)'
);
# 25.5
like(
$f->_throw(
'bad make_dir' => {
dirname => '.',
bitmask => 0777,
exception => 'illegal',
meth => 'anonymous',
}
),
qr/(?sm)^Can't create directory:/,
'bad make_dir'
);
# 26
like(
$f->_throw(
'bad chars' => {
string => 'illegal characters',
purpose => 'testing',
diag => 1,
}
),
qr/(?sm)can't use this string.+?It contains illegal characters\./,
'bad chars (diagnostic mode)'
);
# 26.5
like(
$f->_throw(
'bad chars' => {
string => 'illegal characters',
purpose => 'testing',
}
),
qr/(?sm)^String contains illegal characters:/,
'bad chars'
);
# 27
like( $f->_throw( 'not a filehandle' => { diag => 1, argtype => 'illegal' } ),
qr/can't unlock file with an invalid file handle reference\:/,
'not a filehandle (diagnostic mode)'
);
# 27.5
like( $f->_throw( 'not a filehandle' => { argtype => 'illegal' } ),
qr/(?sm)^Can't unlock file with an invalid file handle reference/,
'not a filehandle'
);
# 28
like( $f->_throw( 'no input' => { diag => 1, meth => 'anonymous' } ),
qr/(?sm)can't honor your call to.+?because you didn't provide/,
'no input (diagnostic mode)'
);
# 28.5
like( $f->_throw( 'no input' => { meth => 'anonymous' } ),
qr/(?sm)^Call to.+?failed: Required input missing/,
'no input'
);
# 29
like( $f->_throw( 'plain error' => 'testtesttest', diag => 1 ),
qr/failed with the following message\:/,
'plain error (diagnostic mode)'
);
# 29.5
like( $f->_throw( 'plain error' => 'testtesttest' ),
qr/(?sm)^testtesttest/,
'plain error'
);
# 30
like( $f->_throw( 'unknown error message' => { diag => 1 } ),
qr/failed with an invalid error-type designation\./,
'unknown error message (diagnostic mode)'
);
# 30.5
like( $f->_throw( 'unknown error message' => { } ),
qr/(?sm)^Failed with an invalid error-type designation\./,
'unknown error message'
);
# 31
like( $f->_throw( 'empty error' => { diag => 1 } ),
qr/failed with an empty error-type designation\./,
'empty error (diagnostic mode)'
);
# 31.5
like( $f->_throw( 'empty error' => { } ),
qr/(?sm)^Failed with an empty error-type designation\./,
'empty error'
);
# 32
like( $f->_throw( 'no unicode' => { diag => 1 } ),
qr/(?sm)can't read\/write with \(binmode => 'utf8'\)/,
'no unicode support (diagnostic mode)'
);
# 32.5
like( $f->_throw( 'no unicode' => { } ),
qr/(?sm)^Your version of Perl is not new enough/,
'no unicode support'
);
exit;
|