From 2e315baf48b7c06d487cf6082e82377e93442bc7 Mon Sep 17 00:00:00 2001 From: eregon Date: Thu, 14 Dec 2017 13:08:02 +0000 Subject: The main Thread should have report_on_exception=true for consistency * Adapt test and add specs. * See [Feature #14143] [ruby-core:84227] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/thread/report_on_exception_spec.rb | 10 ++++++++++ test/ruby/test_thread.rb | 4 ++-- thread.c | 1 - vm.c | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spec/ruby/core/thread/report_on_exception_spec.rb b/spec/ruby/core/thread/report_on_exception_spec.rb index 74b7984a32..d8400c080a 100644 --- a/spec/ruby/core/thread/report_on_exception_spec.rb +++ b/spec/ruby/core/thread/report_on_exception_spec.rb @@ -34,6 +34,16 @@ ruby_version_is "2.4" do end describe "Thread#report_on_exception" do + ruby_version_is "2.5" do + it "returns true for the main Thread" do + Thread.current.report_on_exception.should == true + end + + it "returns true for new Threads" do + Thread.new { Thread.current.report_on_exception }.value.should == true + end + end + it "returns whether the Thread will print a backtrace if it exits with an exception" do t = Thread.new { Thread.current.report_on_exception = true } t.join diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 32a155ef18..386a5cb89b 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -382,8 +382,8 @@ class TestThread < Test::Unit::TestCase assert_equal(true, Thread.report_on_exception, "global flag is true by default") - assert_equal(false, Thread.current.report_on_exception, - "the main thread has report_on_exception=false") + assert_equal(true, Thread.current.report_on_exception, + "the main thread has report_on_exception=true") Thread.report_on_exception = true Thread.current.report_on_exception = false diff --git a/thread.c b/thread.c index 96e6c360c4..5ff387cd43 100644 --- a/thread.c +++ b/thread.c @@ -743,7 +743,6 @@ thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS)) RBASIC_CLEAR_CLASS(th->pending_interrupt_mask_stack); native_mutex_initialize(&th->interrupt_lock); - th->report_on_exception = th->vm->thread_report_on_exception; /* kick thread */ err = native_thread_create(th); diff --git a/vm.c b/vm.c index 83b0a9cffc..be04f5db01 100644 --- a/vm.c +++ b/vm.c @@ -2518,6 +2518,7 @@ th_init(rb_thread_t *th, VALUE self) th->retval = Qundef; #endif th->name = Qnil; + th->report_on_exception = th->vm->thread_report_on_exception; } static VALUE -- cgit v1.2.3