2003-09-04 12:18:59 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
$KCODE = 'none'
|
|
|
|
|
|
|
|
class TestSignal < Test::Unit::TestCase
|
|
|
|
def test_signal
|
2003-10-19 22:31:47 -04:00
|
|
|
defined?(Process.kill) or return
|
|
|
|
begin
|
2003-09-04 12:18:59 -04:00
|
|
|
$x = 0
|
2003-10-19 22:31:47 -04:00
|
|
|
oldtrap = trap "SIGINT", proc{|sig| $x = 2}
|
2003-09-04 12:18:59 -04:00
|
|
|
Process.kill "SIGINT", $$
|
|
|
|
sleep 0.1
|
2003-09-05 11:15:43 -04:00
|
|
|
assert_equal(2, $x)
|
|
|
|
|
2003-09-04 12:18:59 -04:00
|
|
|
trap "SIGINT", proc{raise "Interrupt"}
|
2003-09-05 11:15:43 -04:00
|
|
|
|
|
|
|
x = assert_raises(RuntimeError) do
|
2003-09-04 12:18:59 -04:00
|
|
|
Process.kill "SIGINT", $$
|
|
|
|
sleep 0.1
|
|
|
|
end
|
2003-09-05 11:15:43 -04:00
|
|
|
assert(x)
|
|
|
|
assert_match(/Interrupt/, x.message)
|
2003-10-19 22:31:47 -04:00
|
|
|
ensure
|
|
|
|
trap "SIGINT", oldtrap
|
2003-09-04 12:18:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|