[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

James Turnbull james at lovedthanlost.net
Wed Jul 14 10:29:37 UTC 2010


The following commit has been merged in the upstream branch:
commit 39d4a935d47f1d42241ce492c48818dc5b533c29
Author: Luke Kanies <luke at madstop.com>
Date:   Fri Oct 23 15:49:48 2009 -0700

    Adding a context method to the Errors module
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/lib/puppet/util/errors.rb b/lib/puppet/util/errors.rb
index badba59..0d2f2da 100644
--- a/lib/puppet/util/errors.rb
+++ b/lib/puppet/util/errors.rb
@@ -17,6 +17,18 @@ module Puppet::Util::Errors
         return error
     end
 
+    def error_context
+        if file and line
+            " at #{file}:#{line}"
+        elsif line
+            " at line #{line}"
+        elsif file
+            " in #{file}"
+        else
+            ""
+        end
+    end
+
     # Wrap a call in such a way that we always throw the right exception and keep
     # as much context as possible.
     def exceptwrap(options = {})
diff --git a/spec/unit/util/errors.rb b/spec/unit/util/errors.rb
new file mode 100755
index 0000000..e30b85d
--- /dev/null
+++ b/spec/unit/util/errors.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/util/errors'
+
+class ErrorTester
+    include Puppet::Util::Errors
+    attr_accessor :line, :file
+end
+
+describe Puppet::Util::Errors do
+    before do
+        @tester = ErrorTester.new
+    end
+
+    it "should provide a 'fail' method" do
+        @tester.should respond_to(:fail)
+    end
+
+    it "should provide a 'devfail' method" do
+        @tester.should respond_to(:devfail)
+    end
+
+    it "should raise any provided error when failing" do
+        lambda { @tester.fail(Puppet::ParseError, "stuff") }.should raise_error(Puppet::ParseError)
+    end
+
+    it "should default to Puppet::Error when failing" do
+        lambda { @tester.fail("stuff") }.should raise_error(Puppet::Error)
+    end
+
+    it "should have a method for converting error context into a string" do
+        @tester.file = "/my/file"
+        @tester.line = 50
+        @tester.error_context.should == " at /my/file:50"
+    end
+end
diff --git a/spec/unit/util/inline_docs.rb b/spec/unit/util/inline_docs.rb
index c541d01..a03939e 100755
--- a/spec/unit/util/inline_docs.rb
+++ b/spec/unit/util/inline_docs.rb
@@ -2,7 +2,7 @@
 
 Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
 
-require 'puppet/util/file_locking'
+require 'puppet/util/inline_docs'
 
 class InlineDoccer
     include Puppet::Util::InlineDocs

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list