summaryrefslogtreecommitdiff
path: root/t/cmd
diff options
context:
space:
mode:
authorGerard Goossen <gerard@ggoossen.net>2010-12-16 22:12:33 +0100
committerZefram <zefram@fysh.org>2011-01-08 13:38:39 +0000
commit5e17f11b6866c2782e630759465df4d324d3844b (patch)
treed8bf85cff5ad15bcf7340fffab277549604ce4d5 /t/cmd
parent138b82305768bfde5e5870f82ece1425da54f8e5 (diff)
downloadperl-5e17f11b6866c2782e630759465df4d324d3844b.tar.gz
more while tests
Add some while tests, about the context of the last statement in a block and about reinitializaiton of lexical variables.
Diffstat (limited to 't/cmd')
-rw-r--r--t/cmd/while.t39
1 files changed, 38 insertions, 1 deletions
diff --git a/t/cmd/while.t b/t/cmd/while.t
index 06ff20057f..5107fe286d 100644
--- a/t/cmd/while.t
+++ b/t/cmd/while.t
@@ -4,7 +4,7 @@ BEGIN {
require "test.pl";
}
-plan(20);
+plan(25);
my $tmpfile = tempfile();
open (tmp,'>', $tmpfile) || die "Can't create Cmd_while.tmp.";
@@ -175,3 +175,40 @@ is($` . $& . $', "abc");
}
ok($ok);
}
+
+sub save_context { $_[0] = wantarray; $_[1] }
+
+{
+ my $context = -1;
+ my $p = sub {
+ my $x = 1;
+ while ($x--) {
+ save_context($context, "foo");
+ }
+ };
+ is(scalar($p->()), 0);
+ is($context, undef, "last statement in while block has 'void' context");
+}
+
+{
+ my $context = -1;
+ my $p = sub {
+ my $x = 1;
+ {
+ save_context($context, "foo");
+ }
+ };
+ is(scalar($p->()), "foo");
+ is($context, "", "last statement in block has 'scalar' context");
+}
+
+{
+ # test scope is cleaned
+ my $i = 0;
+ my @a;
+ while ($i++ < 2) {
+ my $x;
+ push @a, \$x;
+ }
+ ok($a[0] ne $a[1]);
+}