1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

support multi-run for test/ruby/test_primitive.rb

need to redefine some classes.
This commit is contained in:
Koichi Sasada 2020-01-28 14:44:12 +09:00
parent 9b65bfdc9e
commit 0f03c1433e

View file

@ -26,24 +26,31 @@ class TestRubyPrimitive < Test::Unit::TestCase
assert_equal 4, c assert_equal 4, c
end end
C = 1 C_Setup = -> do
class A remove_const :C if defined? ::TestRubyPrimitive::C
Const = 1 remove_const :A if defined? ::TestRubyPrimitive::A
class B
Const = 2 C = 1
class C class A
Const = 3 Const = 1
def const class B
Const Const = 2
class C
Const = 3
def const
Const
end
end end
end end
end end
(1..2).map {
A::B::C::Const
}
end end
(1..2).map {
A::B::C::Const
}
def test_constant def test_constant
C_Setup.call
assert_equal 1, C assert_equal 1, C
assert_equal 1, C assert_equal 1, C
assert_equal 1, A::Const assert_equal 1, A::Const
@ -145,42 +152,60 @@ class TestRubyPrimitive < Test::Unit::TestCase
assert_equal 7, ($test_ruby_primitive_gvar = 7) assert_equal 7, ($test_ruby_primitive_gvar = 7)
end end
class A7 A7_Setup = -> do
@@c = 1 remove_const :A7 if defined? TestRubyPrimitive::A7
def m
@@c += 1
end
end
def test_cvar_from_instance_method class A7
assert_equal 2, A7.new.m @@c = 1
assert_equal 3, A7.new.m
assert_equal 4, A7.new.m
end
class A8
@@c = 1
class << self
def m def m
@@c += 1 @@c += 1
end end
end end
end end
def test_cvar_from_instance_method
A7_Setup.call
assert_equal 2, A7.new.m
assert_equal 3, A7.new.m
assert_equal 4, A7.new.m
end
A8_Setup = -> do
remove_const :A8 if defined? TestRubyPrimitive::A8
class A8
@@c = 1
class << self
def m
@@c += 1
end
end
end
end
def test_cvar_from_singleton_method def test_cvar_from_singleton_method
A8_Setup.call
assert_equal 2, A8.m assert_equal 2, A8.m
assert_equal 3, A8.m assert_equal 3, A8.m
assert_equal 4, A8.m assert_equal 4, A8.m
end end
class A9 A9_Setup = -> do
@@c = 1 remove_const :A8 if defined? TestRubyPrimitive::A8
def self.m
@@c += 1 class A9
@@c = 1
def self.m
@@c += 1
end
end end
end end
def test_cvar_from_singleton_method2 def test_cvar_from_singleton_method2
A9_Setup.call
assert_equal 2, A9.m assert_equal 2, A9.m
assert_equal 3, A9.m assert_equal 3, A9.m
assert_equal 4, A9.m assert_equal 4, A9.m
@ -199,6 +224,9 @@ class TestRubyPrimitive < Test::Unit::TestCase
@iv += 2 @iv += 2
assert_equal 4, @iv assert_equal 4, @iv
# init @@cv
@@cv = nil
@@cv ||= 1 @@cv ||= 1
assert_equal 1, @@cv assert_equal 1, @@cv
@@cv &&= 2 @@cv &&= 2