diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
commit | d0233291bc8a5068e52c69c210e5979e5324b5bc (patch) | |
tree | 7d9459449c33792c63eeb7baa071e76352e0baab /trunk/test/ruby/test_beginendblock.rb | |
parent | 0dc342de848a642ecce8db697b8fecd83a63e117 (diff) | |
parent | 72eaacaa15256ab95c3b52ea386f88586fb9da40 (diff) |
re-adding tag v1_9_0_4 as an alias of trunk@18848v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/test/ruby/test_beginendblock.rb')
-rw-r--r-- | trunk/test/ruby/test_beginendblock.rb | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/trunk/test/ruby/test_beginendblock.rb b/trunk/test/ruby/test_beginendblock.rb deleted file mode 100644 index 594596698b..0000000000 --- a/trunk/test/ruby/test_beginendblock.rb +++ /dev/null @@ -1,101 +0,0 @@ -require 'test/unit' -require 'tempfile' -require_relative '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') - result = IO.popen([ruby, 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) - - input = Tempfile.new(self.class.name) - inputpath = input.path - input.close - result = IO.popen([ruby, "-n", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read} - assert_equal(%w(:begin), result.split) - result = IO.popen([ruby, "-p", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read} - assert_equal(%w(:begin), result.split) - input.open - input.puts "foo\nbar" - input.close - result = IO.popen([ruby, "-n", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read} - assert_equal(%w(:begin :end), result.split) - result = IO.popen([ruby, "-p", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read} - assert_equal(%w(:begin foo bar :end), result.split) - 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)}) -system("#{ruby}", "endblockwarn_rb") -EOF - launcher.close - launcherpath = launcher.path - errout.close - erroutpath = errout.path - system(ruby, launcherpath, 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 = EnvUtil.rubybin - out = IO.popen([ruby, '-e', 'STDERR.reopen(STDOUT)', - '-e', 'at_exit{raise %[SomethingBad]}', - '-e', 'raise %[SomethingElse]']) {|f| - f.read - } - assert_match /SomethingBad/, out, "[ruby-core:9675]" - assert_match /SomethingElse/, out, "[ruby-core:9675]" - 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, - '-e', 'STDERR.reopen(STDOUT)', - '-e', 'at_exit{Process.kill(:INT, $$); loop{}}']) {|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 |