Skip to content

Commit

Permalink
Update tests from MRI trunk (2.4).
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 14, 2016
1 parent 8aa6f68 commit c752675
Show file tree
Hide file tree
Showing 456 changed files with 12,965 additions and 3,574 deletions.
4 changes: 2 additions & 2 deletions test/mri/-ext-/bignum/test_big2str.rb
Expand Up @@ -5,8 +5,8 @@
class TestBignum < Test::Unit::TestCase
class TestBig2str < Test::Unit::TestCase

SIZEOF_BDIGIT = Bignum::SIZEOF_BDIGIT
BITSPERDIG = Bignum::BITSPERDIG
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
BITSPERDIG = Integer::BITSPERDIG
BDIGMAX = (1 << BITSPERDIG) - 1

def test_big2str_generic
Expand Down
6 changes: 6 additions & 0 deletions test/mri/-ext-/bignum/test_bigzero.rb
Expand Up @@ -10,5 +10,11 @@ def test_equal_0
assert_equal(0, Bug::Bignum.zero(i), "#{bug8204} Bignum.zero(#{i})")
end
end

def test_zero?
(0..10).each do |i|
assert_equal(true, Bug::Bignum.zero(i).zero?)
end
end
end
end
4 changes: 2 additions & 2 deletions test/mri/-ext-/bignum/test_div.rb
Expand Up @@ -5,8 +5,8 @@
class TestBignum < Test::Unit::TestCase
class TestDiv < Test::Unit::TestCase

SIZEOF_BDIGIT = Bignum::SIZEOF_BDIGIT
BITSPERDIG = Bignum::BITSPERDIG
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
BITSPERDIG = Integer::BITSPERDIG
BDIGMAX = (1 << BITSPERDIG) - 1

def test_divrem_normal
Expand Down
12 changes: 6 additions & 6 deletions test/mri/-ext-/bignum/test_mul.rb
Expand Up @@ -5,8 +5,8 @@
class TestBignum < Test::Unit::TestCase
class TestMul < Test::Unit::TestCase

SIZEOF_BDIGIT = Bignum::SIZEOF_BDIGIT
BITSPERDIG = Bignum::BITSPERDIG
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
BITSPERDIG = Integer::BITSPERDIG
BDIGMAX = (1 << BITSPERDIG) - 1

def test_mul_normal
Expand Down Expand Up @@ -61,14 +61,14 @@ def test_mul_balance
end

def test_mul_balance_2x16
x = (1 << Bignum::BITSPERDIG) | 1
y = (1 << Bignum::BITSPERDIG*16) | 1
x = (1 << Integer::BITSPERDIG) | 1
y = (1 << Integer::BITSPERDIG*16) | 1
assert_equal(x.big_mul_normal(y), x.big_mul_balance(y))
end

def test_mul_balance_2x17
x = (1 << Bignum::BITSPERDIG) | 1
y = (1 << Bignum::BITSPERDIG*17) | 1
x = (1 << Integer::BITSPERDIG) | 1
y = (1 << Integer::BITSPERDIG*17) | 1
assert_equal(x.big_mul_normal(y), x.big_mul_balance(y))
end

Expand Down
4 changes: 2 additions & 2 deletions test/mri/-ext-/bignum/test_str2big.rb
Expand Up @@ -5,8 +5,8 @@
class TestBignum < Test::Unit::TestCase
class TestStr2big < Test::Unit::TestCase

SIZEOF_BDIGIT = Bignum::SIZEOF_BDIGIT
BITSPERDIG = Bignum::BITSPERDIG
SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
BITSPERDIG = Integer::BITSPERDIG
BDIGMAX = (1 << BITSPERDIG) - 1

def test_str2big_poweroftwo
Expand Down
2 changes: 1 addition & 1 deletion test/mri/-ext-/bug_reporter/test_bug_reporter.rb
Expand Up @@ -14,7 +14,7 @@ def test_bug_reporter_add
]
tmpdir = Dir.mktmpdir

args = ["--disable-gems", "-r-test-/bug_reporter/bug_reporter",
args = ["--disable-gems", "-r-test-/bug_reporter",
"-C", tmpdir]
stdin = "register_sample_bug_reporter(12345); Process.kill :SEGV, $$"
assert_in_out_err(args, stdin, [], expected_stderr, encoding: "ASCII-8BIT")
Expand Down
2 changes: 1 addition & 1 deletion test/mri/-ext-/funcall/test_passing_block.rb
Expand Up @@ -7,7 +7,7 @@ def self.target(*args, &block)
yield(*args) if block
end
end
require '-test-/funcall/funcall'
require '-test-/funcall'

def test_with_funcall2
ok = nil
Expand Down
15 changes: 15 additions & 0 deletions test/mri/-ext-/integer/test_integer.rb
@@ -0,0 +1,15 @@
# frozen_string_literal: false
require 'test/unit'
require '-test-/integer'

class TestInteger < Test::Unit::TestCase
FIXNUM_MIN = Integer::FIXNUM_MIN
FIXNUM_MAX = Integer::FIXNUM_MAX

def test_fixnum_range
assert_bignum(FIXNUM_MIN-1)
assert_fixnum(FIXNUM_MIN)
assert_fixnum(FIXNUM_MAX)
assert_bignum(FIXNUM_MAX+1)
end
end
48 changes: 48 additions & 0 deletions test/mri/-ext-/integer/test_my_integer.rb
@@ -0,0 +1,48 @@
# frozen_string_literal: false
require 'test/unit'
require "-test-/integer"

class TestIntegerExt < Test::Unit::TestCase
def test_my_integer_to_f
assert_raise(NotImplementedError) do
Bug::Integer::MyInteger.new.to_f
end

begin
Bug::Integer::MyInteger.class_eval do
def to_f
end
end

assert_nothing_raised do
Bug::Integer::MyInteger.new.to_f
end
ensure
Bug::Integer::MyInteger.class_eval do
remove_method :to_f
end
end
end

def test_my_integer_cmp
assert_raise(NotImplementedError) do
Bug::Integer::MyInteger.new <=> 0
end

begin
Bug::Integer::MyInteger.class_eval do
def <=>(other)
0
end
end

assert_nothing_raised do
Bug::Integer::MyInteger.new <=> 0
end
ensure
Bug::Integer::MyInteger.class_eval do
remove_method :<=>
end
end
end
end
2 changes: 1 addition & 1 deletion test/mri/-ext-/iseq_load/test_iseq_load.rb
Expand Up @@ -2,7 +2,7 @@
require 'test/unit'

class TestIseqLoad < Test::Unit::TestCase
require '-test-/iseq_load/iseq_load'
require '-test-/iseq_load'
ISeq = RubyVM::InstructionSequence

def test_bug8543
Expand Down
2 changes: 1 addition & 1 deletion test/mri/-ext-/load/test_dot_dot.rb
Expand Up @@ -5,7 +5,7 @@ class Test_DotDot < Test::Unit::TestCase
def test_load_dot_dot
feature = '[ruby-dev:41774]'
assert_nothing_raised(LoadError, feature) {
require '-test-/load/dot.dot/dot.dot'
require '-test-/load/dot.dot'
}
end
end
2 changes: 1 addition & 1 deletion test/mri/-ext-/method/test_arity.rb
Expand Up @@ -17,7 +17,7 @@ def foo2(a,b)
end
end

class B<A
class B < A
private :foo1, :foo2
end

Expand Down
7 changes: 4 additions & 3 deletions test/mri/-ext-/num2int/test_num2int.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: false
require 'test/unit'
require '-test-/num2int/num2int'
require '-test-/num2int'
require '-test-/integer'

class TestNum2int < Test::Unit::TestCase
SHRT_MIN = -32768
Expand Down Expand Up @@ -104,7 +105,7 @@ def assert_fix2i_success_internal(exp, func, arg)
end

def assert_fix2i_success(type, num, result=num)
return if !num.kind_of?(Fixnum)
return if !num.fixnum?
func = "FIX2#{type}".upcase
assert_fix2i_success_internal(result.to_s, func, num)
end
Expand All @@ -116,7 +117,7 @@ def assert_fix2i_error_internal(func, arg)
end

def assert_fix2i_error(type, num)
return if !num.kind_of?(Fixnum)
return if !num.fixnum?
func = "FIX2#{type}".upcase
assert_num2i_error_internal(func, num)
end
Expand Down
2 changes: 1 addition & 1 deletion test/mri/-ext-/path_to_class/test_path_to_class.rb
Expand Up @@ -2,7 +2,7 @@
require 'test/unit'

class Test_PathToClass < Test::Unit::TestCase
require '-test-/path_to_class/path_to_class'
require '-test-/path_to_class'

def test_path_to_class
bug5691 = '[ruby-core:41410]'
Expand Down
32 changes: 32 additions & 0 deletions test/mri/-ext-/string/test_capacity.rb
@@ -0,0 +1,32 @@
# frozen_string_literal: true
require 'test/unit'
require '-test-/string'
require 'rbconfig/sizeof'

class Test_StringCapacity < Test::Unit::TestCase
def capa(str)
Bug::String.capacity(str)
end

def test_capacity_embeded
size = RbConfig::SIZEOF['void*'] * 3 - 1
assert_equal size, capa('foo')
end

def test_capacity_shared
assert_equal 0, capa(:abcdefghijklmnopqrstuvwxyz.to_s)
end

def test_capacity_normal
assert_equal 128, capa('1'*128)
end

def test_s_new_capacity
assert_equal("", String.new(capacity: 1000))
assert_equal(String, String.new(capacity: 1000).class)
assert_equal(10000, capa(String.new(capacity: 10000)))

assert_equal("", String.new(capacity: -1000))
assert_equal(capa(String.new(capacity: -10000)), capa(String.new(capacity: -1000)))
end
end
6 changes: 6 additions & 0 deletions test/mri/-ext-/string/test_cstr.rb
Expand Up @@ -18,6 +18,12 @@ def test_long
assert_equal(0, s.cstr_term, Bug4319)
end

def test_shared
s = Bug::String.new("abcdef")*5
s = s.unterminated_substring(0, 29)
assert_equal(0, s.cstr_term, Bug4319)
end

def test_frozen
s0 = Bug::String.new("abcdefgh"*8)

Expand Down
9 changes: 9 additions & 0 deletions test/mri/-ext-/string/test_fstring.rb
@@ -1,8 +1,11 @@
# frozen_string_literal: false
require 'test/unit'
require '-test-/string'
require_relative '../symbol/noninterned_name'

class Test_String_Fstring < Test::Unit::TestCase
include Test_Symbol::NonInterned

def assert_fstring(str)
fstr = Bug::String.fstring(str)
yield str
Expand Down Expand Up @@ -54,6 +57,12 @@ def str.foo
assert_fstring(str) {|s| assert_send([s, :respond_to?, :foo])}
end

def test_singleton_class
str = noninterned_name.force_encoding("us-ascii")
fstr = Bug::String.fstring(str)
assert_raise(TypeError) {fstr.singleton_class}
end

class S < String
end

Expand Down
10 changes: 10 additions & 0 deletions test/mri/-ext-/string/test_modify_expand.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: false
require 'test/unit'
require "-test-/string"
require "rbconfig/sizeof"

class Test_StringModifyExpand < Test::Unit::TestCase
def test_modify_expand_memory_leak
Expand All @@ -13,4 +14,13 @@ def test_modify_expand_memory_leak
s.replace("")
CMD
end

def test_integer_overflow
bug12390 = '[ruby-core:75592] [Bug #12390]'
s = Bug::String.new
long_max = (1 << (8 * RbConfig::SIZEOF['long'] - 1)) - 1
assert_raise(ArgumentError, bug12390) {
s.modify_expand!(long_max)
}
end
end
9 changes: 9 additions & 0 deletions test/mri/-ext-/string/test_set_len.rb
Expand Up @@ -23,4 +23,13 @@ def test_shared
assert_equal("abc", @s1.set_len(3))
}
end

def test_capacity_equals_to_new_size
bug12757 = "[ruby-core:77257] [Bug #12757]"
# fill to ensure capacity does not decrease with force_encoding
str = Bug::String.new("\x00" * 128, capacity: 128)
str.force_encoding("UTF-32BE")
assert_equal 128, Bug::String.capacity(str)
assert_equal 127, str.set_len(127).bytesize, bug12757
end
end
4 changes: 1 addition & 3 deletions test/mri/-ext-/struct/test_member.rb
Expand Up @@ -9,8 +9,6 @@ def test_member_get
s = S.new(1)
assert_equal(1, s.get(:a))
assert_raise_with_message(NameError, /is not a struct member/) {s.get(:b)}
EnvUtil.with_default_external(Encoding::UTF_8) do
assert_raise_with_message(NameError, /\u{3042}/) {s.get(:"\u{3042}")}
end
assert_raise_with_message(NameError, /\u{3042}/) {s.get(:"\u{3042}")}
end
end
15 changes: 15 additions & 0 deletions test/mri/-ext-/symbol/noninterned_name.rb
@@ -0,0 +1,15 @@
require "-test-/symbol"

module Test_Symbol
module NonInterned
module_function

def noninterned_name(prefix = "")
prefix += "_#{Thread.current.object_id.to_s(36).tr('-', '_')}"
begin
name = "#{prefix}_#{rand(0x1000).to_s(16)}_#{Time.now.usec}"
end while Bug::Symbol.find(name)
name
end
end
end
23 changes: 6 additions & 17 deletions test/mri/-ext-/symbol/test_inadvertent_creation.rb
@@ -1,16 +1,10 @@
# frozen_string_literal: false
require 'test/unit'
require "-test-/symbol"
require_relative 'noninterned_name'

module Test_Symbol
class TestInadvertent < Test::Unit::TestCase
def noninterned_name(prefix = "")
prefix += "_#{Thread.current.object_id.to_s(36).tr('-', '_')}"
begin
name = "#{prefix}_#{rand(0x1000).to_s(16)}_#{Time.now.usec}"
end while Bug::Symbol.find(name)
name
end
include NonInterned

def setup
@obj = Object.new
Expand Down Expand Up @@ -362,22 +356,17 @@ def test_invalid_attr_accessor
end

def test_gc_attrset
assert_separately(['-r-test-/symbol', '-', '[ruby-core:62226] [Bug #9787]'], <<-'end;') # begin
bug = ARGV.shift
def noninterned_name(prefix = "")
prefix += "_#{Thread.current.object_id.to_s(36).tr('-', '_')}"
begin
name = "#{prefix}_#{rand(0x1000).to_s(16)}_#{Time.now.usec}"
end while Bug::Symbol.find(name) or Bug::Symbol.find(name + "=")
name
end
assert_separately(['-r-test-/symbol', '-r-ext-/symbol/noninterned_name', '-'], "#{<<-'begin;'}\n#{<<-"end;"}")
bug = '[ruby-core:62226] [Bug #9787]'
include Test_Symbol::NonInterned
names = Array.new(1000) {noninterned_name("gc")}
names.each {|n| n.to_sym}
GC.start(immediate_sweep: false)
names.each do |n|
eval(":#{n}=")
assert_nothing_raised(TypeError, bug) {eval("proc{self.#{n} = nil}")}
end
begin;
end;
end

Expand Down

0 comments on commit c752675

Please sign in to comment.