~ubuntu-branches/ubuntu/precise/ruby1.9/precise

« back to all changes in this revision

Viewing changes to test/ruby/test_beginendblock.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-05-26 21:02:58 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070526210258-nkfg24tdre4e3tqw
Tags: 1.9.0+20070526-1
new upstream snapshot. (2006-07-26)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'test/unit'
2
2
require 'tempfile'
 
3
$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
3
4
require 'envutil'
4
5
 
5
6
class TestBeginEndBlock < Test::Unit::TestCase
12
13
  def test_beginendblock
13
14
    ruby = EnvUtil.rubybin
14
15
    target = File.join(DIR, 'beginmainend.rb')
15
 
    IO.popen("#{q(ruby)} #{q(target)}"){|io|
16
 
      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)
17
 
    }
 
16
    result = IO.popen("#{q(ruby)} #{q(target)}"){|io|io.read}
 
17
    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)
18
18
  end
19
19
 
20
20
  def test_begininmethod
54
54
    # expecting Tempfile to unlink launcher and errout file.
55
55
  end
56
56
 
 
57
  def test_raise_in_at_exit
 
58
    # [ruby-core:09675]
 
59
    ruby = EnvUtil.rubybin
 
60
    out = IO.popen("#{q(ruby)} -e 'STDERR.reopen(STDOUT);" \
 
61
                   "at_exit{raise %[SomethingBad]};" \
 
62
                   "raise %[SomethingElse]'") {|f|
 
63
      f.read
 
64
    }
 
65
    assert_match /SomethingBad/, out
 
66
    assert_match /SomethingElse/, out
 
67
  end
 
68
 
 
69
  def test_should_propagate_exit_code
 
70
    ruby = EnvUtil.rubybin
 
71
    assert_equal false, system("#{q(ruby)} -e 'at_exit{exit 2}'")
 
72
    assert_equal 2, $?.exitstatus
 
73
    assert_nil $?.termsig
 
74
  end
 
75
 
 
76
  def test_should_propagate_signaled
 
77
    ruby = EnvUtil.rubybin
 
78
    out = IO.popen("#{q(ruby)} -e 'STDERR.reopen(STDOUT);" \
 
79
                   "at_exit{Process.kill(:INT, $$)}'"){|f|
 
80
      f.read
 
81
    }
 
82
    assert_match /Interrupt$/, out
 
83
    Process.kill(0, 0) rescue return # check if signal works
 
84
    assert_nil $?.exitstatus
 
85
    assert_equal Signal.list["INT"], $?.termsig
 
86
  end
57
87
end