mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
support multi-run for test/ruby/test_module.rb
add cleanup code in some tests.
This commit is contained in:
parent
cc2fe6936c
commit
1bc731cb65
1 changed files with 35 additions and 2 deletions
|
@ -88,8 +88,11 @@ class TestModule < Test::Unit::TestCase
|
||||||
private :user3
|
private :user3
|
||||||
end
|
end
|
||||||
|
|
||||||
module Other
|
OtherSetup = -> do
|
||||||
def other
|
remove_const :Other if defined? ::TestModule::Other
|
||||||
|
module Other
|
||||||
|
def other
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -223,6 +226,8 @@ class TestModule < Test::Unit::TestCase
|
||||||
@@class_eval = 'b'
|
@@class_eval = 'b'
|
||||||
|
|
||||||
def test_class_eval
|
def test_class_eval
|
||||||
|
OtherSetup.call
|
||||||
|
|
||||||
Other.class_eval("CLASS_EVAL = 1")
|
Other.class_eval("CLASS_EVAL = 1")
|
||||||
assert_equal(1, Other::CLASS_EVAL)
|
assert_equal(1, Other::CLASS_EVAL)
|
||||||
assert_include(Other.constants, :CLASS_EVAL)
|
assert_include(Other.constants, :CLASS_EVAL)
|
||||||
|
@ -331,6 +336,8 @@ class TestModule < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_defined
|
def test_nested_defined
|
||||||
|
OtherSetup.call
|
||||||
|
|
||||||
assert_send([Object, :const_defined?, [self.class.name, 'Other'].join('::')])
|
assert_send([Object, :const_defined?, [self.class.name, 'Other'].join('::')])
|
||||||
assert_send([self.class, :const_defined?, 'User::USER'])
|
assert_send([self.class, :const_defined?, 'User::USER'])
|
||||||
assert_not_send([self.class, :const_defined?, 'User::Foo'])
|
assert_not_send([self.class, :const_defined?, 'User::Foo'])
|
||||||
|
@ -363,6 +370,8 @@ class TestModule < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_const_set
|
def test_const_set
|
||||||
|
OtherSetup.call
|
||||||
|
|
||||||
assert_not_operator(Other, :const_defined?, :KOALA)
|
assert_not_operator(Other, :const_defined?, :KOALA)
|
||||||
Other.const_set(:KOALA, 99)
|
Other.const_set(:KOALA, 99)
|
||||||
assert_operator(Other, :const_defined?, :KOALA)
|
assert_operator(Other, :const_defined?, :KOALA)
|
||||||
|
@ -421,6 +430,8 @@ class TestModule < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup
|
def test_dup
|
||||||
|
OtherSetup.call
|
||||||
|
|
||||||
bug6454 = '[ruby-core:45132]'
|
bug6454 = '[ruby-core:45132]'
|
||||||
|
|
||||||
a = Module.new
|
a = Module.new
|
||||||
|
@ -522,6 +533,11 @@ class TestModule < Test::Unit::TestCase
|
||||||
assert !c.method_defined?(:userx, false)
|
assert !c.method_defined?(:userx, false)
|
||||||
c.define_method(:userx){}
|
c.define_method(:userx){}
|
||||||
assert c.method_defined?(:userx, false)
|
assert c.method_defined?(:userx, false)
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
User.class_eval do
|
||||||
|
remove_const :FOO
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def module_exec_aux
|
def module_exec_aux
|
||||||
|
@ -552,6 +568,14 @@ class TestModule < Test::Unit::TestCase
|
||||||
def dynamically_added_method_4; end
|
def dynamically_added_method_4; end
|
||||||
end
|
end
|
||||||
assert_method_defined?(User, :dynamically_added_method_4)
|
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
|
end
|
||||||
|
|
||||||
def test_module_eval
|
def test_module_eval
|
||||||
|
@ -652,6 +676,10 @@ class TestModule < Test::Unit::TestCase
|
||||||
c2 = Module.constants
|
c2 = Module.constants
|
||||||
assert_equal([:WALTER], c2 - c1)
|
assert_equal([:WALTER], c2 - c1)
|
||||||
|
|
||||||
|
Object.class_eval do
|
||||||
|
remove_const :WALTER
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal([], Module.constants(true))
|
assert_equal([], Module.constants(true))
|
||||||
assert_equal([], Module.constants(false))
|
assert_equal([], Module.constants(false))
|
||||||
|
|
||||||
|
@ -2152,6 +2180,9 @@ class TestModule < Test::Unit::TestCase
|
||||||
class AttrTest
|
class AttrTest
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :cattr
|
attr_accessor :cattr
|
||||||
|
def reset
|
||||||
|
self.cattr = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
attr_accessor :iattr
|
attr_accessor :iattr
|
||||||
def ivar
|
def ivar
|
||||||
|
@ -2194,6 +2225,8 @@ class TestModule < Test::Unit::TestCase
|
||||||
assert_warning '' do
|
assert_warning '' do
|
||||||
assert_equal(42, AttrTest.cattr)
|
assert_equal(42, AttrTest.cattr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
AttrTest.reset
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uninitialized_attr_non_object
|
def test_uninitialized_attr_non_object
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue