From 921b2d1cfb67bae2941642015fbe35f7e7b81698 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 29 Apr 2010 05:46:04 +0000 Subject: [PATCH] * lib/test/unit/assertions.rb (Test::Unit::Assertions#assert): use more descriptive assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- test/ruby/test_bignum.rb | 4 ++-- test/ruby/test_encoding.rb | 4 ++-- test/ruby/test_fixnum.rb | 14 +++++++------- test/ruby/test_float.rb | 4 ++-- test/ruby/test_io.rb | 2 +- test/ruby/test_pack.rb | 2 +- test/ruby/test_regexp.rb | 4 ++-- test/ruby/test_sprintf.rb | 3 ++- test/ruby/test_stringchar.rb | 4 ++-- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index a631f2432c..002165f6dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Thu Apr 29 14:33:39 2010 Nobuyoshi Nakada +Thu Apr 29 14:46:00 2010 Nobuyoshi Nakada + + * lib/test/unit/assertions.rb (Test::Unit::Assertions#assert): + use more descriptive assertions. * test/ruby: fixed nonsense assertions. diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 40c4f21c3f..5cff48c4d7 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -290,8 +290,8 @@ class TestBignum < Test::Unit::TestCase def test_pow assert_equal(1.0, T32 ** 0.0) assert_equal(1.0 / T32, T32 ** -1) - assert((T32 ** T32).infinite?) - assert((T32 ** (2**30-1)).infinite?) + assert_equal(1, (T32 ** T32).infinite?) + assert_equal(1, (T32 ** (2**30-1)).infinite?) ### rational changes the behavior of Bignum#** #assert_raise(TypeError) { T32**"foo" } diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb index 75bb84a80d..46b86ccabf 100644 --- a/test/ruby/test_encoding.rb +++ b/test/ruby/test_encoding.rb @@ -52,8 +52,8 @@ class TestEncoding < Test::Unit::TestCase end def test_replicate - assert(Encoding::UTF_8.replicate('UTF-8-ANOTHER')) - assert(Encoding::ISO_2022_JP.replicate('ISO-2022-JP-ANOTHER')) + assert_instance_of(Encoding, Encoding::UTF_8.replicate('UTF-8-ANOTHER')) + assert_instance_of(Encoding, Encoding::ISO_2022_JP.replicate('ISO-2022-JP-ANOTHER')) bug3127 = '[ruby-dev:40954]' assert_raise(TypeError, bug3127) {Encoding::UTF_8.replicate(0)} assert_raise(ArgumentError, bug3127) {Encoding::UTF_8.replicate("\0")} diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb index e55e324bd1..2aee65c211 100644 --- a/test/ruby/test_fixnum.rb +++ b/test/ruby/test_fixnum.rb @@ -103,15 +103,15 @@ class TestFixnum < Test::Unit::TestCase end def test_lshift - assert_equal(0x40000000, 0x20000000<<1) - assert_equal(-0x40000000, (-0x20000000)<<1) - assert_equal(-0x80000000, (-0x40000000)<<1) + assert_equal(0x40000000, 0x20000000 << 1) + assert_equal(-0x40000000, (-0x20000000) << 1) + assert_equal(-0x80000000, (-0x40000000) << 1) end def test_rshift - assert_equal(0x20000000, 0x40000000>>1) - assert_equal(-0x20000000, (-0x40000000)>>1) - assert_equal(-0x40000000, (-0x80000000)>>1) + assert_equal(0x20000000, 0x40000000 >> 1) + assert_equal(-0x20000000, (-0x40000000) >> 1) + assert_equal(-0x40000000, (-0x80000000) >> 1) end def test_abs @@ -187,7 +187,7 @@ class TestFixnum < Test::Unit::TestCase assert_equal(4, 2**((2**32).coerce(2).first)) assert_equal(2, 4**0.5) assert_equal(0, 0**0.5) - assert((0**-1.0).infinite?) + assert_equal(1, (0**-1.0).infinite?) ### rational changes the behavior of Fixnum#** #assert_raise(TypeError) { 1 ** nil } assert_raise(TypeError, NoMethodError) { 1 ** nil } diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index ebb4fb89ae..a0d72be03d 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -419,10 +419,10 @@ class TestFloat < Test::Unit::TestCase def test_Float assert_in_delta(0.125, Float("0.1_2_5"), 0.00001) assert_in_delta(0.125, "0.1_2_5__".to_f, 0.00001) - assert(Float(([1] * 10000).join).infinite?) + assert_equal(1, Float(([1] * 10000).join).infinite?) assert(!Float(([1] * 10000).join("_")).infinite?) # is it really OK? assert_raise(ArgumentError) { Float("1.0\x001") } - assert(Float("1e10_00").infinite?) + assert_equal(1, Float("1e10_00").infinite?) assert_raise(TypeError) { Float(nil) } o = Object.new def o.to_f; inf = Float::INFINITY; inf/inf; end diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 98b1d7b074..f705a3f2aa 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -814,7 +814,7 @@ class TestIO < Test::Unit::TestCase def test_inspect with_pipe do |r, w| - assert(r.inspect =~ /^#$/) + assert_match(/^#$/, r.inspect) assert_raise(SecurityError) do safe_4 { r.inspect } end diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb index 58154128e6..a4a6308299 100644 --- a/test/ruby/test_pack.rb +++ b/test/ruby/test_pack.rb @@ -567,7 +567,7 @@ class TestPack < Test::Unit::TestCase end def test_pack_p2 - assert([nil].pack("p") =~ /\A\0*\Z/) + assert_match(/\A\0*\Z/, [nil].pack("p")) end def test_pack_unpack_w diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 35f23685eb..00c2ddb5e9 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -637,8 +637,8 @@ class TestRegexp < Test::Unit::TestCase check(/\u3042\d/, ["\u30421", "\u30422"]) # CClassTable cache test - assert(/\u3042\d/.match("\u30421")) - assert(/\u3042\d/.match("\u30422")) + assert_match(/\u3042\d/, "\u30421") + assert_match(/\u3042\d/, "\u30422") end def test_char_class diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb index de75032355..05bccde066 100644 --- a/test/ruby/test_sprintf.rb +++ b/test/ruby/test_sprintf.rb @@ -278,7 +278,8 @@ class TestSprintf < Test::Unit::TestCase end def test_rb_sprintf - assert(T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.new.inspect =~ /^#$/) + assert_match(/^#$/, + T012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.new.inspect) end def test_negative_hex diff --git a/test/ruby/test_stringchar.rb b/test/ruby/test_stringchar.rb index 184e221211..b70f171c84 100644 --- a/test/ruby/test_stringchar.rb +++ b/test/ruby/test_stringchar.rb @@ -37,8 +37,8 @@ END $x.gsub!(/((.|\n)*?)B((.|\n)*?)D/m ,'\1\3') assert_equal("AC\nAC\n", $x) - assert("foobar" =~ /foo(?=(bar)|(baz))/) - assert("foobaz" =~ /foo(?=(bar)|(baz))/) + assert_match(/foo(?=(bar)|(baz))/, "foobar") + assert_match(/foo(?=(bar)|(baz))/, "foobaz") $foo = "abc" assert_equal("abc = abc", "#$foo = abc")