diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-07 06:27:11 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-07 06:27:11 +0000 |
commit | cd8d08b5329fd86660cced8a5b91c4a042f2e2a0 (patch) | |
tree | 9be66a2d0ca34f17a0c52b1616bffa570a28264a /test/ruby/test_beginendblock.rb | |
parent | 0a5f6fd37d7b83dd78adfbaecb050fd3cc4fb3e9 (diff) |
* test/ruby/test_beginendblock.rb: add tests for nested BEGIN/END.
* test/ruby/beginmainend.rb: add tests for nested BEGIN/END.
* test/ruby/endblockwarn.rb: new file added to test of END-in-method warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_beginendblock.rb')
-rw-r--r-- | test/ruby/test_beginendblock.rb | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb index 2e1940f0b7..202a8080ae 100644 --- a/test/ruby/test_beginendblock.rb +++ b/test/ruby/test_beginendblock.rb @@ -1,27 +1,57 @@ require 'test/unit' +require 'tempfile' require "#{File.dirname(File.expand_path(__FILE__))}/envutil" class TestBeginEndBlock < Test::Unit::TestCase DIR = File.dirname(File.expand_path(__FILE__)) + def q(content) + "\"#{content}\"" + end + def test_beginendblock ruby = EnvUtil.rubybin - io = IO.popen("\"#{ruby}\" \"#{DIR}/beginmainend.rb\"") - assert_equal(%w(begin1 begin2 main innerbegin1 innerbegin2 end1 innerend1 innerend2 end2).join("\n") << "\n", io.read) + 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 - end - def test_endinmethod - verbose, $VERBOSE = $VERBOSE, nil - assert_nothing_raised(SyntaxError) do - eval("def foo; END {}; end") + assert_raises(SyntaxError) do + eval('eval("def foo; BEGIN {}; end")') end - ensure - $VERBOSE = verbose + 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\\"" +exec(cmd) +exit!("must not reach here") +EOF + launcher.close + launcherpath = launcher.path + errout.close + erroutpath = errout.path + system("#{q(ruby)} #{q(launcherpath)} #{q(erroutpath)}") + expected = <<EOW +endblockwarn.rb:16: 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 end |