ruby-changes:40303
From: nobu <ko1@a...>
Date: Fri, 30 Oct 2015 13:37:31 +0900 (JST)
Subject: [ruby-changes:40303] nobu:r52384 (trunk): use assert_raise
nobu 2015-10-30 13:37:13 +0900 (Fri, 30 Oct 2015) New Revision: 52384 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52384 Log: use assert_raise Modified files: trunk/test/fiddle/test_closure.rb trunk/test/fiddle/test_cparser.rb trunk/test/fiddle/test_func.rb trunk/test/fiddle/test_function.rb trunk/test/fiddle/test_handle.rb trunk/test/fiddle/test_import.rb trunk/test/fiddle/test_pointer.rb trunk/test/json/test_json.rb trunk/test/json/test_json_addition.rb trunk/test/json/test_json_encoding.rb trunk/test/json/test_json_fixtures.rb trunk/test/json/test_json_generate.rb trunk/test/lib/test/unit/assertions.rb trunk/test/ruby/test_hash.rb Index: test/ruby/test_hash.rb =================================================================== --- test/ruby/test_hash.rb (revision 52383) +++ test/ruby/test_hash.rb (revision 52384) @@ -506,7 +506,7 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L506 assert_equal(4, res.length) assert_equal %w( three two one nil ), res - assert_raises KeyError do + assert_raise KeyError do @h.fetch_values(3, 'invalid') end Index: test/json/test_json_encoding.rb =================================================================== --- test/json/test_json_encoding.rb (revision 52383) +++ test/json/test_json_encoding.rb (revision 52384) @@ -59,7 +59,7 @@ class TestJSONEncoding < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/json/test_json_encoding.rb#L59 assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true) else # XXX checking of correct utf8 data is not as strict (yet?) without :ascii_only - assert_raises(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) } + assert_raise(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) } end end end Index: test/json/test_json_fixtures.rb =================================================================== --- test/json/test_json_fixtures.rb (revision 52383) +++ test/json/test_json_fixtures.rb (revision 52384) @@ -26,7 +26,7 @@ class TestJSONFixtures < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/json/test_json_fixtures.rb#L26 def test_failing for name, source in @failed - assert_raises(JSON::ParserError, JSON::NestingError, + assert_raise(JSON::ParserError, JSON::NestingError, "Did not fail for fixture '#{name}': #{source.inspect}") do JSON.parse(source) end Index: test/json/test_json_generate.rb =================================================================== --- test/json/test_json_generate.rb (revision 52383) +++ test/json/test_json_generate.rb (revision 52384) @@ -123,12 +123,12 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json_generate.rb#L123 assert s[:check_circular?] h = { 1=>2 } h[3] = h - assert_raises(JSON::NestingError) { generate(h) } - assert_raises(JSON::NestingError) { generate(h, s) } + assert_raise(JSON::NestingError) { generate(h) } + assert_raise(JSON::NestingError) { generate(h, s) } s = JSON.state.new a = [ 1, 2 ] a << a - assert_raises(JSON::NestingError) { generate(a, s) } + assert_raise(JSON::NestingError) { generate(a, s) } assert s.check_circular? assert s[:check_circular?] end @@ -185,34 +185,34 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json_generate.rb#L185 end def test_allow_nan - assert_raises(GeneratorError) { generate([JSON::NaN]) } + assert_raise(GeneratorError) { generate([JSON::NaN]) } assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true) - assert_raises(GeneratorError) { fast_generate([JSON::NaN]) } - assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) } + assert_raise(GeneratorError) { fast_generate([JSON::NaN]) } + assert_raise(GeneratorError) { pretty_generate([JSON::NaN]) } assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true) - assert_raises(GeneratorError) { generate([JSON::Infinity]) } + assert_raise(GeneratorError) { generate([JSON::Infinity]) } assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true) - assert_raises(GeneratorError) { fast_generate([JSON::Infinity]) } - assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) } + assert_raise(GeneratorError) { fast_generate([JSON::Infinity]) } + assert_raise(GeneratorError) { pretty_generate([JSON::Infinity]) } assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true) - assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) } + assert_raise(GeneratorError) { generate([JSON::MinusInfinity]) } assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true) - assert_raises(GeneratorError) { fast_generate([JSON::MinusInfinity]) } - assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) } + assert_raise(GeneratorError) { fast_generate([JSON::MinusInfinity]) } + assert_raise(GeneratorError) { pretty_generate([JSON::MinusInfinity]) } assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true) end def test_depth ary = []; ary << ary assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth - assert_raises(JSON::NestingError) { JSON.generate(ary) } + assert_raise(JSON::NestingError) { JSON.generate(ary) } assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth - assert_raises(JSON::NestingError) { JSON.pretty_generate(ary) } + assert_raise(JSON::NestingError) { JSON.pretty_generate(ary) } assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth s = JSON.state.new assert_equal 0, s.depth - assert_raises(JSON::NestingError) { ary.to_json(s) } + assert_raise(JSON::NestingError) { ary.to_json(s) } assert_equal 100, s.depth end Index: test/json/test_json_addition.rb =================================================================== --- test/json/test_json_addition.rb (revision 52383) +++ test/json/test_json_addition.rb (revision 52384) @@ -112,7 +112,7 @@ class TestJSONAddition < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/json/test_json_addition.rb#L112 c = C.new assert !C.json_creatable? json = generate(c) - assert_raises(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) } + assert_raise(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) } end def test_raw_strings @@ -151,7 +151,7 @@ class TestJSONAddition < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/json/test_json_addition.rb#L151 assert_equal s, JSON(JSON(s), :create_additions => true) struct = Struct.new :foo, :bar s = struct.new 4711, 'foot' - assert_raises(JSONError) { JSON(s) } + assert_raise(JSONError) { JSON(s) } begin raise TypeError, "test me" rescue TypeError => e Index: test/json/test_json.rb =================================================================== --- test/json/test_json.rb (revision 52383) +++ test/json/test_json.rb (revision 52384) @@ -65,10 +65,10 @@ class TestJSON < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L65 assert_equal([23], parse('[23]')) assert_equal([0.23], parse('[0.23]')) assert_equal([0.0], parse('[0e0]')) - assert_raises(JSON::ParserError) { parse('[+23.2]') } - assert_raises(JSON::ParserError) { parse('[+23]') } - assert_raises(JSON::ParserError) { parse('[.23]') } - assert_raises(JSON::ParserError) { parse('[023]') } + assert_raise(JSON::ParserError) { parse('[+23.2]') } + assert_raise(JSON::ParserError) { parse('[+23]') } + assert_raise(JSON::ParserError) { parse('[.23]') } + assert_raise(JSON::ParserError) { parse('[023]') } assert_equal_float [3.141], parse('[3.141]') assert_equal_float [-3.141], parse('[-3.141]') assert_equal_float [3.141], parse('[3141e-3]') @@ -77,11 +77,11 @@ class TestJSON < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L77 assert_equal_float [3.141], parse('[3141.0E-3]') assert_equal_float [-3.141], parse('[-3141.0e-3]') assert_equal_float [-3.141], parse('[-3141e-3]') - assert_raises(ParserError) { parse('[NaN]') } + assert_raise(ParserError) { parse('[NaN]') } assert parse('[NaN]', :allow_nan => true).first.nan? - assert_raises(ParserError) { parse('[Infinity]') } + assert_raise(ParserError) { parse('[Infinity]') } assert_equal [1.0/0], parse('[Infinity]', :allow_nan => true) - assert_raises(ParserError) { parse('[-Infinity]') } + assert_raise(ParserError) { parse('[-Infinity]') } assert_equal [-1.0/0], parse('[-Infinity]', :allow_nan => true) assert_equal([""], parse('[""]')) assert_equal(["foobar"], parse('["foobar"]')) @@ -95,7 +95,7 @@ class TestJSON < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L95 assert_equal({ "a" => nil }, parse('{"a":null}')) assert_equal({ "a" => false }, parse('{ "a" : false } ')) assert_equal({ "a" => false }, parse('{"a":false}')) - assert_raises(JSON::ParserError) { parse('{false}') } + assert_raise(JSON::ParserError) { parse('{false}') } assert_equal({ "a" => true }, parse('{"a":true}')) assert_equal({ "a" => true }, parse(' { "a" : true } ')) assert_equal({ "a" => -23 }, parse(' { "a" : -23 } ')) @@ -380,7 +380,7 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L380 * comment */ } EOT - assert_raises(ParserError) { parse(json) } + assert_raise(ParserError) { parse(json) } json = <<EOT { "key1":"value1" /* multi line @@ -389,7 +389,7 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L389 and again, throw an Error */ } EOT - assert_raises(ParserError) { parse(json) } + assert_raise(ParserError) { parse(json) } json = <<EOT { "key1":"value1" /*/*/ @@ -425,32 +425,32 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L425 end def test_wrong_inputs - assert_raises(ParserError) { JSON.parse('"foo"') } - assert_raises(ParserError) { JSON.parse('123') } - assert_raises(ParserError) { JSON.parse('[] bla') } - assert_raises(ParserError) { JSON.parse('[] 1') } - assert_raises(ParserError) { JSON.parse('[] []') } - assert_raises(ParserError) { JSON.parse('[] {}') } - assert_raises(ParserError) { JSON.parse('{} []') } - assert_raises(ParserError) { JSON.parse('{} {}') } - assert_raises(ParserError) { JSON.parse('[NULL]') } - assert_raises(ParserError) { JSON.parse('[FALSE]') } - assert_raises(ParserError) { JSON.parse('[TRUE]') } - assert_raises(ParserError) { JSON.parse('[07] ') } - assert_raises(ParserError) { JSON.parse('[0a]') } - assert_raises(ParserError) { JSON.parse('[1.]') } - assert_raises(ParserError) { JSON.parse(' ') } + assert_raise(ParserError) { JSON.parse('"foo"') } + assert_raise(ParserError) { JSON.parse('123') } + assert_raise(ParserError) { JSON.parse('[] bla') } + assert_raise(ParserError) { JSON.parse('[] 1') } + assert_raise(ParserError) { JSON.parse('[] []') } + assert_raise(ParserError) { JSON.parse('[] {}') } + assert_raise(ParserError) { JSON.parse('{} []') } + assert_raise(ParserError) { JSON.parse('{} {}') } + assert_raise(ParserError) { JSON.parse('[NULL]') } + assert_raise(ParserError) { JSON.parse('[FALSE]') } + assert_raise(ParserError) { JSON.parse('[TRUE]') } + assert_raise(ParserError) { JSON.parse('[07] ') } + assert_raise(ParserError) { JSON.parse('[0a]') } + assert_raise(ParserError) { JSON.parse('[1.]') } + assert_raise(ParserError) { JSON.parse(' ') } end def test_nesting - assert_raises(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 } - assert_raises(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse } + assert_raise(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 } + assert_raise(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse } assert_equal [[]], JSON.parse('[[]]', :max_nesting => 2) too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]' too_deep_ary = eval too_deep - assert_raises(JSON::NestingError) { JSON.parse too_deep } - assert_raises(JSON::NestingError) { JSON.parser.new(too_deep).parse } - assert_raises(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 100 } + assert_raise(JSON::NestingError) { JSON.parse too_deep } + assert_raise(JSON::NestingError) { JSON.parser.new(too_deep).parse } + assert_raise(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 100 } ok = JSON.parse too_deep, :max_nesting => 101 assert_equal too_deep_ary, ok ok = JSON.parse too_deep, :max_nesting => nil @@ -459,10 +459,10 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L459 assert_equal too_deep_ary, ok ok = JSON.parse too_deep, :max_nesting => 0 assert_equal too_deep_ary, ok - assert_raises(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 } + assert_raise(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 } assert_equal '[[]]', JSON.generate([[]], :max_nesting => 2) - assert_raises(JSON::NestingError) { JSON.generate too_deep_ary } - assert_raises(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 } + assert_raise(JSON::NestingError) { JSON.generate too_deep_ary } + assert_raise(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 } ok = JSON.generate too_deep_ary, :max_nesting => 101 assert_equal too_deep, ok ok = JSON.generate too_deep_ary, :max_nesting => nil @@ -505,8 +505,8 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/json/test_json.rb#L505 too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]' assert_equal too_deep, JSON.dump(eval(too_deep)) assert_kind_of String, Marshal.dump(eval(too_deep)) - assert_raises(ArgumentError) { JSON.dump(eval(too_deep), 100) } - assert_raises(ArgumentError) { Marshal.dump(eval(too_deep), 100) } + assert_raise(ArgumentError) { JSON.dump(eval(too_deep), 100) } + assert_raise(ArgumentError) { Marshal.dump(eval(too_deep), 100) } assert_equal too_deep, JSON.dump(eval(too_deep), 101) assert_kind_of String, Marshal.dump(eval(too_deep), 101) output = StringIO.new Index: test/fiddle/test_cparser.rb =================================================================== --- test/fiddle/test_cparser.rb (revision 52383) +++ test/fiddle/test_cparser.rb (revision 52384) @@ -60,7 +60,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_cparser.rb#L60 end def test_undefined_ctype - assert_raises(DLError) { parse_ctype('DWORD') } + assert_raise(DLError) { parse_ctype('DWORD') } end def test_undefined_ctype_with_type_alias @@ -92,7 +92,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_cparser.rb#L92 end def test_struct_undefined - assert_raises(DLError) { parse_struct_signature(['int i', 'DWORD cb']) } + assert_raise(DLError) { parse_struct_signature(['int i', 'DWORD cb']) } end def test_struct_undefined_with_type_alias Index: test/fiddle/test_pointer.rb =================================================================== --- test/fiddle/test_pointer.rb (revision 52383) +++ test/fiddle/test_pointer.rb (revision 52384) @@ -105,7 +105,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_pointer.rb#L105 ptr2 = Pointer.to_ptr Struct.new(:to_ptr).new(ptr) assert_equal ptr, ptr2 - assert_raises(Fiddle::DLError) do + assert_raise(Fiddle::DLError) do Pointer.to_ptr Struct.new(:to_ptr).new(nil) end end Index: test/fiddle/test_function.rb =================================================================== --- test/fiddle/test_function.rb (revision 52383) +++ test/fiddle/test_function.rb (revision 52384) @@ -23,15 +23,15 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_function.rb#L23 end def test_argument_errors - assert_raises(TypeError) do + assert_raise(TypeError) do Function.new(@libm['sin'], TYPE_DOUBLE, TYPE_DOUBLE) end - assert_raises(TypeError) do + assert_raise(TypeError) do Function.new(@libm['sin'], ['foo'], TYPE_DOUBLE) end - assert_raises(TypeError) do + assert_raise(TypeError) do Function.new(@libm['sin'], [TYPE_DOUBLE], 'foo') end end @@ -49,10 +49,10 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_function.rb#L49 }.new(TYPE_INT, [TYPE_INT]) func = Function.new(closure, [TYPE_INT], TYPE_INT) - assert_raises(ArgumentError) do + assert_raise(ArgumentError) do func.call(1,2,3) end - assert_raises(ArgumentError) do + assert_raise(ArgumentError) do func.call end end Index: test/fiddle/test_import.rb =================================================================== --- test/fiddle/test_import.rb (revision 52383) +++ test/fiddle/test_import.rb (revision 52384) @@ -44,7 +44,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_import.rb#L44 class TestImport < TestCase def test_ensure_call_dlload - err = assert_raises(RuntimeError) do + err = assert_raise(RuntimeError) do Class.new do extend Importer extern "void *strcpy(char*, char*)" Index: test/fiddle/test_func.rb =================================================================== --- test/fiddle/test_func.rb (revision 52383) +++ test/fiddle/test_func.rb (revision 52384) @@ -12,7 +12,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_func.rb#L12 def test_syscall_with_tainted_string f = Function.new(@libc['system'], [TYPE_VOIDP], TYPE_INT) - assert_raises(SecurityError) do + assert_raise(SecurityError) do Thread.new { $SAFE = 1 f.call("uname -rs".taint) Index: test/fiddle/test_handle.rb =================================================================== --- test/fiddle/test_handle.rb (revision 52383) +++ test/fiddle/test_handle.rb (revision 52384) @@ -15,8 +15,8 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_handle.rb#L15 end def test_static_sym_unknown - assert_raises(DLError) { Fiddle::Handle.sym('fooo') } - assert_raises(DLError) { Fiddle::Handle['fooo'] } + assert_raise(DLError) { Fiddle::Handle.sym('fooo') } + assert_raise(DLError) { Fiddle::Handle['fooo'] } end def test_static_sym @@ -41,20 +41,20 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_handle.rb#L41 def test_sym_closed_handle handle = Fiddle::Handle.new(LIBC_SO) handle.close - assert_raises(DLError) { handle.sym("calloc") } - assert_raises(DLError) { handle["calloc"] } + assert_raise(DLError) { handle.sym("calloc") } + assert_raise(DLError) { handle["calloc"] } end def test_sym_unknown handle = Fiddle::Handle.new(LIBC_SO) - assert_raises(DLError) { handle.sym('fooo') } - assert_raises(DLError) { handle['fooo'] } + assert_raise(DLError) { handle.sym('fooo') } + assert_raise(DLError) { handle['fooo'] } end def test_sym_with_bad_args handle = Handle.new(LIBC_SO) - assert_raises(TypeError) { handle.sym(nil) } - assert_raises(TypeError) { handle[nil] } + assert_raise(TypeError) { handle.sym(nil) } + assert_raise(TypeError) { handle[nil] } end def test_sym @@ -71,7 +71,7 @@ module Fiddle https://github.com/ruby/ruby/blob/trunk/test/fiddle/test_handle.rb#L71 def test_handle_close_twice handle = Handle.new(LIBC_SO) handle.close - assert_raises(DLError) do + assert_raise(DLError) do (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/