1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/ruby/test_signal.rb: add tests to achieve over 80% test

coverage of signal.c.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-05-30 13:42:23 +00:00
parent bd9030438e
commit 76f2fc8b46
2 changed files with 104 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Fri May 30 22:40:53 2008 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_signal.rb: add tests to achieve over 80% test
coverage of signal.c.
Fri May 30 22:28:03 2008 Yusuke Endoh <mame@tsg.ne.jp>
* signal.c (esignal_signo): fix SignalException#signo which returned

View file

@ -64,4 +64,103 @@ class TestSignal < Test::Unit::TestCase
w0.close
end
end
def test_invalid_signal_name
return unless Process.respond_to?(:kill)
assert_raise(ArgumentError) { Process.kill(:XXXXXXXXXX, $$) }
end
def test_signal_exception
assert_raise(ArgumentError) { SignalException.new }
assert_raise(ArgumentError) { SignalException.new(-1) }
assert_raise(ArgumentError) { SignalException.new(:XXXXXXXXXX) }
Signal.list.each do |signm, signo|
next if signm == "EXIT"
assert_equal(SignalException.new(signm).signo, signo)
assert_equal(SignalException.new(signm.to_sym).signo, signo)
assert_equal(SignalException.new(signo).signo, signo)
end
end
def test_interrupt
assert_raise(Interrupt) { raise Interrupt.new }
end
def test_signal2
return unless Process.respond_to?(:kill)
begin
x = false
oldtrap = Signal.trap(:INT) {|sig| x = true }
GC.start
assert_raise(ArgumentError) { Process.kill }
Timeout.timeout(10) do
x = false
Process.kill(SignalException.new(:INT).signo, $$)
nil until x
x = false
Process.kill("INT", $$)
nil until x
x = false
Process.kill("SIGINT", $$)
nil until x
x = false
o = Object.new
def o.to_str; "SIGINT"; end
Process.kill(o, $$)
nil until x
end
assert_raise(ArgumentError) { Process.kill(Object.new, $$) }
ensure
Signal.trap(:INT, oldtrap) if oldtrap
end
end
def test_trap
return unless Process.respond_to?(:kill)
begin
oldtrap = Signal.trap(:INT) {|sig| }
assert_raise(ArgumentError) { Signal.trap }
assert_raise(SecurityError) do
s = proc {}.taint
Signal.trap(:INT, s)
end
# FIXME!
Signal.trap(:INT, nil)
Signal.trap(:INT, "")
Signal.trap(:INT, "SIG_IGN")
Signal.trap(:INT, "IGNORE")
Signal.trap(:INT, "SIG_DFL")
Signal.trap(:INT, "SYSTEM_DEFAULT")
Signal.trap(:INT, "EXIT")
assert_raise(ArgumentError) { Signal.trap(:INT, "xxxxxx") }
assert_raise(ArgumentError) { Signal.trap(:INT, "xxxx") }
Signal.trap(SignalException.new(:INT).signo, "SIG_DFL")
assert_raise(ArgumentError) { Signal.trap(-1, "xxxx") }
o = Object.new
def o.to_str; "SIGINT"; end
Signal.trap(o, "SIG_DFL")
assert_raise(ArgumentError) { Signal.trap("XXXXXXXXXX", "SIG_DFL") }
ensure
Signal.trap(:INT, oldtrap) if oldtrap
end
end
end