summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/ast/ifstatement.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2010-02-08 20:17:38 +0100
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commite93eab81a58282db5306de6fec42703795c85523 (patch)
tree86968377febee8044e168ef3f4e1e528e6e32120 /spec/unit/parser/ast/ifstatement.rb
parentb8832725e2bf1933af0d583ddbd81c8a8db4ae8f (diff)
downloadpuppet-e93eab81a58282db5306de6fec42703795c85523.tar.gz
puppet-e93eab81a58282db5306de6fec42703795c85523.tar.xz
puppet-e93eab81a58282db5306de6fec42703795c85523.zip
Fix #3155 - prevent error when using two matching regex in cascade
The following manifest: case $var { /match/: { if $var =~ /matchagain/ { } } } is failing because the "=~" operators when matching sets an ephemeral variable in the scope. But the case regex also did it, and since they both belong to the same scope, and Puppet variables are immutables, the scope raises an error. This patch fixes this issue by adding to the current scope a stack of ephemeral symbol tables. Each new match operator or case/selector with regex adds a new scope. When we get out of the case/if/selector structure the scope is reset to the ephemeral level we were when entering it. This way the following manifest produces the correct output: case $var { /match(rematch)/: { notice("1. \$0 = $0, \$1 = $1") if $var =~ /matchagain/ { notice("2. \$0 = $0, \$1 = $1") } notice("3. \$0 = $0, \$1 = $1") } } notice("4. \$0 = $0") And the output is: 1. $0 = match, $1 = rematch 2. $0 = matchagain, $1 = rematch 3. $0 = match, $1 = rematch 4. $0 = Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit/parser/ast/ifstatement.rb')
-rwxr-xr-xspec/unit/parser/ast/ifstatement.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/spec/unit/parser/ast/ifstatement.rb b/spec/unit/parser/ast/ifstatement.rb
index 10d877a4b..83121cddd 100755
--- a/spec/unit/parser/ast/ifstatement.rb
+++ b/spec/unit/parser/ast/ifstatement.rb
@@ -64,10 +64,11 @@ describe Puppet::Parser::AST::IfStatement do
end
it "should reset ephemeral statements after evaluation" do
+ @scope.expects(:ephemeral_level).returns(:level)
Puppet::Parser::Scope.stubs(:true?).returns(true)
@stmt.expects(:safeevaluate).with(@scope)
- @scope.expects(:unset_ephemeral_var)
+ @scope.expects(:unset_ephemeral_var).with(:level)
@ifstmt.evaluate(@scope)
end