diff options
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_beginendblock.rb | 9 | ||||
-rw-r--r-- | test/ruby/test_bignum.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_file.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_io_m17n.rb | 10 | ||||
-rw-r--r-- | test/ruby/test_iseq.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 17 | ||||
-rw-r--r-- | test/ruby/test_object.rb | 11 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_require.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_signal.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_sprintf.rb | 54 | ||||
-rw-r--r-- | test/ruby/test_super.rb | 3 |
14 files changed, 61 insertions, 83 deletions
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb index 909702a9e5..0543476875 100644 --- a/test/ruby/test_beginendblock.rb +++ b/test/ruby/test_beginendblock.rb @@ -32,22 +32,19 @@ class TestBeginEndBlock < Test::Unit::TestCase end def test_begininmethod - e = assert_raise(SyntaxError) do + assert_raise_with_message(SyntaxError, /BEGIN is permitted only at toplevel/) do eval("def foo; BEGIN {}; end") end - assert_match(/BEGIN is permitted only at toplevel/, e.message) - e = assert_raise(SyntaxError) do + assert_raise_with_message(SyntaxError, /BEGIN is permitted only at toplevel/) do eval('eval("def foo; BEGIN {}; end")') end - assert_match(/BEGIN is permitted only at toplevel/, e.message) end def test_begininclass - e = assert_raise(SyntaxError) do + assert_raise_with_message(SyntaxError, /BEGIN is permitted only at toplevel/) do eval("class TestBeginEndBlock; BEGIN {}; end") end - assert_match(/BEGIN is permitted only at toplevel/, e.message) end def test_endblockwarn diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 4d87d5fca3..2c6eda0d8e 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -634,8 +634,7 @@ class TestBignum < Test::Unit::TestCase if (big = 2**31-1).is_a?(Fixnum) return end - e = assert_raise(RangeError) {(1 << big).to_s} - assert_match(/too big to convert/, e.message) + assert_raise_with_message(RangeError, /too big to convert/) {(1 << big).to_s} end def test_fix_fdiv diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index b7b41db1cd..95db1308e7 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -28,7 +28,7 @@ class TestException < Test::Unit::TestCase def test_exception_in_rescue string = "this must be handled no.3" - e = assert_raise(RuntimeError) do + assert_raise_with_message(RuntimeError, string) do begin raise "exception in rescue clause" rescue @@ -36,12 +36,11 @@ class TestException < Test::Unit::TestCase end assert(false) end - assert_equal(string, e.message) end def test_exception_in_ensure string = "exception in ensure clause" - e = assert_raise(RuntimeError) do + assert_raise_with_message(RuntimeError, string) do begin raise "this must be handled no.4" ensure @@ -51,7 +50,6 @@ class TestException < Test::Unit::TestCase end assert(false) end - assert_equal(string, e.message) end def test_exception_ensure @@ -333,8 +331,10 @@ end.join bug3237 = '[ruby-core:29948]' str = "\u2600" id = :"\u2604" - e = assert_raise(NoMethodError) {str.__send__(id)} - assert_equal("undefined method `#{id}' for #{str.inspect}:String", e.message, bug3237) + msg = "undefined method `#{id}' for #{str.inspect}:String" + assert_raise_with_message(NoMethodError, msg, bug3237) do + str.__send__(id) + end end def test_errno diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 4a1f03cb00..41debbbb1c 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -339,8 +339,9 @@ class TestFile < Test::Unit::TestCase end def test_file_open_double_mode - e = assert_raise(ArgumentError) { File.open("a", 'w', :mode => 'rw+') } - assert_equal 'mode specified twice', e.message + assert_raise_with_message(ArgumentError, 'mode specified twice') { + File.open("a", 'w', :mode => 'rw+') + } end def test_conflicting_encodings diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 718cddf7fc..c86384ee0b 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2098,8 +2098,9 @@ End assert_equal(["foo\n", "bar\n", "baz\n"], a, bug) bug6054 = '[ruby-dev:45267]' - e = assert_raise(IOError, bug6054) {IO.foreach(t.path, mode:"w").next} - assert_match(/not opened for reading/, e.message, bug6054) + assert_raise_with_message(IOError, /not opened for reading/, bug6054) do + IO.foreach(t.path, mode:"w").next + end } end diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index dee36abaaf..45fa98e897 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -763,10 +763,12 @@ EOT assert_equal(eucjp, r.read) end) - e = assert_raise(ArgumentError) {with_pipe("UTF-8", "UTF-8".encode("UTF-32BE")) {}} - assert_match(/invalid name encoding/, e.message) - e = assert_raise(ArgumentError) {with_pipe("UTF-8".encode("UTF-32BE")) {}} - assert_match(/invalid name encoding/, e.message) + assert_raise_with_message(ArgumentError, /invalid name encoding/) do + with_pipe("UTF-8", "UTF-8".encode("UTF-32BE")) {} + end + assert_raise_with_message(ArgumentError, /invalid name encoding/) do + with_pipe("UTF-8".encode("UTF-32BE")) {} + end ENCS.each {|enc| pipe(enc, diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 621320c2b0..f8f186175f 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -49,8 +49,7 @@ class TestISeq < Test::Unit::TestCase def test_unsupport_type ary = RubyVM::InstructionSequence.compile("p").to_a ary[9] = :foobar - e = assert_raise(TypeError) {RubyVM::InstructionSequence.load(ary)} - assert_match(/:foobar/, e.message) + assert_raise_with_message(TypeError, /:foobar/) {RubyVM::InstructionSequence.load(ary)} end if defined?(RubyVM::InstructionSequence.load) def test_disasm_encoding diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index ddaf6777b4..9ad2f39fa9 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -248,10 +248,11 @@ class TestModule < Test::Unit::TestCase ":", ["String::", "[Bug #7573]"], ].each do |name, msg| - e = assert_raise(NameError, "#{msg}#{': ' if msg}wrong constant name #{name.dump}") { + expected = "wrong constant name %s" % name + msg = "#{msg}#{': ' if msg}wrong constant name #{name.dump}" + assert_raise_with_message(NameError, expected, msg) { Object.const_get name } - assert_equal("wrong constant name %s" % name, e.message) end end @@ -624,8 +625,9 @@ class TestModule < Test::Unit::TestCase bug5084 = '[ruby-dev:44200]' assert_raise(TypeError, bug5084) { c1.const_get(1) } bug7574 = '[ruby-dev:46749]' - e = assert_raise(NameError) { Object.const_get("String\0") } - assert_equal("wrong constant name \"String\\u0000\"", e.message, bug7574) + assert_raise_with_message(NameError, "wrong constant name \"String\\u0000\"", bug7574) { + Object.const_get("String\0") + } end def test_const_defined_invalid_name @@ -634,8 +636,9 @@ class TestModule < Test::Unit::TestCase bug5084 = '[ruby-dev:44200]' assert_raise(TypeError, bug5084) { c1.const_defined?(1) } bug7574 = '[ruby-dev:46749]' - e = assert_raise(NameError) { Object.const_defined?("String\0") } - assert_equal("wrong constant name \"String\\u0000\"", e.message, bug7574) + assert_raise_with_message(NameError, "wrong constant name \"String\\u0000\"", bug7574) { + Object.const_defined?("String\0") + } end def test_const_get_no_inherited @@ -1656,7 +1659,7 @@ class TestModule < Test::Unit::TestCase @@foo $foo ].each do |name| - assert_raise(NameError) do + assert_raise_with_message(NameError, /#{Regexp.quote(name)}/) do Module.new { attr_accessor name.to_sym } end end diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index d33884e036..55f3ef2b16 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -488,11 +488,10 @@ class TestObject < Test::Unit::TestCase end end - e = assert_raise(ArgumentError, '[bug:6000]') do + msg = 'respond_to? must accept 1 or 2 arguments (requires 3)' + assert_raise_with_message(ArgumentError, msg, '[bug:6000]') do [[p]].flatten end - - assert_equal('respond_to? must accept 1 or 2 arguments (requires 3)', e.message) end def test_method_missing_passed_block @@ -803,9 +802,7 @@ class TestObject < Test::Unit::TestCase def test_type_error_message issue = "Bug #7539" - err = assert_raise(TypeError){ Integer([42]) } - assert_equal "can't convert Array into Integer", err.message, issue - err = assert_raise(TypeError){ [].first([42]) } - assert_equal 'no implicit conversion of Array into Integer', err.message, issue + assert_raise_with_message(TypeError, "can't convert Array into Integer") {Integer([42])} + assert_raise_with_message(TypeError, 'no implicit conversion of Array into Integer') {[].first([42])} end end diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 1f2a4d13a8..b0efe38d8c 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -946,8 +946,9 @@ class TestRegexp < Test::Unit::TestCase def test_error_message_on_failed_conversion bug7539 = '[ruby-core:50733]' assert_equal false, /x/=== 42 - err = assert_raise(TypeError){ Regexp.quote(42) } - assert_equal 'no implicit conversion of Fixnum into String', err.message, bug7539 + assert_raise_with_message(TypeError, 'no implicit conversion of Fixnum into String', bug7539) { + Regexp.quote(42) + } end def test_conditional_expression diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 228a45c4eb..bca9604640 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -50,8 +50,7 @@ class TestRequire < Test::Unit::TestCase def test_require_nonascii bug3758 = '[ruby-core:31915]' ["\u{221e}", "\x82\xa0".force_encoding("cp932")].each do |path| - e = assert_raise(LoadError, bug3758) {require path} - assert_match(/#{path}\z/, e.message, bug3758) + assert_raise_with_message(LoadError, /#{path}\z/, bug3758) {require path} end end diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb index ba0ee6d9e4..c7bcc4a375 100644 --- a/test/ruby/test_signal.rb +++ b/test/ruby/test_signal.rb @@ -16,12 +16,10 @@ class TestSignal < Test::Unit::TestCase assert_equal 2, x Signal.trap(:INT) { raise "Interrupt" } - ex = assert_raise(RuntimeError) { + assert_raise_with_message(RuntimeError, /Interrupt/) { Process.kill :INT, Process.pid sleep 0.1 } - assert_kind_of Exception, ex - assert_match(/Interrupt/, ex.message) ensure Signal.trap :INT, oldtrap if oldtrap end diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb index 21329dcd66..aba71153ee 100644 --- a/test/ruby/test_sprintf.rb +++ b/test/ruby/test_sprintf.rb @@ -325,70 +325,52 @@ class TestSprintf < Test::Unit::TestCase def test_named_untyped assert_equal("value", sprintf("%<key>s", :key => "value")) - e = assert_raise(ArgumentError) {sprintf("%1$<key2>s", :key => "value")} - assert_equal("named<key2> after numbered", e.message) - e = assert_raise(ArgumentError) {sprintf("%s%s%<key2>s", "foo", "bar", :key => "value")} - assert_equal("named<key2> after unnumbered(2)", e.message) - e = assert_raise(ArgumentError) {sprintf("%<key><key2>s", :key => "value")} - assert_equal("named<key2> after <key>", e.message) - e = assert_raise(KeyError) {sprintf("%<key>s", {})} - assert_equal("key<key> not found", e.message) + assert_raise_with_message(ArgumentError, "named<key2> after numbered") {sprintf("%1$<key2>s", :key => "value")} + assert_raise_with_message(ArgumentError, "named<key2> after unnumbered(2)") {sprintf("%s%s%<key2>s", "foo", "bar", :key => "value")} + assert_raise_with_message(ArgumentError, "named<key2> after <key>") {sprintf("%<key><key2>s", :key => "value")} + assert_raise_with_message(KeyError, "key<key> not found") {sprintf("%<key>s", {})} end def test_named_untyped_enc key = "\u{3012}" [Encoding::UTF_8, Encoding::EUC_JP].each do |enc| k = key.encode(enc) - e = assert_raise(ArgumentError) {sprintf("%1$<#{k}>s", key: "value")} + e = assert_raise_with_message(ArgumentError, "named<#{k}> after numbered") {sprintf("%1$<#{k}>s", key: "value")} assert_equal(enc, e.message.encoding) - assert_equal("named<#{k}> after numbered", e.message) - e = assert_raise(ArgumentError) {sprintf("%s%s%<#{k}>s", "foo", "bar", key: "value")} + e = assert_raise_with_message(ArgumentError, "named<#{k}> after unnumbered(2)") {sprintf("%s%s%<#{k}>s", "foo", "bar", key: "value")} assert_equal(enc, e.message.encoding) - assert_equal("named<#{k}> after unnumbered(2)", e.message) - e = assert_raise(ArgumentError) {sprintf("%<key><#{k}>s", key: "value")} + e = assert_raise_with_message(ArgumentError, "named<#{k}> after <key>") {sprintf("%<key><#{k}>s", key: "value")} assert_equal(enc, e.message.encoding) - assert_equal("named<#{k}> after <key>", e.message) - e = assert_raise(ArgumentError) {sprintf("%<#{k}><key>s", k.to_sym => "value")} + e = assert_raise_with_message(ArgumentError, "named<key> after <#{k}>") {sprintf("%<#{k}><key>s", k.to_sym => "value")} assert_equal(enc, e.message.encoding) - assert_equal("named<key> after <#{k}>", e.message) - e = assert_raise(KeyError) {sprintf("%<#{k}>s", {})} + e = assert_raise_with_message(KeyError, "key<#{k}> not found") {sprintf("%<#{k}>s", {})} assert_equal(enc, e.message.encoding) - assert_equal("key<#{k}> not found", e.message) end end def test_named_typed assert_equal("value", sprintf("%{key}", :key => "value")) - e = assert_raise(ArgumentError) {sprintf("%1${key2}", :key => "value")} - assert_equal("named{key2} after numbered", e.message) - e = assert_raise(ArgumentError) {sprintf("%s%s%{key2}", "foo", "bar", :key => "value")} - assert_equal("named{key2} after unnumbered(2)", e.message) - e = assert_raise(ArgumentError) {sprintf("%<key>{key2}", :key => "value")} - assert_equal("named{key2} after <key>", e.message) + assert_raise_with_message(ArgumentError, "named{key2} after numbered") {sprintf("%1${key2}", :key => "value")} + assert_raise_with_message(ArgumentError, "named{key2} after unnumbered(2)") {sprintf("%s%s%{key2}", "foo", "bar", :key => "value")} + assert_raise_with_message(ArgumentError, "named{key2} after <key>") {sprintf("%<key>{key2}", :key => "value")} assert_equal("value{key2}", sprintf("%{key}{key2}", :key => "value")) - e = assert_raise(KeyError) {sprintf("%{key}", {})} - assert_equal("key{key} not found", e.message) + assert_raise_with_message(KeyError, "key{key} not found") {sprintf("%{key}", {})} end def test_named_typed_enc key = "\u{3012}" [Encoding::UTF_8, Encoding::EUC_JP].each do |enc| k = key.encode(enc) - e = assert_raise(ArgumentError) {sprintf("%1${#{k}}s", key: "value")} + e = assert_raise_with_message(ArgumentError, "named{#{k}} after numbered") {sprintf("%1${#{k}}s", key: "value")} assert_equal(enc, e.message.encoding) - assert_equal("named{#{k}} after numbered", e.message) - e = assert_raise(ArgumentError) {sprintf("%s%s%{#{k}}s", "foo", "bar", key: "value")} + e = assert_raise_with_message(ArgumentError, "named{#{k}} after unnumbered(2)") {sprintf("%s%s%{#{k}}s", "foo", "bar", key: "value")} assert_equal(enc, e.message.encoding) - assert_equal("named{#{k}} after unnumbered(2)", e.message) - e = assert_raise(ArgumentError) {sprintf("%<key>{#{k}}s", key: "value")} + e = assert_raise_with_message(ArgumentError, "named{#{k}} after <key>") {sprintf("%<key>{#{k}}s", key: "value")} assert_equal(enc, e.message.encoding) - assert_equal("named{#{k}} after <key>", e.message) - e = assert_raise(ArgumentError) {sprintf("%<#{k}>{key}s", k.to_sym => "value")} + e = assert_raise_with_message(ArgumentError, "named{key} after <#{k}>") {sprintf("%<#{k}>{key}s", k.to_sym => "value")} assert_equal(enc, e.message.encoding) - assert_equal("named{key} after <#{k}>", e.message) - e = assert_raise(KeyError) {sprintf("%{#{k}}", {})} + e = assert_raise_with_message(KeyError, "key{#{k}} not found") {sprintf("%{#{k}}", {})} assert_equal(enc, e.message.encoding) - assert_equal("key{#{k}} not found", e.message) end end end diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb index 244f820217..846f40946d 100644 --- a/test/ruby/test_super.rb +++ b/test/ruby/test_super.rb @@ -152,14 +152,13 @@ class TestSuper < Test::Unit::TestCase a = A.new a.uu(12) assert_equal("A#tt", a.tt(12), "[ruby-core:3856]") - e = assert_raise(RuntimeError, "[ruby-core:24244]") { + assert_raise_with_message(RuntimeError, /implicit argument passing of super from method defined by define_method/, "[ruby-core:24244]") { lambda { Class.new { define_method(:a) {super} }.new.a }.call } - assert_match(/implicit argument passing of super from method defined by define_method/, e.message) end class SubSeq |