summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-10-18 08:50:10 -0700
committerJeremy Evans <code@jeremyevans.net>2021-11-17 22:43:40 -0800
commitb35b7a1ef25347735a6bb7c28ab7e77afea1d856 (patch)
tree0e9ca22419d4798df525c3d81d9d7ded1291cffb /test/ruby
parent05a3dc1a654c5e92200d994d0a51a2e159c88162 (diff)
Allow Kernel#load to load code into a specified module
Instead of always using a new anonymous module for Kernel#load if the wrap argument is not false/nil, use the given module if a module is provided. Implements [Feature #6210]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4986
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_require.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 7a9faf18f9..77cdae64d9 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -367,6 +367,38 @@ class TestRequire < Test::Unit::TestCase
}
end
+ def test_load_into_module
+ Tempfile.create(["test_ruby_test_require", ".rb"]) {|t|
+ t.puts "def b; 1 end"
+ t.puts "class Foo"
+ t.puts " def c; 2 end"
+ t.puts "end"
+ t.close
+
+ m = Module.new
+ load(t.path, m)
+ assert_equal([:b], m.private_instance_methods(false))
+ c = Class.new do
+ include m
+ public :b
+ end
+ assert_equal(1, c.new.b)
+ assert_equal(2, m::Foo.new.c)
+ }
+ end
+
+ def test_load_wrap_nil
+ Dir.mktmpdir do |tmp|
+ File.write("#{tmp}/1.rb", "class LoadWrapNil; end\n")
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ path = ""#{tmp.dump}"/1.rb"
+ begin;
+ load path, nil
+ assert_instance_of(Class, LoadWrapNil)
+ end;
+ end
+ end
+
def test_load_ospath
bug = '[ruby-list:49994] path in ospath'
base = "test_load\u{3042 3044 3046 3048 304a}".encode(Encoding::Windows_31J)