diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-17 06:52:00 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-17 06:52:00 +0000 |
commit | bc6c037f8499bd630da8f05e8e63e65f5eef76eb (patch) | |
tree | 1455a48335b31b47f2fd32ef666fba740db7b667 /test | |
parent | 559b717567e61206294a310cdeedea9f28426e22 (diff) |
Merge commit r32996 from trunk:
* ext/bigdecimal/bigdecimal.c (cannot_be_coerced_into_BigDecimal):
add a new function for raising error when an object cannot coerce
into BigDecimal. [Bug #5172]
* ext/bigdecimal/bigdecimal.c (BigDecimalValueWithPrec): use
cannot_be_coerced_into_BigDecimal function.
* ext/bigdecimal/bigdecimal.c (BigMath_s_exp): ditto.
* ext/bigdecimal/bigdecimal.c (BigMath_s_log): ditto.
* test/bigdecimal/test_bigdecimal.rb: test for the avobe changes.
* test/bigdecimal/testbase.rb (under_gc_stress): add a new utility
method to run tests under the condition of GC.stress = true.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 45 | ||||
-rw-r--r-- | test/bigdecimal/testbase.rb | 7 |
2 files changed, 51 insertions, 1 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index e3ae631820..a9524bb2ae 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1086,7 +1086,7 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, BigDecimal.new("-1E-1" + "0" * 10000).sign) end - def test_gc + def test_split_under_gc_stress bug3258 = '[ruby-dev:41213]' stress, GC.stress = GC.stress, true 10.upto(20) do |i| @@ -1097,6 +1097,21 @@ class TestBigDecimal < Test::Unit::TestCase GC.stress = stress end + def test_coerce_under_gc_stress + expect = ":too_long_to_embed_as_string can't be coerced into BigDecimal" + under_gc_stress do + b = BigDecimal.new("1") + 10.times do + begin + b.coerce(:too_long_to_embed_as_string) + rescue => e + assert_instance_of TypeError, e + assert_equal expect, e.message + end + end + end + end + def test_INFINITY assert(BigDecimal::INFINITY.infinite?, "BigDecimal::INFINITY is not a infinity") end @@ -1157,6 +1172,20 @@ class TestBigDecimal < Test::Unit::TestCase assert_in_epsilon(Math.exp(-40), BigMath.exp(BigDecimal("-40"), n)) end + def test_BigMath_exp_under_gc_stress + expect = ":too_long_to_embed_as_string can't be coerced into BigDecimal" + under_gc_stress do + 10.times do + begin + BigMath.exp(:too_long_to_embed_as_string, 6) + rescue => e + assert_instance_of ArgumentError, e + assert_equal expect, e.message + end + end + end + end + def test_BigMath_log_with_nil assert_raise(ArgumentError) do BigMath.log(nil, 20) @@ -1241,4 +1270,18 @@ class TestBigDecimal < Test::Unit::TestCase assert_in_delta(Math.log(1e-42), BigMath.log(1e-42, 20)) assert_in_delta(Math.log(1e-42), BigMath.log(BigDecimal("1e-42"), 20)) end + + def test_BigMath_log_under_gc_stress + expect = ":too_long_to_embed_as_string can't be coerced into BigDecimal" + under_gc_stress do + 10.times do + begin + BigMath.log(:too_long_to_embed_as_string, 6) + rescue => e + assert_instance_of ArgumentError, e + assert_equal expect, e.message + end + end + end + end end diff --git a/test/bigdecimal/testbase.rb b/test/bigdecimal/testbase.rb index 275b1b2b5d..c014e61e92 100644 --- a/test/bigdecimal/testbase.rb +++ b/test/bigdecimal/testbase.rb @@ -17,4 +17,11 @@ module TestBigDecimalBase BigDecimal.mode(mode, !(@mode & mode).zero?) end end + + def under_gc_stress + stress, GC.stress = GC.stress, true + yield + ensure + GC.stress = stress + end end |