chdir 't' if -d 't';
require './test.pl';
}
-plan tests => 79;
+plan tests => 85;
+
+my $list_assignment_supported = 1;
+
+#mg.c says list assignment not supported on VMS, EPOC, and SYMBIAN.
+$list_assignment_supported = 0 if ($^O eq 'VMS');
+
sub foo {
local($a, $b) = @_;
shift @a;
}
is($a[0].$a[1], "Xb");
+{
+ my $d = "@a";
+ local @a = @a;
+ is("@a", $d);
+}
%h = ('a' => 1, 'b' => 2, 'c' => 3);
{
}
is($h{'a'}, 1);
is($h{'b'}, 2);
+{
+ my $d = join("\n", map { "$_=>$h{$_}" } sort keys %h);
+ local %h = %h;
+ is(join("\n", map { "$_=>$h{$_}" } sort keys %h), $d);
+}
is($h{'c'}, 3);
# check for scope leakage
is($a[1], 'b');
is($a[2], 'c');
ok(!defined $a[0]);
+{
+ my $d = "@a";
+ local @a = @a;
+ is("@a", $d);
+}
{
package TH;
sub EXISTS { print "# EXISTS [@_]\n"; exists $_[0]->{$_[1]}; }
sub DELETE { print "# DELETE [@_]\n"; delete $_[0]->{$_[1]}; }
sub CLEAR { print "# CLEAR [@_]\n"; %{$_[0]} = (); }
+ sub FIRSTKEY { print "# FIRSTKEY [@_]\n"; keys %{$_[0]}; each %{$_[0]} }
+ sub NEXTKEY { print "# NEXTKEY [@_]\n"; each %{$_[0]} }
}
# see if localization works on tied hashes
# local() should preserve the existenceness of tied hash elements
ok(! exists $h{'y'});
ok(! exists $h{'z'});
+TODO: {
+ todo_skip("Localize entire tied hash");
+ my $d = join("\n", map { "$_=>$h{$_}" } sort keys %h);
+ local %h = %h;
+ is(join("\n", map { "$_=>$h{$_}" } sort keys %h), $d);
+}
@a = ('a', 'b', 'c');
{
is($SIG{TERM}, 'main::foo');
is($SIG{INT}, \&foo);
is($SIG{__WARN__}, \&foo);
+{
+ my $d = join("\n", map { "$_=>$SIG{$_}" } sort keys %SIG);
+ local %SIG = %SIG;
+ is(join("\n", map { "$_=>$SIG{$_}" } sort keys %SIG), $d);
+}
# and for %ENV
ok(! exists $ENV{_A_});
ok(! exists $ENV{_B_});
+SKIP: {
+ skip("Can't make list assignment to \%ENV on this system")
+ unless $list_assignment_supported;
+ my $d = join("\n", map { "$_=>$ENV{$_}" } sort keys %ENV);
+ local %ENV = %ENV;
+ is(join("\n", map { "$_=>$ENV{$_}" } sort keys %ENV), $d);
+}
+
# does implicit localization in foreach skip magic?
$_ = "o 0,o 1,";