[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5rc1-120-g2247c80

Mitchell Hashimoto mitchell.hashimoto at gmail.com
Mon Feb 7 06:40:41 UTC 2011


The following commit has been merged in the upstream branch:
commit c1b5c7f515a0add663fb532859d91e28ef37a971
Author: Mitchell Hashimoto <mitchell.hashimoto at gmail.com>
Date:   Sun Jan 16 14:27:24 2011 -0800

    (#5913) Fix Puppet::Application.find constant lookup behavior
    
    Puppet::Application.find now only looks in the Puppet::Application
    namespace for the given constant.

diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index f0159a6..17ad69c 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -212,10 +212,17 @@ class Application
     end
 
     def find(name)
-        self.const_get(name.to_s.capitalize)
-    rescue
+      klass = name.to_s.capitalize
+
+      # const_defined? is used before const_get since const_defined? will only
+      # check within our namespace, whereas const_get will check ancestor
+      # trees as well, resulting in unexpected behaviour.
+      if !self.const_defined?(klass)
         puts "Unable to find application '#{name.to_s}'."
         Kernel::exit(1)
+      end
+
+      self.const_get(klass)
     end
 
     def [](name)
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index f68a7e2..c0f9733 100755
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -16,6 +16,25 @@ describe Puppet::Application do
     Puppet.settings.stubs(:parse)
   end
 
+  describe "finding" do
+    before do
+      @klass = Puppet::Application
+      @klass.stubs(:puts)
+    end
+
+    it "should find classes in the namespace" do
+      @klass.find("Agent").should == @klass::Agent
+    end
+
+    it "should not find classes outside the namespace" do
+      lambda { @klass.find("String") }.should raise_error(SystemExit)
+    end
+
+    it "should exit if it can't find a class" do
+      lambda { @klass.find("ThisShallNeverEverEverExistAsdf") }.should raise_error(SystemExit)
+    end
+  end
+
   describe ".run_mode" do
     it "should default to user" do
       @appclass.run_mode.name.should == :user

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list