1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/ruby/envutil.rb (Test::Unit::Assertions#assert_in_out_err): new

method.

* test/ruby/test_argf.rb: use assert_in_out_err instead of
  EnvUtil.rubyexec.

* test/ruby/test_module.rb: ditto.

* test/ruby/test_require.rb: ditto.

* test/ruby/test_objectspace.rb: ditto.

* test/ruby/test_object.rb: ditto.

* test/ruby/test_string.rb: ditto.

* test/ruby/test_method.rb: ditto.

* test/ruby/test_variable.rb: ditto.

* test/ruby/test_io.rb: ditto.

* test/ruby/test_rubyoptions.rb: ditto.

* test/ruby/test_exception.rb: ditto.

* test/ruby/test_class.rb: ditto.

* test/ruby/test_thread.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-07-15 15:26:04 +00:00
parent e74af2cf41
commit eafe85f603
15 changed files with 568 additions and 869 deletions

View file

@ -3,10 +3,6 @@ require 'thread'
require_relative 'envutil'
class TestThread < Test::Unit::TestCase
def ruby(*r, &b)
EnvUtil.rubyexec(*r, &b)
end
class Thread < ::Thread
Threads = []
def self.new(*)
@ -180,13 +176,11 @@ class TestThread < Test::Unit::TestCase
end
def test_kill_main_thread
ruby do |w, r, e|
w.puts "p 1"
w.puts "Thread.kill Thread.current"
w.puts "p 2"
w.close
assert_equal("1", r.read.chomp)
end
assert_in_out_err([], <<-INPUT, %w(1), [])
p 1
Thread.kill Thread.current
p 2
INPUT
end
def test_exit
@ -218,104 +212,83 @@ class TestThread < Test::Unit::TestCase
end
def test_stop
ruby do |w, r, e|
w.puts "begin"
w.puts " Thread.stop"
w.puts " p 1"
w.puts "rescue ThreadError"
w.puts " p 2"
w.puts "end"
w.close
assert_equal("2", r.read.chomp)
end
assert_in_out_err([], <<-INPUT, %w(2), [])
begin
Thread.stop
p 1
rescue ThreadError
p 2
end
INPUT
end
def test_list
ruby do |w, r, e|
w.puts "t1 = Thread.new { sleep }"
w.puts "t2 = Thread.new { loop { } }"
w.puts "t3 = Thread.new { }.join"
w.puts "p [Thread.current, t1, t2].sort_by {|t| t.object_id }"
w.puts "p Thread.list.sort_by {|t| t.object_id }"
w.close
assert_equal(r.gets, r.gets)
assert_in_out_err([], <<-INPUT) do |r, e|
t1 = Thread.new { sleep }
t2 = Thread.new { loop { } }
t3 = Thread.new { }.join
p [Thread.current, t1, t2].sort_by {|t| t.object_id }
p Thread.list.sort_by {|t| t.object_id }
INPUT
assert_equal(r.first, r.last)
assert_equal([], e)
end
end
def test_main
ruby do |w, r, e|
w.puts "p Thread.main == Thread.current"
w.puts "Thread.new { p Thread.main == Thread.current }.join"
w.close
assert_equal("true", r.gets.chomp)
assert_equal("false", r.gets.chomp)
end
assert_in_out_err([], <<-INPUT, %w(true false), [])
p Thread.main == Thread.current
Thread.new { p Thread.main == Thread.current }.join
INPUT
end
def test_abort_on_exception
ruby do |w, r, e|
w.puts "p Thread.abort_on_exception"
w.puts "begin"
w.puts " Thread.new { raise }"
w.puts " sleep 0.5"
w.puts " p 1"
w.puts "rescue"
w.puts " p 2"
w.puts "end"
w.close_write
assert_equal("false", r.gets.chomp)
assert_equal("1", r.gets.chomp)
assert_equal("", e.read)
end
assert_in_out_err([], <<-INPUT, %w(false 1), [])
p Thread.abort_on_exception
begin
Thread.new { raise }
sleep 0.5
p 1
rescue
p 2
end
INPUT
ruby do |w, r, e|
w.puts "Thread.abort_on_exception = true"
w.puts "p Thread.abort_on_exception"
w.puts "begin"
w.puts " Thread.new { raise }"
w.puts " sleep 0.5"
w.puts " p 1"
w.puts "rescue"
w.puts " p 2"
w.puts "end"
w.close_write
assert_equal("true", r.gets.chomp)
assert_equal("2", r.gets.chomp)
assert_equal("", e.read)
end
assert_in_out_err([], <<-INPUT, %w(true 2), [])
Thread.abort_on_exception = true
p Thread.abort_on_exception
begin
Thread.new { raise }
sleep 0.5
p 1
rescue
p 2
end
INPUT
ruby('-d') do |w, r, e|
w.puts "p Thread.abort_on_exception"
w.puts "begin"
w.puts " Thread.new { raise }"
w.puts " sleep 0.5"
w.puts " p 1"
w.puts "rescue"
w.puts " p 2"
w.puts "end"
w.close_write
assert_equal("false", r.gets.chomp)
assert_equal("2", r.gets.chomp)
assert_not_equal("", e.read)
end
assert_in_out_err(%w(-d), <<-INPUT, %w(false 2), /.+/)
p Thread.abort_on_exception
begin
Thread.new { raise }
sleep 0.5
p 1
rescue
p 2
end
INPUT
ruby do |w, r, e|
w.puts "p Thread.abort_on_exception"
w.puts "begin"
w.puts " t = Thread.new { sleep 0.5; raise }"
w.puts " t.abort_on_exception = true"
w.puts " p t.abort_on_exception"
w.puts " sleep 1"
w.puts " p 1"
w.puts "rescue"
w.puts " p 2"
w.puts "end"
w.close_write
assert_equal("false", r.gets.chomp)
assert_equal("true", r.gets.chomp)
assert_equal("2", r.gets.chomp)
assert_equal("", e.read)
end
assert_in_out_err([], <<-INPUT, %w(false true 2), [])
p Thread.abort_on_exception
begin
t = Thread.new { sleep 0.5; raise }
t.abort_on_exception = true
p t.abort_on_exception
sleep 1
p 1
rescue
p 2
end
INPUT
end
def test_status_and_stop_p