ruby-changes:59838
From: Koichi <ko1@a...>
Date: Tue, 28 Jan 2020 15:24:45 +0900 (JST)
Subject: [ruby-changes:59838] 0f03c1433e (master): support multi-run for test/ruby/test_primitive.rb
https://git.ruby-lang.org/ruby.git/commit/?id=0f03c1433e From 0f03c1433ef6a17acd64f4dc4a539b4630e975aa Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Tue, 28 Jan 2020 14:44:12 +0900 Subject: support multi-run for test/ruby/test_primitive.rb need to redefine some classes. diff --git a/test/ruby/test_primitive.rb b/test/ruby/test_primitive.rb index 19af44a..f1db934 100644 --- a/test/ruby/test_primitive.rb +++ b/test/ruby/test_primitive.rb @@ -26,24 +26,31 @@ class TestRubyPrimitive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_primitive.rb#L26 assert_equal 4, c end - C = 1 - class A - Const = 1 - class B - Const = 2 - class C - Const = 3 - def const - Const + C_Setup = -> do + remove_const :C if defined? ::TestRubyPrimitive::C + remove_const :A if defined? ::TestRubyPrimitive::A + + C = 1 + class A + Const = 1 + class B + Const = 2 + class C + Const = 3 + def const + Const + end end end end + (1..2).map { + A::B::C::Const + } end - (1..2).map { - A::B::C::Const - } def test_constant + C_Setup.call + assert_equal 1, C assert_equal 1, C assert_equal 1, A::Const @@ -145,42 +152,60 @@ class TestRubyPrimitive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_primitive.rb#L152 assert_equal 7, ($test_ruby_primitive_gvar = 7) end - class A7 - @@c = 1 - def m - @@c += 1 + A7_Setup = -> do + remove_const :A7 if defined? TestRubyPrimitive::A7 + + class A7 + @@c = 1 + def m + @@c += 1 + 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 - class A8 - @@c = 1 - class << self - def m - @@c += 1 + 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 + A8_Setup.call + assert_equal 2, A8.m assert_equal 3, A8.m assert_equal 4, A8.m end - class A9 - @@c = 1 - def self.m - @@c += 1 + A9_Setup = -> do + remove_const :A8 if defined? TestRubyPrimitive::A8 + + class A9 + @@c = 1 + def self.m + @@c += 1 + end end end def test_cvar_from_singleton_method2 + A9_Setup.call + assert_equal 2, A9.m assert_equal 3, A9.m assert_equal 4, A9.m @@ -199,6 +224,9 @@ class TestRubyPrimitive < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_primitive.rb#L224 @iv += 2 assert_equal 4, @iv + # init @@cv + @@cv = nil + @@cv ||= 1 assert_equal 1, @@cv @@cv &&= 2 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/