зеркало из https://github.com/github/ruby.git
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@4687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
82f064a524
Коммит
cc32628660
10
ChangeLog
10
ChangeLog
|
@ -1,4 +1,12 @@
|
|||
Sun Oct 5 :00 2003 Nathaniel Talbott <ntalbott@ruby-lang.org>
|
||||
Sun Oct 5 09:52:00 2003 Nathaniel Talbott <ntalbott@ruby-lang.org>
|
||||
|
||||
* 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.
|
||||
|
||||
Sun Oct 5 07:42:00 2003 Nathaniel Talbott <ntalbott@ruby-lang.org>
|
||||
|
||||
* lib/test/unit/assertions.rb: made small improvements to assertion
|
||||
messages. Deprecated Assertions#assert_not_nil; use #assert instead.
|
||||
|
|
|
@ -337,14 +337,27 @@ EOT
|
|||
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
|
||||
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
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ module Test
|
|||
1 + 1
|
||||
}
|
||||
}
|
||||
check_fails(%r{\Afailed assert_raises.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\nMessage: <Error>\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
check_fails(%r{\Afailed assert_raises.\n<ArgumentError> exception expected but was\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
assert_raises(ArgumentError, "failed assert_raises") {
|
||||
raise "Error"
|
||||
}
|
||||
|
@ -265,17 +265,17 @@ module Test
|
|||
rescue ZeroDivisionError
|
||||
end
|
||||
}
|
||||
check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <Error>\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
assert_nothing_raised {
|
||||
raise "Error"
|
||||
}
|
||||
}
|
||||
check_fails(%r{\Afailed assert_nothing_raised\.\nException raised:\nClass: <RuntimeError>\nMessage: <Error>\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
check_fails(%r{\Afailed assert_nothing_raised\.\nException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
assert_nothing_raised("failed assert_nothing_raised") {
|
||||
raise "Error"
|
||||
}
|
||||
}
|
||||
check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <Error>\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
|
||||
assert_nothing_raised(StandardError, RuntimeError) {
|
||||
raise "Error"
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче