diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-01-28 14:16:06 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-01-28 15:23:51 +0900 |
commit | 1bc731cb65cfd9baae718b9a8588e668dd1c75e0 (patch) | |
tree | f45e9228066188c610dcd2005dc512b666cb12a8 | |
parent | cc2fe6936c0e9b815d43a942d2bb7dff0363ccf6 (diff) | |
download | ruby-1bc731cb65cfd9baae718b9a8588e668dd1c75e0.tar.gz |
support multi-run for test/ruby/test_module.rb
add cleanup code in some tests.
-rw-r--r-- | test/ruby/test_module.rb | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 9373c48a9a..2e0a14e300 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -88,8 +88,11 @@ class TestModule < Test::Unit::TestCase 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 @@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 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 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 end def test_dup + OtherSetup.call + bug6454 = '[ruby-core:45132]' a = Module.new @@ -522,6 +533,11 @@ class TestModule < Test::Unit::TestCase 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 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 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 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 assert_warning '' do assert_equal(42, AttrTest.cattr) end + + AttrTest.reset end def test_uninitialized_attr_non_object |