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 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
|
#!/usr/bin/env perl
use 5.010001;
use strict;
use warnings;
use English qw< -no_match_vars >;
use Carp qw< confess >;
use Carp qw< confess >;
use Fatal qw< open close >;
my $this_program = __FILE__;
(my $test_file_name = $this_program) =~ s/ [.] PL \z //xms;
if ($this_program eq $test_file_name) {
confess
'Was not able to figure out the name of the file to generate.'
. "This program: $this_program.";
}
print "\n\nGenerating $test_file_name.\n";
open my $test_file, '>', $test_file_name ## no critic (RequireBriefOpen)
or confess "Could not open $test_file_name: $ERRNO";
print {$test_file} <<"END_HEADER";
# Do not edit!!! This test suite generated by $this_program.
END_HEADER
emit_simple_tests($test_file);
emit_primary_tests($test_file);
emit_footer($test_file);
close $test_file;
print "Done.\n\n";
#-----------------------------------------------------------------------------
sub emit_simple_tests {
my ($test_file) = @_;
print {$test_file} <<'END_SIMPLE_TESTS';
#-----------------------------------------------------------------------------
## name Basic Passes
## failures 0
## cut
my $foo;
our $bar;
my($foo, $bar) = ("BLEH", "BLEH");
my @foo;
my %bar;
sub foo {}
my $foo123;
my $foo123bar;
sub foo123 {}
sub foo123bar {}
package This::SomeThing;
package This;
package This::Thing;
package Acme::12345;
package YYZ;
#-----------------------------------------------------------------------------
## name Basic Failures
## failures 14
## cut
my $Foo;
our $Bar;
my @Foo;
my %Bar;
sub Foo {}
my $foo_Bar;
sub foo_Bar {}
my $FooBar;
sub FooBar {}
my $foo123Bar;
sub foo123Bar {}
package pragma;
package Foo::baz;
package baz::FooBar;
#-----------------------------------------------------------------------------
## name Special case: main
## failures 0
## cut
package main;
#-----------------------------------------------------------------------------
## name Combined passes and fails
## failures 2
## cut
my($foo, $Bar);
our($Bar, $foo);
#-----------------------------------------------------------------------------
## name Variables from other packages should pass
## failures 0
## cut
local $Other::Package::Foo;
$Other::Package::Foo;
#-----------------------------------------------------------------------------
## name Only cares about declarations
## failures 0
## cut
Foo();
$Foo = 42;
#-----------------------------------------------------------------------------
## name Constants must be all caps, passes
## failures 0
## cut
Readonly::Scalar my $CONSTANT = 23;
const my $CONSTANT = 23;
use constant FOO => 42;
use constant { BAR => 3, BAZ => 7 };
use constant 1.16 FOO => 42;
use constant 1.16 { BAR => 3, BAZ => 7 };
#-----------------------------------------------------------------------------
## name Constants must be all caps, failures
## failures 3
## cut
Readonly::Scalar my $Foo = 23;
Readonly::Scalar my $foo = 23;
const my $fooBAR = 23;
#-----------------------------------------------------------------------------
## name PPI misparses part of ternary as a label (RT #41170)
## failures 0
## cut
my $foo = $condition ? $objection->method : $alternative;
my $foo = $condition ? undef : 1;
END_SIMPLE_TESTS
return;
}
sub emit_primary_tests {
my ($test_file) = @_;
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'all_lower_case', 'guaranteed_to_pass', ':single_case', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'ALL_UPPER_CASE', 'guaranteed_to_pass', ':single_case', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'mixedCase', 'guaranteed_to_pass', ':single_case', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'a11_lower_case_with_digits', 'guaranteed_to_pass', ':single_case', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'A11_UPPER_CASE_WITH_DIGITS', 'guaranteed_to_pass', ':single_case', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'all_lower_case', 'guaranteed_to_pass', ':all_lower', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'ALL_UPPER_CASE', 'guaranteed_to_pass', ':all_lower', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'mixedCase', 'guaranteed_to_pass', ':all_lower', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'a11_lower_case_with_digits', 'guaranteed_to_pass', ':all_lower', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'A11_UPPER_CASE_WITH_DIGITS', 'guaranteed_to_pass', ':all_lower', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'all_lower_case', 'GUARANTEED_TO_PASS', ':all_upper', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'ALL_UPPER_CASE', 'GUARANTEED_TO_PASS', ':all_upper', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'mixedCase', 'GUARANTEED_TO_PASS', ':all_upper', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'a11_lower_case_with_digits', 'GUARANTEED_TO_PASS', ':all_upper', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'A11_UPPER_CASE_WITH_DIGITS', 'GUARANTEED_TO_PASS', ':all_upper', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'all_lower_case', 'guaranteed_to_pass', ':starts_with_lower', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'ALL_UPPER_CASE', 'guaranteed_to_pass', ':starts_with_lower', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file,
'________all_lower_case_with_leading_underscores',
'guaranteed_to_pass',
':starts_with_lower',
0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'a11_lower_case_with_digits', 'guaranteed_to_pass', ':starts_with_lower', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'A11_UPPER_CASE_WITH_DIGITS', 'guaranteed_to_pass', ':starts_with_lower', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'all_lower_case', 'GUARANTEED_TO_PASS', ':starts_with_upper', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'ALL_UPPER_CASE', 'GUARANTEED_TO_PASS', ':starts_with_upper', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file,
'________ALL_UPPER_CASE_WITH_LEADING_UNDERSCORES',
'GUARANTEED_TO_PASS',
':starts_with_upper',
0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'a11_lower_case_with_digits', 'GUARANTEED_TO_PASS', ':starts_with_upper', 1,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'A11_UPPER_CASE_WITH_DIGITS', 'GUARANTEED_TO_PASS', ':starts_with_upper', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'all_lower_case', 'guaranteed_to_pass', ':no_restriction', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'ALL_UPPER_CASE', 'guaranteed_to_pass', ':no_restriction', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'mixedCase', 'guaranteed_to_pass', ':no_restriction', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file,
'________ALL_UPPER_CASE_WITH_LEADING_UNDERSCORES',
'guaranteed_to_pass',
':no_restriction',
0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'a11_lower_case_with_digits', 'guaranteed_to_pass', ':no_restriction', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'A11_UPPER_CASE_WITH_DIGITS', 'guaranteed_to_pass', ':no_restriction', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'foobar', 'foo_guaranteed_to_pass_bar', 'foo.*bar', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'fooXYZZYbar', 'foo_guaranteed_to_pass_bar', 'foo.*bar', 0,
);
emit_all_tests_for_name_and_capitalization_scheme(
$test_file, 'xyzzy', 'foo_guaranteed_to_pass_bar', 'foo.*bar', 1,
);
return;
}
sub emit_all_tests_for_name_and_capitalization_scheme {
my ($test_file, $name, $guaranteed_to_pass, $capitalization_scheme, $failures)
= @_;
emit_package_test(
$test_file,
$name,
$guaranteed_to_pass,
$capitalization_scheme,
$failures
);
emit_subroutine_test(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_local_lexical_variable_in_subroutine_test(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_local_lexical_variable_in_scheduled_subroutine_test(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_scoped_lexical_variable_test(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_file_lexical_variable_test(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_global_variable_test(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_foreach_loop_variable_tests(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_c_style_for_loop_variable_tests(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_local_lexical_variable_in_io_assignment_in_while_loop_test(
$test_file, $name, $capitalization_scheme, $failures,
);
emit_label_test($test_file, $name, $capitalization_scheme, $failures);
return;
}
sub emit_package_test {
my ($test_file, $package_name, $good_package_component, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_PACKAGE_TEST";
#-----------------------------------------------------------------------------
## name Package named "$package_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { packages => '$capitalization_scheme' }
## cut
package $package_name;
#-----------------------------------------------------------------------------
## name Exempted package named "bLaHlAhLaH" vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { packages => '$capitalization_scheme', package_exemptions => 'bLa.*LaH' }
## cut
package bLaHlAhLaH;
#-----------------------------------------------------------------------------
## name Package named "${good_package_component}::$package_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { packages => '$capitalization_scheme' }
## cut
package ${good_package_component}::$package_name;
END_PACKAGE_TEST
return;
}
sub emit_subroutine_test {
my ($test_file, $subroutine_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_SUBROUTINE_TEST";
#-----------------------------------------------------------------------------
## name Subroutine named "$subroutine_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { subroutines => '$capitalization_scheme' }
## cut
sub $subroutine_name {
# Blah blah blah
}
#-----------------------------------------------------------------------------
## name Exempted subroutine named "bLaHlAhLaH" vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { subroutines => '$capitalization_scheme', subroutine_exemptions => 'bLa.*LaH' }
## cut
sub bLaHlAhLaH {
# Blah blah blah
}
#-----------------------------------------------------------------------------
## name Subroutine named "Foo::Bar::$subroutine_name" vs the "$capitalization_scheme" capitalization scheme.
## parms { subroutines => '$capitalization_scheme' }
## failures $failures
## cut
sub Foo::Bar::$subroutine_name;
END_SUBROUTINE_TEST
return;
}
sub emit_local_lexical_variable_in_subroutine_test {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_LOCAL_LEXICAL_VARIABLE_TEST";
#-----------------------------------------------------------------------------
## name Local lexical variable in subroutine named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { subroutines => ':all_lower', local_lexical_variables => '$capitalization_scheme' }
## cut
sub some_subroutine {
my \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Exempted local lexical variable in subroutine named "bLaHlAhLaH" vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { subroutines => ':all_lower', local_lexical_variables => '$capitalization_scheme', local_lexical_variable_exemptions => 'bLa.*LaH' }
## cut
sub some_subroutine {
my \$bLaHlAhLaH;
}
END_LOCAL_LEXICAL_VARIABLE_TEST
return;
}
sub emit_local_lexical_variable_in_scheduled_subroutine_test {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_LOCAL_LEXICAL_VARIABLE_TEST";
#-----------------------------------------------------------------------------
## name Local lexical variable in subroutine named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { local_lexical_variables => '$capitalization_scheme' }
## cut
CHECK {
my \$$variable_name;
}
END_LOCAL_LEXICAL_VARIABLE_TEST
return;
}
sub emit_scoped_lexical_variable_test {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_SCOPED_LEXICAL_VARIABLE_TEST";
#-----------------------------------------------------------------------------
## name Scoped lexical variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { scoped_lexical_variables => '$capitalization_scheme' }
## cut
{
my \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Exempted scoped lexical variable named "bLaHlAhLaH" vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { scoped_lexical_variables => '$capitalization_scheme', scoped_lexical_variable_exemptions => 'bLa.*LaH' }
## cut
{
my \$bLaHlAhLaH;
}
END_SCOPED_LEXICAL_VARIABLE_TEST
return;
}
sub emit_file_lexical_variable_test {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_FILE_LEXICAL_VARIABLE_TEST";
#-----------------------------------------------------------------------------
## name File lexical variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { file_lexical_variables => '$capitalization_scheme' }
## cut
my \$$variable_name;
#-----------------------------------------------------------------------------
## name Exempted file lexical variable named "bLaHlAhLaH" vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { file_lexical_variables => '$capitalization_scheme', file_lexical_variable_exemptions => 'bLa.*LaH' }
## cut
my \$bLaHlAhLaH;
END_FILE_LEXICAL_VARIABLE_TEST
return;
}
sub emit_global_variable_test {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
foreach my $variable_type ( qw< our local > ) {
print {$test_file} <<"END_FILE_LEXICAL_VARIABLE_TEST";
#-----------------------------------------------------------------------------
## name "$variable_type" variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { global_variables => '$capitalization_scheme' }
## cut
$variable_type \$$variable_name;
#-----------------------------------------------------------------------------
## name Exempted "$variable_type" variable named "bLaHlAhLaH" vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { global_variables => '$capitalization_scheme', global_variable_exemptions => 'bLa.*LaH' }
## cut
$variable_type \$bLaHlAhLaH;
END_FILE_LEXICAL_VARIABLE_TEST
}
return;
}
sub emit_foreach_loop_variable_tests {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_FOREACH_LOOP_VARIABLE_TESTS";
#-----------------------------------------------------------------------------
## name Local lexical variable as foreach loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { local_lexical_variables => '$capitalization_scheme' }
## cut
foreach my \$$variable_name (\@_) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name State variable as foreach loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { local_lexical_variables => '$capitalization_scheme' }
## cut
foreach state \$$variable_name (\@_) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Implied local lexical variable as foreach loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { local_lexical_variables => '$capitalization_scheme' }
## cut
foreach \$$variable_name (\@_) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Global variable as foreach loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { global_variables => '$capitalization_scheme' }
## cut
foreach our \$$variable_name (\@_) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Localized builtin variable
## failures 0
## cut
local \$\@;
#-----------------------------------------------------------------------------
## name Localized \$\\
## failures 0
## cut
# \$\\ was missing from the built in global exceptions
local \$\\;
END_FOREACH_LOOP_VARIABLE_TESTS
return;
}
sub emit_c_style_for_loop_variable_tests {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_C_STYLE_FOR_LOOP_VARIABLE_TESTS";
#-----------------------------------------------------------------------------
## name Local lexical variable as C-style for loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { local_lexical_variables => '$capitalization_scheme' }
## cut
for (my \$$variable_name = -7; \$$variable_name <= 17; \$$variable_name += 3) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name State variable as C-style for loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { local_lexical_variables => '$capitalization_scheme' }
## cut
# Declare the same variable twice in order to catch the case where the
# variable is the second one in the loop definition.
for (state \$$variable_name = -7; \$$variable_name <= 17; \$$variable_name += 3) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Global variable as C-style for loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { global_variables => '$capitalization_scheme' }
## cut
# Declare the same variable twice in order to catch the case where the
# variable is the second one in the loop definition.
for (our \$$variable_name = -7; \$$variable_name <= 17; \$$variable_name += 3) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Localized variable as C-style for loop variable named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { global_variables => '$capitalization_scheme' }
## cut
# Localize the same variable twice in order to catch the case where the
# variable is the second one in the loop definition.
for (local \$$variable_name = -7; \$$variable_name <= 17; \$$variable_name += 3) {
say \$$variable_name;
}
#-----------------------------------------------------------------------------
## name Localized builtin variable as C-style for loop variable vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { global_variables => '$capitalization_scheme' }
## cut
for (local \$EVAL_ERROR = -23; \$EVAL_ERROR <= 17; \$EVAL_ERROR += 3) {
say \$EVAL_ERROR;
}
#-----------------------------------------------------------------------------
## name Localized variable in another package as C-style for loop variable vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { global_variables => '$capitalization_scheme' }
## cut
for (local \$Foo::Baz = -23; \$Foo::Baz <= 17; \$Foo::Baz += 3) {
say \$Foo::Baz
}
END_C_STYLE_FOR_LOOP_VARIABLE_TESTS
return;
}
sub emit_local_lexical_variable_in_io_assignment_in_while_loop_test {
my ($test_file, $variable_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_LOCAL_LEXICAL_VARIABLE_TEST";
#-----------------------------------------------------------------------------
## name Local lexical variable, in I/O assignment in while loop, named "$variable_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { subroutines => ':all_lower', local_lexical_variables => '$capitalization_scheme' }
## cut
sub some_subroutine {
while (my \$$variable_name = <>) {
say \$$variable_name;
}
}
END_LOCAL_LEXICAL_VARIABLE_TEST
return;
}
sub emit_label_test {
my ($test_file, $label_name, $capitalization_scheme, $failures) = @_;
print {$test_file} <<"END_LABEL_TEST";
#-----------------------------------------------------------------------------
## name Label named "$label_name" vs the "$capitalization_scheme" capitalization scheme.
## failures $failures
## parms { labels => '$capitalization_scheme' }
## cut
$label_name:
while ( foo() ) {
next $label_name;
}
#-----------------------------------------------------------------------------
## name Exempted label named "bLaHlAhLaH" vs the "$capitalization_scheme" capitalization scheme.
## failures 0
## parms { labels => '$capitalization_scheme', label_exemptions => 'bLa.*LaH' }
## cut
bLaHlAhLaH:
while ( foo() ) {
next bLaHlAhLaH;
}
END_LABEL_TEST
return;
}
sub emit_footer {
my ($test_file) = @_;
print {$test_file} <<'END_FOOTER';
#-----------------------------------------------------------------------------
## name Variable in continue block gets handled as a local lexical and not a scoped lexical.
## failures 1
## parms { local_lexical_variables => ':all_upper', scoped_lexical_variables => ':all_lower' }
## cut
while (blah) {
blah;
}
continue {
my $this_should_be_local_and_not_scoped;
}
#-----------------------------------------------------------------------------
## name Builtin variables and variables in other packages are exempt.
## failures 0
## parms { global_variables => ':all_lower' }
## cut
local $EVAL_ERROR
local @ARGV;
local %INC;
local $Foo::Bar;
#-----------------------------------------------------------------------------
## name Test customization example in the Capitalization POD passing.
## failures 0
## parms { global_variables => 'G_(?:(?!_)\w)+', global_variable_exemptions => '.*THINGY.*' }
## cut
our $G_FooBar;
our $THINGY;
our @otherTHINGY;
#-----------------------------------------------------------------------------
## name Test customization example in the Capitalization POD failing.
## failures 4
## parms { global_variables => 'G_(?:(?!_)\w)+', global_variable_exemptions => '.*THINGY.*' }
## cut
our $FooBar;
our $G_;
our $G_foo_bar;
our @THING;
#-----------------------------------------------------------------------------
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 78
# indent-tabs-mode: nil
# c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
END_FOOTER
return;
}
#-----------------------------------------------------------------------------
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 78
# indent-tabs-mode: nil
# c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
|