diff options
author | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-05 00:59:02 +0000 |
---|---|---|
committer | ntalbott <ntalbott@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-05 00:59:02 +0000 |
commit | a2108abc5b0f46650cc33e2e9574c3c7e5edb499 (patch) | |
tree | b3c7cbdee651561c4f9439798ea932b1ac0d9622 /lib/test | |
parent | 36df633da547e9c35f86c471e25f3625938a14ba (diff) | |
download | ruby-a2108abc5b0f46650cc33e2e9574c3c7e5edb499.tar.gz ruby-a2108abc5b0f46650cc33e2e9574c3c7e5edb499.tar.xz ruby-a2108abc5b0f46650cc33e2e9574c3c7e5edb499.zip |
* lib/test/unit/assertions.rb: will use pp for output if available.
Can be disabled by setting Assertions.use_pp = false.
* test/testunit/test_assertions.rb: made a small change to exception
formatting.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/test')
-rw-r--r-- | lib/test/unit/assertions.rb | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb index 23e578927..fdb9632e0 100644 --- a/lib/test/unit/assertions.rb +++ b/lib/test/unit/assertions.rb @@ -336,15 +336,28 @@ EOT private def add_assertion end + + # Select whether or not to use the prettyprinter. If this + # option is set to false before any assertions are made, the + # prettyprinter will not be required at all. + public + def self.use_pp=(value) + AssertionMessage.use_pp = value + end class AssertionMessage # :nodoc: all + @use_pp = true + class << self + attr_accessor :use_pp + end + class Literal def initialize(value) @value = value end def inspect - @value + @value.to_s end end @@ -383,15 +396,25 @@ EOT def convert(object) case object when Exception - return <<EOM.chop -Class: <#{object.class}> -Message: <#{object.message}> + <<EOM.chop +Class: <#{convert(object.class)}> +Message: <#{convert(object.message)}> ---Backtrace--- #{filter_backtrace(object.backtrace).join("\n")} --------------- EOM else - return object.inspect + if(self.class.use_pp) + begin + require 'pp' + rescue LoadError + self.class.use_pp = false + return object.inspect + end unless(defined?(PP)) + PP.pp(object, '').chomp + else + object.inspect + end end end |