test_settracefunc.rb: fix tests

* test/ruby/test_settracefunc.rb (assert_security_error_safe4): fix
  tests to set $SAFE separatedly

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-01-29 08:58:04 +00:00
parent 68fa2e8cae
commit e3f88ac44d

View File

@ -397,34 +397,38 @@ class TestSetTraceFunc < Test::Unit::TestCase
assert_equal(self, ok, bug3921) assert_equal(self, ok, bug3921)
end end
def assert_security_error_safe4 def assert_security_error_safe4(block)
func = lambda { assert_raise(SecurityError) do
$SAFE = 4 block.call
proc {yield} end
}.call
assert_raise(SecurityError, &func)
end end
def test_set_safe4 def test_set_safe4
assert_security_error_safe4 do func = proc do
$SAFE = 4
set_trace_func(lambda {|*|}) set_trace_func(lambda {|*|})
end end
assert_security_error_safe4(func)
end end
def test_thread_set_safe4 def test_thread_set_safe4
th = Thread.start {sleep} th = Thread.start {sleep}
assert_security_error_safe4 do func = proc do
$SAFE = 4
th.set_trace_func(lambda {|*|}) th.set_trace_func(lambda {|*|})
end end
assert_security_error_safe4(func)
ensure ensure
th.kill th.kill
end end
def test_thread_add_safe4 def test_thread_add_safe4
th = Thread.start {sleep} th = Thread.start {sleep}
assert_security_error_safe4 do func = proc do
$SAFE = 4
th.add_trace_func(lambda {|*|}) th.add_trace_func(lambda {|*|})
end end
assert_security_error_safe4(func)
ensure ensure
th.kill th.kill
end end
@ -922,15 +926,19 @@ class TestSetTraceFunc < Test::Unit::TestCase
def test_trace_point_enable_safe4 def test_trace_point_enable_safe4
tp = TracePoint.new {} tp = TracePoint.new {}
assert_security_error_safe4 do func = proc do
$SAFE = 4
tp.enable tp.enable
end end
assert_security_error_safe4(func)
end end
def test_trace_point_disable_safe4 def test_trace_point_disable_safe4
tp = TracePoint.new {} tp = TracePoint.new {}
assert_security_error_safe4 do func = proc do
$SAFE = 4
tp.disable tp.disable
end end
assert_security_error_safe4(func)
end end
end end