test: use RbConfig::Limits

* test/lib/envutil.rb: rbconfig/sizeof may not be available when
  cross-compiling.  use RbConfig::Limits instead of calculating
  limits of Fixnum with hard-coded CHAR_BIT.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-03-02 04:54:19 +00:00
parent 6e0967ec6d
commit 033c4a083d
7 changed files with 13 additions and 15 deletions

View File

@ -3,8 +3,8 @@ require 'test/unit'
require '-test-/integer' require '-test-/integer'
class TestInteger < Test::Unit::TestCase class TestInteger < Test::Unit::TestCase
FIXNUM_MIN = Integer::FIXNUM_MIN FIXNUM_MIN = RbConfig::Limits['FIXNUM_MIN']
FIXNUM_MAX = Integer::FIXNUM_MAX FIXNUM_MAX = RbConfig::Limits['FIXNUM_MAX']
def test_fixnum_range def test_fixnum_range
assert_bignum(FIXNUM_MIN-1) assert_bignum(FIXNUM_MIN-1)

View File

@ -3,15 +3,13 @@
require "open3" require "open3"
require "timeout" require "timeout"
require_relative "find_executable" require_relative "find_executable"
require "rbconfig/sizeof"
begin begin
require 'rbconfig' require 'rbconfig'
rescue LoadError rescue LoadError
end end
begin
class Integer require "rbconfig/sizeof"
FIXNUM_MIN = -(1 << (8 * RbConfig::SIZEOF['long'] - 2)) rescue LoadError
FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF['long'] - 2)) - 1
end end
module EnvUtil module EnvUtil

View File

@ -2759,8 +2759,8 @@ class TestArray < Test::Unit::TestCase
assert_raise(TypeError) {h.dig(1, 0)} assert_raise(TypeError) {h.dig(1, 0)}
end end
FIXNUM_MIN = -(1 << (8 * RbConfig::SIZEOF['long'] - 2)) FIXNUM_MIN = RbConfig::Limits['FIXNUM_MIN']
FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF['long'] - 2)) - 1 FIXNUM_MAX = RbConfig::Limits['FIXNUM_MAX']
def assert_typed_equal(e, v, cls, msg=nil) def assert_typed_equal(e, v, cls, msg=nil)
assert_kind_of(cls, v, msg) assert_kind_of(cls, v, msg)

View File

@ -6,8 +6,8 @@ rescue LoadError
else else
class TestBignum < Test::Unit::TestCase class TestBignum < Test::Unit::TestCase
FIXNUM_MIN = Integer::FIXNUM_MIN FIXNUM_MIN = RbConfig::Limits['FIXNUM_MIN']
FIXNUM_MAX = Integer::FIXNUM_MAX FIXNUM_MAX = RbConfig::Limits['FIXNUM_MAX']
BIGNUM_MIN = FIXNUM_MAX + 1 BIGNUM_MIN = FIXNUM_MAX + 1
b = BIGNUM_MIN b = BIGNUM_MIN

View File

@ -184,8 +184,8 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal(nil, @empty.inject() {9}) assert_equal(nil, @empty.inject() {9})
end end
FIXNUM_MIN = Integer::FIXNUM_MIN FIXNUM_MIN = RbConfig::Limits['FIXNUM_MIN']
FIXNUM_MAX = Integer::FIXNUM_MAX FIXNUM_MAX = RbConfig::Limits['FIXNUM_MAX']
def test_inject_array_mul def test_inject_array_mul
assert_equal(nil, [].inject(:*)) assert_equal(nil, [].inject(:*))

View File

@ -622,7 +622,7 @@ class TestMarshal < Test::Unit::TestCase
def test_untainted_numeric def test_untainted_numeric
bug8945 = '[ruby-core:57346] [Bug #8945] Numerics never be tainted' bug8945 = '[ruby-core:57346] [Bug #8945] Numerics never be tainted'
b = Integer::FIXNUM_MAX + 1 b = RbConfig::Limits['FIXNUM_MAX'] + 1
tainted = [0, 1.0, 1.72723e-77, b].select do |x| tainted = [0, 1.0, 1.72723e-77, b].select do |x|
Marshal.load(Marshal.dump(x).taint).tainted? Marshal.load(Marshal.dump(x).taint).tainted?
end end

View File

@ -258,7 +258,7 @@ class TestNumeric < Test::Unit::TestCase
end end
def test_step def test_step
bignum = Integer::FIXNUM_MAX + 1 bignum = RbConfig::Limits['FIXNUM_MAX'] + 1
assert_raise(ArgumentError) { 1.step(10, 1, 0) { } } assert_raise(ArgumentError) { 1.step(10, 1, 0) { } }
assert_raise(ArgumentError) { 1.step(10, 1, 0).size } assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
assert_raise(ArgumentError) { 1.step(10, 0) { } } assert_raise(ArgumentError) { 1.step(10, 0) { } }