|
5 | 5 | set_up_inc("../lib"); |
6 | 6 | } |
7 | 7 |
|
8 | | -plan 167; |
| 8 | +plan 188; |
9 | 9 |
|
10 | 10 | eval '\$x = \$y'; |
11 | 11 | like $@, qr/^Experimental aliasing via reference not enabled/, |
@@ -651,3 +651,55 @@ pass("RT #123821"); |
651 | 651 | is("$h{one} $h{two} $h{three}", "102 200 301", "rt #133538 %h still aliased"); |
652 | 652 |
|
653 | 653 | } |
| 654 | +{ |
| 655 | + use feature 'refaliasing', 'declared_refs'; |
| 656 | + no warnings 'experimental::declared_refs'; |
| 657 | + my %hash = ( locked => "k1", normal => "k2" ); |
| 658 | + Internals::SvREADONLY(%hash, 1); |
| 659 | + Internals::SvREADONLY($hash{locked}, 1); |
| 660 | + my $href = \%hash; |
| 661 | + my $val = "val"; |
| 662 | + ok(!eval { \$hash{locked} = \$val; 1}, |
| 663 | + "Eval alias of readonly hash key in restricted hash died"); |
| 664 | + like($@,qr/Attempt to alias readonly key "locked" in restricted hash at/, |
| 665 | + "Got the error we expected"); |
| 666 | + ok(!eval { local \$hash{locked} = \$val; 1}, |
| 667 | + "Eval local alias of readonly hash key in restricted hash died"); |
| 668 | + like($@,qr/Attempt to alias readonly key "locked" in restricted hash at/, |
| 669 | + "Got the error we expected"); |
| 670 | + ok(!eval { local $hash{locked} = $val; 1}, |
| 671 | + "Eval localization of readonly hash key in restricted hash died"); |
| 672 | + like($@,qr/Attempt to localize readonly key "locked" in restricted hash at/, |
| 673 | + "Got the error we expected"); |
| 674 | + ok(!eval { \$href->{locked} = \$val; 1}, |
| 675 | + "Eval alias of readonly hashref key in restricted hash died"); |
| 676 | + like($@,qr/Attempt to alias readonly key "locked" in restricted hash at/, |
| 677 | + "Got the error we expected"); |
| 678 | + ok(!eval { local \$href->{locked} = \$val; 1}, |
| 679 | + "Eval local alias of readonly hashref key in restricted hash died"); |
| 680 | + like($@,qr/Attempt to alias readonly key "locked" in restricted hash at/, |
| 681 | + "Got the error we expected"); |
| 682 | + ok(!eval { local $href->{locked} = $val; 1}, |
| 683 | + "Eval localization of readonly hashref key in restricted hash died"); |
| 684 | + like($@,qr/Attempt to localize readonly key "locked" in restricted hash at/, |
| 685 | + "Got the error we expected"); |
| 686 | + ok(eval { { local \$hash{normal} = \1; } 1}, |
| 687 | + "Eval unlocalization of aliased readonly hash key should not die"); |
| 688 | + ok(eval { { local $hash{normal} = 1; Internals::SvREADONLY($hash{normal},1); } 1}, |
| 689 | + "Eval unlocalization of readonly hash key should not die"); |
| 690 | + ok(eval { { local $hash{normal} = 1; Internals::SvREADONLY($hash{normal},1); } 1}, |
| 691 | + "Eval unlocalization of readonly hash key should not die"); |
| 692 | + ok(eval { { local \$hash->{normal} = \1; } 1}, |
| 693 | + "Eval unlocalization of aliased readonly hashref key should not die"); |
| 694 | + ok(eval { { local $hash->{normal} = 1; Internals::SvREADONLY($hash{normal},1); } 1}, |
| 695 | + "Eval unlocalization of readonly hashref key should not die"); |
| 696 | + ok(!eval { { local \$hash{normal} = \1; local \$hash{normal} = \2; } 1}, |
| 697 | + "Eval aliased localization of localized aliased readonly hash key should die"); |
| 698 | + like($@,qr/Attempt to alias readonly key \"normal\" in restricted hash/, |
| 699 | + "Got the error we expected"); |
| 700 | + ok(!eval { { local $hash{normal} = 1; Internals::SvREADONLY($hash{normal},1); |
| 701 | + local $hash{normal} = 2; } 1}, |
| 702 | + "Eval localization of localized readonly hash key should die"); |
| 703 | + like($@,qr/Attempt to localize readonly key \"normal\" in restricted hash/, |
| 704 | + "Got the error we expected"); |
| 705 | +} |
0 commit comments