diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-12 18:44:49 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-12 18:44:49 +0000 |
commit | 15689ed7780b06ddc14cde4f427de834177283a5 (patch) | |
tree | bed64f4fdaf3e1a140642bdd0354384ae286759c /test/ruby | |
parent | 967eab83e333430600926366621aa3a978701c6a (diff) | |
download | ruby-15689ed7780b06ddc14cde4f427de834177283a5.tar.gz |
Fix test-all tests to avoid creating report_on_exception warnings
* The warnings are shown by Thread.report_on_exception defaulting to
true. [Feature #14143] [ruby-core:83979]
* Improves tests by narrowing down the scope where an exception
is expected.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_continuation.rb | 9 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 10 | ||||
-rw-r--r-- | test/ruby/test_fiber.rb | 19 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 24 | ||||
-rw-r--r-- | test/ruby/test_process.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_thread.rb | 82 |
6 files changed, 83 insertions, 66 deletions
diff --git a/test/ruby/test_continuation.rb b/test/ruby/test_continuation.rb index efc549b67a..a06ac98c8c 100644 --- a/test/ruby/test_continuation.rb +++ b/test/ruby/test_continuation.rb @@ -37,9 +37,11 @@ class TestContinuation < Test::Unit::TestCase def test_error cont = callcc{|c| c} - assert_raise(RuntimeError){ - Thread.new{cont.call}.join - } + Thread.new{ + assert_raise(RuntimeError){ + cont.call + } + }.join assert_raise(LocalJumpError){ callcc } @@ -132,4 +134,3 @@ class TestContinuation < Test::Unit::TestCase assert_equal 3, @memo end end - diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index fab6ec9f0f..3e9f4d1bc2 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -183,12 +183,12 @@ class TestException < Test::Unit::TestCase def test_throw_false bug12743 = '[ruby-core:77229] [Bug #12743]' - e = assert_raise_with_message(UncaughtThrowError, /false/, bug12743) { - Thread.start { + Thread.start { + e = assert_raise_with_message(UncaughtThrowError, /false/, bug12743) { throw false - }.join - } - assert_same(false, e.tag, bug12743) + } + assert_same(false, e.tag, bug12743) + }.join end def test_else_no_exception diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb index 92c9961259..7b513a11fa 100644 --- a/test/ruby/test_fiber.rb +++ b/test/ruby/test_fiber.rb @@ -70,10 +70,12 @@ class TestFiber < Test::Unit::TestCase assert_raise(ArgumentError){ Fiber.new # Fiber without block } - assert_raise(FiberError){ - f = Fiber.new{} - Thread.new{f.resume}.join # Fiber yielding across thread - } + f = Fiber.new{} + Thread.new{ + assert_raise(FiberError){ # Fiber yielding across thread + f.resume + } + }.join assert_raise(FiberError){ f = Fiber.new{} f.resume @@ -199,11 +201,11 @@ class TestFiber < Test::Unit::TestCase end def test_resume_root_fiber - assert_raise(FiberError) do - Thread.new do + Thread.new do + assert_raise(FiberError) do Fiber.current.resume - end.join - end + end + end.join end def test_gc_root_fiber @@ -377,4 +379,3 @@ class TestFiber < Test::Unit::TestCase assert_match(/resumed/, Fiber.current.to_s) end end - diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f3b509a261..009afc3297 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -3392,12 +3392,16 @@ __END__ str = "" IO.pipe {|r,| - t = Thread.new { r.read(nil, str) } + t = Thread.new { + assert_raise(RuntimeError) { + r.read(nil, str) + } + } sleep 0.1 until t.stop? t.raise sleep 0.1 while t.alive? assert_nothing_raised(RuntimeError, bug8669) { str.clear } - assert_raise(RuntimeError) { t.join } + t.join } end if /cygwin/ !~ RUBY_PLATFORM @@ -3406,12 +3410,16 @@ __END__ str = "" IO.pipe {|r, w| - t = Thread.new { r.readpartial(4096, str) } + t = Thread.new { + assert_raise(RuntimeError) { + r.readpartial(4096, str) + } + } sleep 0.1 until t.stop? t.raise sleep 0.1 while t.alive? assert_nothing_raised(RuntimeError, bug8669) { str.clear } - assert_raise(RuntimeError) { t.join } + t.join } end if /cygwin/ !~ RUBY_PLATFORM @@ -3431,12 +3439,16 @@ __END__ str = "" IO.pipe {|r, w| - t = Thread.new { r.sysread(4096, str) } + t = Thread.new { + assert_raise(RuntimeError) { + r.sysread(4096, str) + } + } sleep 0.1 until t.stop? t.raise sleep 0.1 while t.alive? assert_nothing_raised(RuntimeError, bug8669) { str.clear } - assert_raise(RuntimeError) { t.join } + t.join } end if /cygwin/ !~ RUBY_PLATFORM diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index e4c7bc9190..58644832d3 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1580,7 +1580,10 @@ class TestProcess < Test::Unit::TestCase pid = nil IO.pipe do |r, w| pid = fork { r.read(1); exit } - Thread.start { raise } + Thread.start { + Thread.current.report_on_exception = false + raise + } w.puts end Process.wait pid diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index ed22249091..1e3e760a4d 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -448,7 +448,10 @@ class TestThread < Test::Unit::TestCase end def test_status_and_stop_p - a = ::Thread.new { raise("die now") } + a = ::Thread.new { + Thread.current.report_on_exception = false + raise("die now") + } b = Thread.new { Thread.stop } c = Thread.new { Thread.exit } e = Thread.current @@ -560,13 +563,13 @@ class TestThread < Test::Unit::TestCase end def test_thread_local_security - assert_raise(FrozenError) do - Thread.new do - Thread.current[:foo] = :bar - Thread.current.freeze + Thread.new do + Thread.current[:foo] = :bar + Thread.current.freeze + assert_raise(FrozenError) do Thread.current[:foo] = :baz - end.join - end + end + end.join end def test_thread_local_dynamic_symbol @@ -615,11 +618,11 @@ class TestThread < Test::Unit::TestCase def test_mutex_illegal_unlock m = Thread::Mutex.new m.lock - assert_raise(ThreadError) do - Thread.new do + Thread.new do + assert_raise(ThreadError) do m.unlock - end.join - end + end + end.join end def test_mutex_fifo_like_lock @@ -767,12 +770,12 @@ class TestThread < Test::Unit::TestCase r=:ng e=Class.new(Exception) th_s = Thread.current - begin - th = Thread.start{ + th = Thread.start{ + assert_raise(RuntimeError) { Thread.handle_interrupt(Object => :on_blocking){ begin Thread.pass until r == :wait - Thread.current.raise RuntimeError + Thread.current.raise RuntimeError, "will raise in sleep" r = :ok sleep ensure @@ -780,11 +783,9 @@ class TestThread < Test::Unit::TestCase end } } - assert_raise(e) {r = :wait; sleep 0.2} - assert_raise(RuntimeError) {th.join(0.2)} - ensure - th.kill - end + } + assert_raise(e) {r = :wait; sleep 0.2} + assert_not_equal nil, th.join assert_equal(:ok,r) end @@ -971,11 +972,11 @@ _eom end def test_thread_join_main_thread - assert_raise(ThreadError) do - Thread.new(Thread.current) {|t| + Thread.new(Thread.current) {|t| + assert_raise(ThreadError) do t.join - }.join - end + end + }.join end def test_main_thread_status_at_exit @@ -1019,31 +1020,30 @@ q.pop ary = [] t = Thread.new { - begin - ary << Thread.current.status - sleep #1 - ensure + assert_raise(RuntimeError) do begin ary << Thread.current.status - sleep #2 + sleep #1 ensure - ary << Thread.current.status + begin + ary << Thread.current.status + sleep #2 + ensure + ary << Thread.current.status + end end end } - begin - Thread.pass until ary.size >= 1 - Thread.pass until t.stop? - t.kill # wake up sleep #1 - Thread.pass until ary.size >= 2 - Thread.pass until t.stop? - t.raise "wakeup" # wake up sleep #2 - Thread.pass while t.alive? - assert_equal(ary, ["run", "aborting", "aborting"]) - ensure - t.join rescue nil - end + Thread.pass until ary.size >= 1 + Thread.pass until t.stop? + t.kill # wake up sleep #1 + Thread.pass until ary.size >= 2 + Thread.pass until t.stop? + t.raise "wakeup" # wake up sleep #2 + Thread.pass while t.alive? + assert_equal(ary, ["run", "aborting", "aborting"]) + t.join end def test_mutex_owned |