[前][次][番号順一覧][スレッド一覧]

ruby-changes:61552

From: Benoit <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:34 +0900 (JST)
Subject: [ruby-changes:61552] 709d58446f (master): [rubygems/rubygems] Clarify what test_activate_via_require_respects_loaded_files does and tests

https://git.ruby-lang.org/ruby.git/commit/?id=709d58446f

From 709d58446f5f059a7808d2dcb6bd839f0238f04a Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Wed, 22 Apr 2020 21:23:14 +0200
Subject: [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

diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index 43765ab..e61fb41 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -259,20 +259,33 @@ class TestGemRequire < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L259
       $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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]