[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

James Turnbull james at lovedthanlost.net
Fri Jan 23 14:21:45 UTC 2009


The following commit has been merged in the master branch:
commit 3421954444f4c06d6e7b80430f89fccf56343fe2
Author: Luke Kanies <luke at madstop.com>
Date:   Tue Nov 25 22:20:39 2008 -0600

    Fixing #1755 - handling fully qualified classes correctly.
    
    This involves lexing '::class' tokens along with correctly
    looking them up from the Resource::Reference class.
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 69a46d0..a7b87e6 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -134,7 +134,7 @@ class Puppet::Parser::Lexer
         '*' => :TIMES,
         '<<' => :LSHIFT,
         '>>' => :RSHIFT,
-        %r{([a-z][-\w]*::)+[a-z][-\w]*} => :CLASSNAME,
+        %r{([a-z][-\w]*)?(::[a-z][-\w]*)+} => :CLASSNAME, # Require '::' in the class name, else we'd compete with NAME
         %r{((::){0,1}[A-Z][-\w]*)+} => :CLASSREF
     )
 
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb
index c597480..cb505d6 100644
--- a/lib/puppet/parser/resource/reference.rb
+++ b/lib/puppet/parser/resource/reference.rb
@@ -37,7 +37,7 @@ class Puppet::Parser::Resource::Reference < Puppet::ResourceReference
                 if self.title == :main
                     tmp = @scope.findclass("")
                 else
-                    unless tmp = @scope.findclass(self.title)
+                    unless tmp = @scope.parser.classes[self.title]
                         fail Puppet::ParseError, "Could not find class '%s'" % self.title
                     end
                 end
@@ -46,8 +46,9 @@ class Puppet::Parser::Resource::Reference < Puppet::ResourceReference
                     fail Puppet::ParseError, "Could not find node '%s'" % self.title
                 end
             else # normal definitions
-                # We have to swap these variables around so the errors are right.
-                tmp = @scope.finddefine(self.type)
+                # The resource type is capitalized, so we have to downcase.  Really,
+                # we should have a better interface for finding these, but eh.
+                tmp = @scope.parser.definitions[self.type.downcase]
             end
 
             if tmp
diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb
index 389f1fe..24c3463 100755
--- a/spec/unit/parser/lexer.rb
+++ b/spec/unit/parser/lexer.rb
@@ -208,6 +208,42 @@ describe Puppet::Parser::Lexer::TOKENS do
     end
 end
 
+describe Puppet::Parser::Lexer::TOKENS[:CLASSNAME] do
+    before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSNAME] }
+
+    it "should match against lower-case alpha-numeric terms separated by double colons" do
+        @token.regex.should =~ "one::two"
+    end
+
+    it "should match against many lower-case alpha-numeric terms separated by double colons" do
+        @token.regex.should =~ "one::two::three::four::five"
+    end
+
+    it "should match against lower-case alpha-numeric terms prefixed by double colons" do
+        @token.regex.should =~ "::one"
+    end
+end
+
+describe Puppet::Parser::Lexer::TOKENS[:CLASSREF] do
+    before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSREF] }
+
+    it "should match against single upper-case alpha-numeric terms" do
+        @token.regex.should =~ "One"
+    end
+
+    it "should match against upper-case alpha-numeric terms separated by double colons" do
+        @token.regex.should =~ "One::Two"
+    end
+
+    it "should match against many upper-case alpha-numeric terms separated by double colons" do
+        @token.regex.should =~ "One::Two::Three::Four::Five"
+    end
+
+    it "should match against upper-case alpha-numeric terms prefixed by double colons" do
+        @token.regex.should =~ "::One"
+    end
+end
+
 describe Puppet::Parser::Lexer::TOKENS[:NAME] do
     before { @token = Puppet::Parser::Lexer::TOKENS[:NAME] }
 
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
index 147f772..bb14526 100755
--- a/spec/unit/parser/resource/reference.rb
+++ b/spec/unit/parser/resource/reference.rb
@@ -72,4 +72,24 @@ describe Puppet::Parser::Resource::Reference, " when modeling defined types" do
         ref.builtin?.should be_false
         ref.definedtype.object_id.should  == @nodedef.object_id
     end
+
+    it "should only look for fully qualified classes" do
+        top = @parser.newclass "top"
+        sub = @parser.newclass "other::top"
+
+        scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :parser => @parser)
+
+        ref = @type.new(:type => "class", :title => "top", :scope => scope)
+        ref.definedtype.classname.should equal(top.classname)
+    end
+
+    it "should only look for fully qualified definitions" do
+        top = @parser.newdefine "top"
+        sub = @parser.newdefine "other::top"
+
+        scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :parser => @parser)
+
+        ref = @type.new(:type => "top", :title => "foo", :scope => scope)
+        ref.definedtype.classname.should equal(top.classname)
+    end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list