mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
assertions.rb: set default internal encoding
* test/lib/test/unit/assertions.rb (assert_raise_with_message): set default internal encoding to the excpected message, which affects String#inspect in messages. * test/lib/test/unit/assertions.rb (assert_warning): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
56417d1f24
commit
404bf57aaf
13 changed files with 53 additions and 78 deletions
|
@ -9,8 +9,6 @@ class Bug::Struct::Test_Member < Test::Unit::TestCase
|
|||
s = S.new(1)
|
||||
assert_equal(1, s.get(:a))
|
||||
assert_raise_with_message(NameError, /is not a struct member/) {s.get(:b)}
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
assert_raise_with_message(NameError, /\u{3042}/) {s.get(:"\u{3042}")}
|
||||
end
|
||||
assert_raise_with_message(NameError, /\u{3042}/) {s.get(:"\u{3042}")}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -123,21 +123,17 @@ module Test_Symbol
|
|||
end
|
||||
|
||||
def test_check_id_invalid_type
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1F431}/) {
|
||||
Bug::Symbol.pinneddown?(cx)
|
||||
}
|
||||
end
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1F431}/) {
|
||||
Bug::Symbol.pinneddown?(cx)
|
||||
}
|
||||
end
|
||||
|
||||
def test_check_symbol_invalid_type
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1F431}/) {
|
||||
Bug::Symbol.find(cx)
|
||||
}
|
||||
end
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1F431}/) {
|
||||
Bug::Symbol.find(cx)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -131,14 +131,20 @@ module Test
|
|||
raise TypeError, "Expected #{expected.inspect} to be a kind of String or Regexp, not #{expected.class}"
|
||||
end
|
||||
|
||||
ex = assert_raise(exception, msg || proc {"Exception(#{exception}) with message matches to #{expected.inspect}"}) {yield}
|
||||
ex = m = nil
|
||||
EnvUtil.with_default_internal(expected.encoding) do
|
||||
ex = assert_raise(exception, msg || proc {"Exception(#{exception}) with message matches to #{expected.inspect}"}) do
|
||||
yield
|
||||
end
|
||||
m = ex.message
|
||||
end
|
||||
msg = message(msg, "") {"Expected Exception(#{exception}) was raised, but the message doesn't match"}
|
||||
|
||||
if assert == :assert_equal
|
||||
assert_equal(expected, ex.message, msg)
|
||||
assert_equal(expected, m, msg)
|
||||
else
|
||||
msg = message(msg) { "Expected #{mu_pp expected} to match #{mu_pp ex.message}" }
|
||||
assert expected =~ ex.message, msg
|
||||
msg = message(msg) { "Expected #{mu_pp expected} to match #{mu_pp m}" }
|
||||
assert expected =~ m, msg
|
||||
block.binding.eval("proc{|_|$~=_}").call($~)
|
||||
end
|
||||
ex
|
||||
|
@ -626,7 +632,11 @@ eom
|
|||
end
|
||||
|
||||
def assert_warning(pat, msg = nil)
|
||||
stderr = EnvUtil.verbose_warning { yield }
|
||||
stderr = EnvUtil.verbose_warning {
|
||||
EnvUtil.with_default_internal(pat.encoding) {
|
||||
yield
|
||||
}
|
||||
}
|
||||
msg = message(msg) {diff pat, stderr}
|
||||
assert(pat === stderr, msg)
|
||||
end
|
||||
|
|
|
@ -544,9 +544,7 @@ class TestClass < Test::Unit::TestCase
|
|||
m = Module.new
|
||||
o = m.module_eval "class A\u{3042}; self; end.new"
|
||||
assert_raise_with_message(TypeError, /A\u{3042}/) {
|
||||
EnvUtil.with_default_internal(Encoding::UTF_8) {
|
||||
o::Foo
|
||||
}
|
||||
o::Foo
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -53,12 +53,10 @@ class TestConst < Test::Unit::TestCase
|
|||
name = "X\u{5b9a 6570}"
|
||||
c.const_set(name, 1)
|
||||
prev_line = __LINE__ - 1
|
||||
EnvUtil.with_default_internal(Encoding::UTF_8) do
|
||||
assert_warning(<<-WARNING) {c.const_set(name, 2)}
|
||||
assert_warning(<<-WARNING) {c.const_set(name, 2)}
|
||||
#{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::#{name}
|
||||
#{__FILE__}:#{prev_line}: warning: previous definition of #{name} was here
|
||||
WARNING
|
||||
end
|
||||
end
|
||||
|
||||
def test_redefinition_memory_leak
|
||||
|
|
|
@ -430,11 +430,9 @@ end.join
|
|||
bug3237 = '[ruby-core:29948]'
|
||||
str = "\u2600"
|
||||
id = :"\u2604"
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
msg = "undefined method `#{id}' for #{str.inspect}:String"
|
||||
assert_raise_with_message(NoMethodError, msg, bug3237) do
|
||||
str.__send__(id)
|
||||
end
|
||||
msg = "undefined method `#{id}' for \"#{str}\":String"
|
||||
assert_raise_with_message(NoMethodError, msg, bug3237) do
|
||||
str.__send__(id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -252,11 +252,9 @@ class TestMethod < Test::Unit::TestCase
|
|||
m = o.method(:bar).unbind
|
||||
assert_raise(TypeError) { m.bind(Object.new) }
|
||||
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1f431}/) {
|
||||
o.method(cx)
|
||||
}
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1f431}/) do
|
||||
o.method(cx)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -286,11 +284,9 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_raise(TypeError) do
|
||||
Class.new.class_eval { define_method(:bar, o.method(:bar)) }
|
||||
end
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1F431}/) {
|
||||
Class.new {define_method(cx) {}}
|
||||
}
|
||||
cx = EnvUtil.labeled_class("X\u{1f431}")
|
||||
assert_raise_with_message(TypeError, /X\u{1F431}/) do
|
||||
Class.new {define_method(cx) {}}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ class TestModule < Test::Unit::TestCase
|
|||
"\u3042",
|
||||
"Name?",
|
||||
].each do |name, msg|
|
||||
expected = "wrong constant name %s" % quote(name)
|
||||
expected = "wrong constant name %s" % name
|
||||
msg = "#{msg}#{': ' if msg}wrong constant name #{name.dump}"
|
||||
assert_raise_with_message(NameError, expected, "#{msg} to #{m}") do
|
||||
yield name
|
||||
|
@ -709,9 +709,7 @@ class TestModule < Test::Unit::TestCase
|
|||
assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32be"), :foo) }
|
||||
assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32le"), :foo) }
|
||||
cx = EnvUtil.labeled_class("X\u{3042}")
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) {
|
||||
assert_raise_with_message(TypeError, /X\u{3042}/) { c1.const_set(cx, :foo) }
|
||||
}
|
||||
assert_raise_with_message(TypeError, /X\u{3042}/) { c1.const_set(cx, :foo) }
|
||||
end
|
||||
|
||||
def test_const_get_invalid_name
|
||||
|
@ -1967,10 +1965,7 @@ class TestModule < Test::Unit::TestCase
|
|||
|
||||
name = "@\u{5909 6570}"
|
||||
assert_warning(/instance variable #{name} not initialized/) do
|
||||
val = EnvUtil.with_default_external(Encoding::UTF_8) {
|
||||
a.instance_eval(name)
|
||||
}
|
||||
assert_nil(val)
|
||||
assert_nil(a.instance_eval(name))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,18 +18,14 @@ class TestNumeric < Test::Unit::TestCase
|
|||
assert_raise_with_message(TypeError, /can't be coerced into /) {1|:foo}
|
||||
assert_raise_with_message(TypeError, /can't be coerced into /) {1^:foo}
|
||||
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
|
||||
end
|
||||
EnvUtil.with_default_external(Encoding::US_ASCII) do
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
|
||||
end
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
|
||||
assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
|
||||
|
||||
bug10711 = '[ruby-core:67405] [Bug #10711]'
|
||||
exp = "1.2 can't be coerced into Fixnum"
|
||||
|
|
|
@ -387,19 +387,15 @@ class TestObject < Test::Unit::TestCase
|
|||
|
||||
m = "\u{30e1 30bd 30c3 30c9}"
|
||||
c = Class.new
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
assert_raise_with_message(NameError, /#{m}/) do
|
||||
c.class_eval {remove_method m}
|
||||
end
|
||||
assert_raise_with_message(NameError, /#{m}/) do
|
||||
c.class_eval {remove_method m}
|
||||
end
|
||||
c = Class.new {
|
||||
define_method(m) {}
|
||||
remove_method(m)
|
||||
}
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) do
|
||||
assert_raise_with_message(NameError, /#{m}/) do
|
||||
c.class_eval {remove_method m}
|
||||
end
|
||||
assert_raise_with_message(NameError, /#{m}/) do
|
||||
c.class_eval {remove_method m}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -790,9 +790,7 @@ EXPECTED
|
|||
[].pack("\x7f")
|
||||
}
|
||||
assert_warning(/\A(.* in '\u{3042}'\n)+\z/) {
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) {
|
||||
[].pack("\u{3042}")
|
||||
}
|
||||
[].pack("\u{3042}")
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -112,9 +112,7 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_raise(TypeError){Rational(nil)}
|
||||
assert_raise(ArgumentError){Rational('')}
|
||||
assert_raise_with_message(ArgumentError, /\u{221a 2668}/) {
|
||||
EnvUtil.with_default_external(Encoding::UTF_8) {
|
||||
Rational("\u{221a 2668}")
|
||||
}
|
||||
Rational("\u{221a 2668}")
|
||||
}
|
||||
assert_raise(TypeError){Rational(Object.new)}
|
||||
assert_raise(ArgumentError){Rational()}
|
||||
|
|
|
@ -586,9 +586,7 @@ class TestRegexp < Test::Unit::TestCase
|
|||
key = "\u{3042}"
|
||||
[Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc|
|
||||
idx = key.encode(enc)
|
||||
EnvUtil.with_default_external(enc) do
|
||||
assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]}
|
||||
end
|
||||
assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue