diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-29 04:06:12 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-29 04:06:12 +0000 |
commit | 11dbedfaad4a9a9521ece2198a8dc491678b1902 (patch) | |
tree | 4806dc0ff0c3827ecc40921838c4507340cfdb3a /ruby_1_8_6/test/ruby/test_beginendblock.rb | |
parent | 29e8d8b439b34c2a394407dc598fc01d14be0c20 (diff) |
add tag v1_8_6_5001v1_8_6_5001
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_6_5001@13304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_8_6/test/ruby/test_beginendblock.rb')
-rw-r--r-- | ruby_1_8_6/test/ruby/test_beginendblock.rb | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/ruby_1_8_6/test/ruby/test_beginendblock.rb b/ruby_1_8_6/test/ruby/test_beginendblock.rb new file mode 100644 index 0000000000..a60e41b848 --- /dev/null +++ b/ruby_1_8_6/test/ruby/test_beginendblock.rb @@ -0,0 +1,86 @@ +require 'test/unit' +require 'tempfile' +$:.replace([File.dirname(File.expand_path(__FILE__))] | $:) +require 'envutil' + +class TestBeginEndBlock < Test::Unit::TestCase + DIR = File.dirname(File.expand_path(__FILE__)) + + def q(content) + "\"#{content}\"" + end + + def test_beginendblock + ruby = EnvUtil.rubybin + target = File.join(DIR, 'beginmainend.rb') + io = IO.popen("#{q(ruby)} #{q(target)}") + 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) + io.close + end + + def test_begininmethod + assert_raises(SyntaxError) do + eval("def foo; BEGIN {}; end") + end + + assert_raises(SyntaxError) do + eval('eval("def foo; BEGIN {}; end")') + end + end + + def test_endblockwarn + ruby = EnvUtil.rubybin + # Use Tempfile to create temporary file path. + launcher = Tempfile.new(self.class.name) + errout = Tempfile.new(self.class.name) + + launcher << <<EOF +errout = ARGV.shift +STDERR.reopen(File.open(errout, "w")) +STDERR.sync = true +Dir.chdir(#{q(DIR)}) +cmd = "\\"#{ruby}\\" \\"endblockwarn.rb\\"" +system(cmd) +EOF + launcher.close + launcherpath = launcher.path + errout.close + erroutpath = errout.path + system("#{q(ruby)} #{q(launcherpath)} #{q(erroutpath)}") + expected = <<EOW +endblockwarn.rb:2: warning: END in method; use at_exit +(eval):2: warning: END in method; use at_exit +EOW + assert_equal(expected, File.read(erroutpath)) + # 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(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("#{ruby} #{File.dirname(__FILE__)}/suicide.rb"){|f| + f.read + } + assert_match /Interrupt$/, out + assert_nil $?.exitstatus + assert_equal Signal.list["INT"], $?.termsig + end +end |