[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 51bcebe38cab6088c901f1006339bbe40a36d161

James Turnbull james at lovedthanlost.net
Wed Aug 18 05:55:39 UTC 2010


The following commit has been merged in the upstream branch:
commit 810980659d86a30cc9dde6018a4749f659fe2d00
Author: Peter Meier <peter.meier at immerda.ch>
Date:   Sat Nov 7 12:10:29 2009 +0100

    introduce a warn mechanism for debugging
    
    We can now warn messages that will be passed to Kernel.warn if
    debugging is enabled.

diff --git a/lib/facter.rb b/lib/facter.rb
index 3c69a94..ac06f68 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -68,11 +68,15 @@ module Facter
         if string.nil?
             return
         end
-        if @@debug != 0
+        if self.debugging?
             puts GREEN + string + RESET
         end
     end
 
+    def self.debugging?
+        @@debug != 0
+    end
+
     # Return a fact object by name.  If you use this, you still have to call
     # 'value' on it to retrieve the actual value.
     def self.[](name)
@@ -173,6 +177,13 @@ module Facter
         end
     end
 
+
+    def self.warn(msg)
+        if Facter.debugging? and msg and not msg.empty?
+            msg.each { |line| Kernel.warn line }
+        end
+    end
+
     # Remove them all.
     def self.reset
         @collection = nil
diff --git a/spec/unit/facter.rb b/spec/unit/facter.rb
index f248aa7..9f7b4cf 100755
--- a/spec/unit/facter.rb
+++ b/spec/unit/facter.rb
@@ -131,6 +131,79 @@ describe Facter do
         Facter.should respond_to(:search_path)
     end
 
+    it "should have a method to query debugging mode" do
+        Facter.should respond_to(:debugging?)
+    end
+
+    it "should have a method to warn" do
+        Facter.should respond_to(:warn)
+    end
+
+    describe "when warning" do
+        it "should warn if debugging is enabled" do
+          Facter.debugging(true)
+          Kernel.stubs(:warn)
+          Kernel.expects(:warn).with('foo')
+          Facter.warn('foo')
+        end
+
+        it "should not warn if debugging is enabled but nil is passed" do
+          Facter.debugging(true)
+          Kernel.stubs(:warn)
+          Kernel.expects(:warn).never
+          Facter.warn(nil)
+        end
+
+        it "should not warn if debugging is enabled but an empyt string is passed" do
+          Facter.debugging(true)
+          Kernel.stubs(:warn)
+          Kernel.expects(:warn).never
+          Facter.warn('')
+        end
+
+        it "should not warn if debugging is disabled" do
+          Facter.debugging(false)
+          Kernel.stubs(:warn)
+          Kernel.expects(:warn).never
+          Facter.warn('foo')
+        end
+
+        it "should warn for any given element for an array if debugging is enabled" do
+          Facter.debugging(true)
+          Kernel.stubs(:warn)
+          Kernel.expects(:warn).with('foo')
+          Kernel.expects(:warn).with('bar')
+          Facter.warn( ['foo','bar'])
+        end
+    end
+
+    describe "when setting debugging mode" do
+        it "should have debugging enabled using 1" do
+            Facter.debugging(1)
+            Facter.should be_debugging
+        end
+        it "should have debugging enabled using true" do
+            Facter.debugging(true)
+            Facter.should be_debugging
+        end
+        it "should have debugging enabled using any string except off" do
+            Facter.debugging('aaaaa')
+            Facter.should be_debugging
+        end
+        it "should have debugging disabled using 0" do
+            Facter.debugging(0)
+            Facter.should_not be_debugging
+        end
+        it "should have debugging disabled using false" do
+            Facter.debugging(false)
+            Facter.should_not be_debugging
+        end
+        it "should have debugging disabled using the string 'off'" do
+            Facter.debugging('off')
+            Facter.should_not be_debugging
+        end
+    end
+
     describe "when registering directories to search" do
         after { Facter.instance_variable_set("@search_path", []) }
 

-- 
Packaging of Facter for debian



More information about the Pkg-puppet-devel mailing list