diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-04-22 21:23:14 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-06-05 07:32:42 +0900 |
commit | 709d58446f5f059a7808d2dcb6bd839f0238f04a (patch) | |
tree | ff78a4ed54e65f1ac0d270eee7378c9c768dadf6 | |
parent | 5c1957e95c649659b0e5abb184393c4c7ee34cd7 (diff) |
[rubygems/rubygems] Clarify what test_activate_via_require_respects_loaded_files does and tests
* Clearly require the benchmark stdlib instead of far away in test_case.rb
https://github.com/rubygems/rubygems/commit/d74b9ca04c
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3184
-rw-r--r-- | test/rubygems/test_require.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index 43765abef2..e61fb41d1b 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -259,20 +259,33 @@ class TestGemRequire < Gem::TestCase $LOAD_PATH.push lib_dir end + require 'benchmark' # the stdlib + a1 = util_spec "a", "1", {"b" => ">= 1"}, "lib/test_gem_require_a.rb" b1 = util_spec "b", "1", nil, "lib/benchmark.rb" b2 = util_spec "b", "2", nil, "lib/benchmark.rb" install_specs b1, b2, a1 + # Activates a-1, but not b-1 and b-2 assert_require 'test_gem_require_a' + assert $LOAD_PATH.include? a1.load_paths[0] + refute $LOAD_PATH.include? b1.load_paths[0] + refute $LOAD_PATH.include? b2.load_paths[0] + assert_equal unresolved_names, ["b (>= 1)"] - refute require('benchmark'), "benchmark should have already been loaded" + # The require('benchmark') below will activate b-2. However, its + # lib/benchmark.rb won't ever be loaded. The reason is MRI sees that even + # though b-2 is earlier in $LOAD_PATH it already loaded a benchmark.rb file + # and that still exists in $LOAD_PATH (further down), + # and as a result #gem_original_require returns false. + refute require('benchmark'), "the benchmark stdlib should be recognized as already loaded" + assert $LOAD_PATH.include? b2.load_paths[0] # We detected that we should activate b-2, so we did so, but - # then original_require decided "I've already got benchmark.rb" loaded. - # This case is fine because our lazy loading is provided exactly + # then #gem_original_require decided "I've already got some benchmark.rb" loaded. + # This case is fine because our lazy loading provided exactly # the same behavior as eager loading would have. assert_equal %w[a-1 b-2], loaded_spec_names |