From 2644742060e37e57279914237c0241c28d555773 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 6 Oct 2016 06:53:22 +0000 Subject: load.c: fix load/require context * load.c (rb_load_internal0): load/require is not the main script. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ load.c | 2 +- test/ruby/test_require.rb | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 475c1c7930..0b4e88c3fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Oct 6 15:53:20 2016 Nobuyoshi Nakada + + * load.c (rb_load_internal0): load/require is not the main + script. + Thu Oct 6 13:35:15 2016 Marc-Andre Lafortune * enum.c: [DOC] Improve doc [ci-skip] diff --git a/load.c b/load.c index 1ccd23878c..82bf07c306 100644 --- a/load.c +++ b/load.c @@ -610,7 +610,7 @@ rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap) } else { VALUE parser = rb_parser_new(); - rb_parser_set_context(parser, NULL, TRUE); + rb_parser_set_context(parser, NULL, FALSE); node = (NODE *)rb_parser_load_file(parser, fname); iseq = rb_iseq_new_top(node, rb_str_new2(""), fname, rb_realpath_internal(Qnil, fname, 1), NULL); } diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 818db4b6d3..5a7d118fc4 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -182,6 +182,26 @@ class TestRequire < Test::Unit::TestCase end end + def test_require_syntax_error + Dir.mktmpdir do |tmp| + req = File.join(tmp, "test.rb") + File.write(req, "'\n") + assert_raise_with_message(SyntaxError, /unterminated/) { + require req + } + end + 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 + end + def test_define_class begin require "socket" -- cgit v1.2.3