ruby-changes:44289
From: nobu <ko1@a...>
Date: Thu, 6 Oct 2016 15:53:26 +0900 (JST)
Subject: [ruby-changes:44289] nobu:r56362 (trunk): load.c: fix load/require context
nobu 2016-10-06 15:53:22 +0900 (Thu, 06 Oct 2016) New Revision: 56362 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56362 Log: load.c: fix load/require context * load.c (rb_load_internal0): load/require is not the main script. Modified files: trunk/ChangeLog trunk/load.c trunk/test/ruby/test_require.rb Index: load.c =================================================================== --- load.c (revision 56361) +++ load.c (revision 56362) @@ -610,7 +610,7 @@ rb_load_internal0(rb_thread_t *th, VALUE https://github.com/ruby/ruby/blob/trunk/load.c#L610 } 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("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), NULL); } Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 56361) +++ test/ruby/test_require.rb (revision 56362) @@ -182,6 +182,26 @@ 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 + 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" Index: ChangeLog =================================================================== --- ChangeLog (revision 56361) +++ ChangeLog (revision 56362) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 6 15:53:20 2016 Nobuyoshi Nakada <nobu@r...> + + * load.c (rb_load_internal0): load/require is not the main + script. + Thu Oct 6 13:35:15 2016 Marc-Andre Lafortune <ruby-core@m...> * enum.c: [DOC] Improve doc [ci-skip] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/