ruby-changes:44290
From: nobu <ko1@a...>
Date: Thu, 6 Oct 2016 17:29:52 +0900 (JST)
Subject: [ruby-changes:44290] nobu:r56363 (trunk): load.c: setup syntax error backtrace
nobu 2016-10-06 17:29:46 +0900 (Thu, 06 Oct 2016) New Revision: 56363 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56363 Log: load.c: setup syntax error backtrace * load.c (rb_require_safe): SyntaxError created by the parser just has the mesage and needs to set up the backtrace. [ruby-core:77491] [Bug #12811] Modified files: trunk/ChangeLog trunk/load.c trunk/test/ruby/test_require.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 56362) +++ ChangeLog (revision 56363) @@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Thu Oct 6 15:53:20 2016 Nobuyoshi Nakada <nobu@r...> +Thu Oct 6 17:29:44 2016 Nobuyoshi Nakada <nobu@r...> + + * load.c (rb_require_safe): SyntaxError created by the parser just + has the mesage and needs to set up the backtrace. + [ruby-core:77491] [Bug #12811] * load.c (rb_load_internal0): load/require is not the main script. Index: load.c =================================================================== --- load.c (revision 56362) +++ load.c (revision 56363) @@ -1040,6 +1040,7 @@ rb_require_safe(VALUE fname, int safe) https://github.com/ruby/ruby/blob/trunk/load.c#L1040 int result = rb_require_internal(fname, safe); if (result > TAG_RETURN) { + if (result == TAG_RAISE) rb_exc_raise(rb_errinfo()); JUMP_TAG(result); } if (result < 0) { Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 56362) +++ test/ruby/test_require.rb (revision 56363) @@ -182,24 +182,24 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L182 end end - def test_require_syntax_error + def assert_syntax_error_backtrace Dir.mktmpdir do |tmp| req = File.join(tmp, "test.rb") File.write(req, "'\n") - assert_raise_with_message(SyntaxError, /unterminated/) { - require req + e = assert_raise_with_message(SyntaxError, /unterminated/) { + yield req } + assert_not_nil(bt = e.backtrace) + assert_not_empty(bt.find_all {|b| b.start_with? __FILE__}) end end + def test_require_syntax_error + assert_syntax_error_backtrace {|req| require req} + end + def test_load_syntax_error - Dir.mktmpdir do |tmp| - req = File.join(tmp, "test.rb") - File.write(req, "'\n") - assert_raise_with_message(SyntaxError, /unterminated/) { - load req - } - end + assert_syntax_error_backtrace {|req| load req} end def test_define_class -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/