[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Nick Lewis nick at puppetlabs.com
Tue May 10 08:12:40 UTC 2011


The following commit has been merged in the experimental branch:
commit 1954bbfe175ae7f18316e57af43362eb4ed73553
Author: Markus Roberts <Markus at reality.com>
Date:   Thu Oct 21 20:39:33 2010 -0700

    Refactor on the road to #5027 -- remove unused Scope#strinterp
    
    One of the uses of lookupvar was in the method Scope#strinterp; this method
    is no longer used (string interpolation is now handled by the parser (for
    the syntax) and AST nodes (for the semantics)) so this use of lookupvar can
    be excised, along with a fair amount of surrounding code.

diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index df30791..7703299 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -343,65 +343,6 @@ class Puppet::Parser::Scope
     end
   end
 
-  # Return an interpolated string.
-  def strinterp(string, file = nil, line = nil)
-    # Most strings won't have variables in them.
-    ss = StringScanner.new(string)
-    out = ""
-    while not ss.eos?
-      if ss.scan(/^\$\{((\w*::)*\w+|[0-9]+)\}|^\$([0-9])|^\$((\w*::)*\w+)/)
-        # If it matches the backslash, then just retun the dollar sign.
-        if ss.matched == '\\$'
-          out << '$'
-        else # look the variable up
-          # make sure $0-$9 are lookupable only if ephemeral
-          var = ss[1] || ss[3] || ss[4]
-          if var and var =~ /^[0-9]+$/ and not ephemeral_include?(var)
-            next
-          end
-          out << undef_as('',lookupvar(var)).to_s
-        end
-      elsif ss.scan(/^\\(.)/)
-        # Puppet.debug("Got escape: pos:%d; m:%s" % [ss.pos, ss.matched])
-        case ss[1]
-        when 'n'
-          out << "\n"
-        when 't'
-          out << "\t"
-        when 's'
-          out << " "
-        when '\\'
-          out << '\\'
-        when '$'
-          out << '$'
-        else
-          str = "Unrecognised escape sequence '#{ss.matched}'"
-          str += " in file #{file}" if file
-          str += " at line #{line}" if line
-          Puppet.warning str
-          out << ss.matched
-        end
-      elsif ss.scan(/^\$/)
-        out << '$'
-      elsif ss.scan(/^\\\n/) # an escaped carriage return
-        next
-      else
-        tmp = ss.scan(/[^\\$]+/)
-        # Puppet.debug("Got other: pos:%d; m:%s" % [ss.pos, tmp])
-        unless tmp
-          error = Puppet::ParseError.new("Could not parse string #{string.inspect}")
-          {:file= => file, :line= => line}.each do |m,v|
-            error.send(m, v) if v
-          end
-          raise error
-        end
-        out << tmp
-      end
-    end
-
-    out
-  end
-
   # Return the tags associated with this scope.  It's basically
   # just our parents' tags, plus our type.  We don't cache this value
   # because our parent tags might change between calls.
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index b37cb4a..17f485c 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -376,149 +376,6 @@ describe Puppet::Parser::Scope do
     end
   end
 
-  describe "when interpolating string" do
-    (0..9).each do |n|
-      it "should allow $#{n} to match" do
-        @scope.setvar(n.to_s, "value", :ephemeral => true)
-
-        @scope.strinterp("$#{n}").should == "value"
-      end
-    end
-
-    (0..9).each do |n|
-      it "should not allow $#{n} to match if not ephemeral" do
-        @scope.setvar(n.to_s, "value", :ephemeral => false)
-
-        @scope.strinterp("$#{n}").should_not == "value"
-      end
-    end
-
-    it "should not allow $10 to match" do
-      @scope.setvar("10", "value", :ephemeral => true)
-
-      @scope.strinterp('==$10==').should_not == "==value=="
-    end
-
-    it "should not allow ${10} to match" do
-      @scope.setvar("10", "value", :ephemeral => true)
-
-      @scope.strinterp('==${10}==').should == "==value=="
-    end
-
-    describe "with qualified variables" do
-      before do
-        @scopes = {}
-        klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, ""))
-        Puppet::Parser::Resource.new("class", :main, :scope => @scope, :source => mock('source')).evaluate
-        @scopes[""] = @scope.class_scope(klass)
-        @scopes[""].setvar("test", "value")
-
-        %w{one one::two one::two::three}.each do |name|
-          klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, name))
-          Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate
-          @scopes[name] = @scope.class_scope(klass)
-          @scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}")
-        end
-      end
-      {
-        "===${one::two::three::test}===" => "===value-three===",
-        "===$one::two::three::test===" => "===value-three===",
-        "===${one::two::test}===" => "===value-two===",
-        "===$one::two::test===" => "===value-two===",
-        "===${one::test}===" => "===value-one===",
-        "===$one::test===" => "===value-one===",
-        "===${::test}===" => "===value===",
-        "===$::test===" => "===value==="
-      }.each do |input, output|
-        it "should parse '#{input}' correctly" do
-          @scope.strinterp(input).should == output
-        end
-      end
-    end
-
-    tests = {
-      "===${test}===" => "===value===",
-      "===${test} ${test} ${test}===" => "===value value value===",
-      "===$test ${test} $test===" => "===value value value===",
-      "===\\$test===" => "===$test===",
-      '===\\$test string===' => "===$test string===",
-      '===$test string===' => "===value string===",
-      '===a testing $===' => "===a testing $===",
-      '===a testing \$===' => "===a testing $===",
-      "===an escaped \\\n carriage return===" => "===an escaped  carriage return===",
-      '\$' => "$",
-      '\s' => "\s",
-      '\t' => "\t",
-      '\n' => "\n"
-    }
-
-    tests.each do |input, output|
-      it "should parse '#{input}' correctly" do
-        @scope.setvar("test", "value")
-        @scope.strinterp(input).should == output
-      end
-    end
-
-    # #523
-    %w{d f h l w z}.each do |l|
-      it "should parse '#{l}' when escaped" do
-        string = "\\#{l}"
-        @scope.strinterp(string).should == string
-      end
-    end
-  end
-
-  def test_strinterp
-    # Make and evaluate our classes so the qualified lookups work
-    parser = mkparser
-    klass = parser.newclass("")
-    scope = mkscope(:parser => parser)
-    Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => scope, :source => mock('source')).evaluate
-
-    assert_nothing_raised {
-      scope.setvar("test","value")
-    }
-
-    scopes = {"" => scope}
-
-    %w{one one::two one::two::three}.each do |name|
-      klass = parser.newclass(name)
-      Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate
-      scopes[name] = scope.class_scope(klass)
-      scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}")
-    end
-
-    assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly")
-    tests.each do |input, output|
-      assert_nothing_raised("Failed to scan #{input.inspect}") do
-        assert_equal(output, scope.strinterp(input), 'did not parserret %s correctly' % input.inspect)
-      end
-    end
-
-    logs = []
-    Puppet::Util::Log.close
-    Puppet::Util::Log.newdestination(logs)
-
-    # #523
-    %w{d f h l w z}.each do |l|
-      string = "\\#{l}"
-      assert_nothing_raised do
-
-              assert_equal(
-        string, scope.strinterp(string),
-        
-          'did not parserret %s correctly' % string)
-      end
-
-
-            assert(
-        logs.detect { |m| m.message =~ /Unrecognised escape/ },
-        
-        "Did not get warning about escape sequence with #{string}")
-      logs.clear
-    end
-  end
-
   describe "when setting ephemeral vars from matches" do
     before :each do
       @match = stub 'match', :is_a? => true

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list