diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-06 08:29:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-06 08:29:46 +0000 |
commit | d3cde81666e0b5ff91b6c2437b8840d883f2ac3e (patch) | |
tree | 751de54e0a0e31ca089bdc33b1f1e56439c107b7 | |
parent | 24b37eb0a68bd18538d74aa421fa67d0fa5aa2b3 (diff) | |
download | ruby-d3cde81666e0b5ff91b6c2437b8840d883f2ac3e.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | load.c | 1 | ||||
-rw-r--r-- | test/ruby/test_require.rb | 20 |
3 files changed, 16 insertions, 11 deletions
@@ -1,4 +1,8 @@ -Thu Oct 6 15:53:20 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> +Thu Oct 6 17:29:44 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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. @@ -1040,6 +1040,7 @@ rb_require_safe(VALUE fname, int safe) 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) { diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 5a7d118fc4..c80a818710 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -182,24 +182,24 @@ class TestRequire < Test::Unit::TestCase 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 |