Signed-off-by: Luke Kanies <[email protected]>
---
lib/puppet/util/errors.rb | 12 ++++++++++++
spec/unit/util/errors.rb | 38 ++++++++++++++++++++++++++++++++++++++
spec/unit/util/inline_docs.rb | 2 +-
3 files changed, 51 insertions(+), 1 deletions(-)
create mode 100755 spec/unit/util/errors.rb
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
--
1.6.1
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.