summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-25 15:04:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-25 15:04:05 +0000
commita1cb9efd343c9150260d457dfea0005166858690 (patch)
treecc162d9fc60983953ad915aff2cef8debe3a8424 /test
parentd289b8e8c6a730063723a2637c45e93cb4bc9a45 (diff)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_beginendblock.rb36
1 files changed, 33 insertions, 3 deletions
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb
index a4a5f114fc..3b087593cd 100644
--- a/test/ruby/test_beginendblock.rb
+++ b/test/ruby/test_beginendblock.rb
@@ -1,5 +1,6 @@
require 'test/unit'
require 'tempfile'
+$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
require 'envutil'
class TestBeginEndBlock < Test::Unit::TestCase
@@ -12,9 +13,8 @@ class TestBeginEndBlock < Test::Unit::TestCase
def test_beginendblock
ruby = EnvUtil.rubybin
target = File.join(DIR, 'beginmainend.rb')
- IO.popen("#{q(ruby)} #{q(target)}"){|io|
- assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e4 e3 e2 e4-2 e4-1 e1-1 e4-1-1), io.read.split)
- }
+ result = IO.popen("#{q(ruby)} #{q(target)}"){|io|io.read}
+ assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e4 e3 e2 e4-2 e4-1 e1-1 e4-1-1), result.split)
end
def test_begininmethod
@@ -54,4 +54,34 @@ EOW
# expecting Tempfile to unlink launcher and errout file.
end
+ def test_raise_in_at_exit
+ # [ruby-core:09675]
+ ruby = EnvUtil.rubybin
+ out = IO.popen("#{q(ruby)} -e 'STDERR.reopen(STDOUT);" \
+ "at_exit{raise %[SomethingBad]};" \
+ "raise %[SomethingElse]'") {|f|
+ f.read
+ }
+ assert_match /SomethingBad/, out
+ assert_match /SomethingElse/, out
+ end
+
+ def test_should_propagate_exit_code
+ ruby = EnvUtil.rubybin
+ assert_equal false, system("#{q(ruby)} -e 'at_exit{exit 2}'")
+ assert_equal 2, $?.exitstatus
+ assert_nil $?.termsig
+ end
+
+ def test_should_propagate_signaled
+ ruby = EnvUtil.rubybin
+ out = IO.popen("#{q(ruby)} -e 'STDERR.reopen(STDOUT);" \
+ "at_exit{Process.kill(:INT, $$)}'"){|f|
+ f.read
+ }
+ assert_match /Interrupt$/, out
+ Process.kill(0, 0) rescue return # check if signal works
+ assert_nil $?.exitstatus
+ assert_equal Signal.list["INT"], $?.termsig
+ end
end