ruby-changes:59830
From: Koichi <ko1@a...>
Date: Tue, 28 Jan 2020 15:24:34 +0900 (JST)
Subject: [ruby-changes:59830] 1bc731cb65 (master): support multi-run for test/ruby/test_module.rb
https://git.ruby-lang.org/ruby.git/commit/?id=1bc731cb65 From 1bc731cb65cfd9baae718b9a8588e668dd1c75e0 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Tue, 28 Jan 2020 14:16:06 +0900 Subject: support multi-run for test/ruby/test_module.rb add cleanup code in some tests. diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 9373c48..2e0a14e 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -88,8 +88,11 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L88 private :user3 end - module Other - def other + OtherSetup = -> do + remove_const :Other if defined? ::TestModule::Other + module Other + def other + end end end @@ -223,6 +226,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L226 @@class_eval = 'b' def test_class_eval + OtherSetup.call + Other.class_eval("CLASS_EVAL = 1") assert_equal(1, Other::CLASS_EVAL) assert_include(Other.constants, :CLASS_EVAL) @@ -331,6 +336,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L336 end def test_nested_defined + OtherSetup.call + assert_send([Object, :const_defined?, [self.class.name, 'Other'].join('::')]) assert_send([self.class, :const_defined?, 'User::USER']) assert_not_send([self.class, :const_defined?, 'User::Foo']) @@ -363,6 +370,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L370 end def test_const_set + OtherSetup.call + assert_not_operator(Other, :const_defined?, :KOALA) Other.const_set(:KOALA, 99) assert_operator(Other, :const_defined?, :KOALA) @@ -421,6 +430,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L430 end def test_dup + OtherSetup.call + bug6454 = '[ruby-core:45132]' a = Module.new @@ -522,6 +533,11 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L533 assert !c.method_defined?(:userx, false) c.define_method(:userx){} assert c.method_defined?(:userx, false) + + # cleanup + User.class_eval do + remove_const :FOO + end end def module_exec_aux @@ -552,6 +568,14 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L568 def dynamically_added_method_4; end end assert_method_defined?(User, :dynamically_added_method_4) + + # cleanup + User.class_eval do + remove_method :dynamically_added_method_1 + remove_method :dynamically_added_method_2 + remove_method :dynamically_added_method_3 + remove_method :dynamically_added_method_4 + end end def test_module_eval @@ -652,6 +676,10 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L676 c2 = Module.constants assert_equal([:WALTER], c2 - c1) + Object.class_eval do + remove_const :WALTER + end + assert_equal([], Module.constants(true)) assert_equal([], Module.constants(false)) @@ -2152,6 +2180,9 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L2180 class AttrTest class << self attr_accessor :cattr + def reset + self.cattr = nil + end end attr_accessor :iattr def ivar @@ -2194,6 +2225,8 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L2225 assert_warning '' do assert_equal(42, AttrTest.cattr) end + + AttrTest.reset end def test_uninitialized_attr_non_object -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/