summaryrefslogtreecommitdiff
path: root/test/ruby/test_require.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-14 00:57:05 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-16 18:48:20 +0900
commitddb32e66160ab50849419ef7c7ac584913b79c34 (patch)
treeea29fbe31a05b3651e3a4b41dd07c64c5ff62b9c /test/ruby/test_require.rb
parent5f1385bec0b6cfddbd51fc867ee6dcff2122399b (diff)
[Bug #18173] Update loaded_features_index
If $LOADED_FEATURES is changed in the just required file, also the index table needs to be updated before loaded_features_snapshot is reset. If the snapshot is reset without updating the table, the name of the added feature will not be found.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4849
Diffstat (limited to 'test/ruby/test_require.rb')
-rw-r--r--test/ruby/test_require.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 4ef08f8b48..401b274ef6 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -839,6 +839,23 @@ class TestRequire < Test::Unit::TestCase
}
end
+ def test_provide_in_required_file
+ paths, loaded = $:.dup, $".dup
+ Dir.mktmpdir do |tmp|
+ provide = File.realdirpath("provide.rb", tmp)
+ File.write(File.join(tmp, "target.rb"), "raise __FILE__\n")
+ File.write(provide, '$" << '"'target.rb'\n")
+ $:.replace([tmp])
+ assert(require("provide"))
+ assert(!require("target"))
+ assert_equal($".pop, provide)
+ assert_equal($".pop, "target.rb")
+ end
+ ensure
+ $:.replace(paths)
+ $".replace(loaded)
+ end
+
if defined?($LOAD_PATH.resolve_feature_path)
def test_resolve_feature_path
paths, loaded = $:.dup, $".dup