diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-08-18 19:37:11 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-08-19 15:46:40 +0900 |
commit | 37f824377fce1bb0fb3ae94f858e2b9417b67b56 (patch) | |
tree | 262faa7f44212747afc4b694b0c67165d3f288ca | |
parent | 41a28637807bef9b15c404c93a778aaa6266ace7 (diff) |
Merge RubyGems 3.2.26 and Bundler 2.2.26
39 files changed, 475 insertions, 282 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index f054a2bfed..294b07d555 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -73,14 +73,6 @@ module Bundler Bundler.ui = UI::Shell.new(options) Bundler.ui.level = "debug" if options["verbose"] unprinted_warnings.each {|w| Bundler.ui.warn(w) } - - if ENV["RUBYGEMS_GEMDEPS"] && !ENV["RUBYGEMS_GEMDEPS"].empty? - Bundler.ui.warn( - "The RUBYGEMS_GEMDEPS environment variable is set. This enables RubyGems' " \ - "experimental Gemfile mode, which may conflict with Bundler and cause unexpected errors. " \ - "To remove this warning, unset RUBYGEMS_GEMDEPS.", :wrap => true - ) - end end check_unknown_options!(:except => [:config, :exec]) @@ -469,7 +461,7 @@ module Bundler map aliases_for("cache") desc "exec [OPTIONS]", "Run the command in context of the bundle" - method_option :keep_file_descriptors, :type => :boolean, :default => false + method_option :keep_file_descriptors, :type => :boolean, :default => true method_option :gemfile, :type => :string, :required => false long_desc <<-D Exec runs a command, providing it access to the gems in the bundle. While using @@ -477,6 +469,10 @@ module Bundler into the system wide RubyGems repository. D def exec(*args) + if ARGV.include?("--no-keep-file-descriptors") + SharedHelpers.major_deprecation(2, "The `--no-keep-file-descriptors` has been deprecated. `bundle exec` no longer mess with your file descriptors. Close them in the exec'd script if you need to") + end + require_relative "cli/exec" Exec.new(options, args).run end diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index 65c51337d2..4221fc7f2b 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -15,7 +15,7 @@ module Bundler definition.validate_runtime! begin - definition.resolve_only_locally! + definition.resolve_with_cache! not_installed = definition.missing_specs rescue GemNotFound, VersionConflict Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies." diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 318d57fb06..42b602a055 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -12,12 +12,7 @@ module Bundler @options = options @cmd = args.shift @args = args - - if !Bundler.current_ruby.jruby? - @args << { :close_others => !options.keep_file_descriptors? } - elsif options.keep_file_descriptors? - Bundler.ui.warn "Ruby version #{RUBY_VERSION} defaults to keeping non-standard file descriptors on Kernel#exec." - end + @args << { :close_others => !options.keep_file_descriptors? } unless Bundler.current_ruby.jruby? end def run diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index eb1119859c..b3bb025b89 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -184,14 +184,15 @@ module Bundler ) end - if File.exist?(target) && !File.directory?(target) + if target.exist? && !target.directory? Bundler.ui.error "Couldn't create a new gem named `#{gem_name}` because there's an existing file named `#{gem_name}`." exit Bundler::BundlerError.all_errors[Bundler::GenericSystemCallError] end if use_git Bundler.ui.info "Initializing git repo in #{target}" - `git init #{target}` + require "shellwords" + `git init #{target.to_s.shellescape}` config[:git_default_branch] = File.read("#{target}/.git/HEAD").split("/").last.chomp end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index f987d85f5b..673bf37698 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -161,12 +161,6 @@ module Bundler @multisource_allowed end - def resolve_only_locally! - @remote = false - sources.local_only! - resolve - end - def resolve_with_cache! sources.cached! resolve @@ -505,7 +499,7 @@ module Bundler end def precompute_source_requirements_for_indirect_dependencies? - sources.non_global_rubygems_sources.all?(&:dependency_api_available?) && !sources.aggregate_global_source? + @remote && sources.non_global_rubygems_sources.all?(&:dependency_api_available?) && !sources.aggregate_global_source? end def current_ruby_platform_locked? diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 3517a109ed..ed7b3e2d6b 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -457,7 +457,7 @@ repo_name ||= user_name def implicit_global_source_warning Bundler::SharedHelpers.major_deprecation 2, "This Gemfile does not include an explicit global source. " \ "Not using an explicit global source may result in a different lockfile being generated depending on " \ - "the gems you have installed locally before bundler is run." \ + "the gems you have installed locally before bundler is run. " \ "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"." end diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb index 11763b4e88..565aaeeb9d 100644 --- a/lib/bundler/errors.rb +++ b/lib/bundler/errors.rb @@ -122,7 +122,7 @@ module Bundler class VirtualProtocolError < BundlerError def message - "There was an error relating to virtualization and file access." \ + "There was an error relating to virtualization and file access. " \ "It is likely that you need to grant access to or mount some file system correctly." end diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index f16135cb48..e8494b4bcd 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -12,12 +12,13 @@ module Bundler end File.open File.join(bundler_path, "setup.rb"), "w" do |file| file.puts "require 'rbconfig'" - file.puts "ruby_engine = RUBY_ENGINE" - file.puts "ruby_version = RbConfig::CONFIG[\"ruby_version\"]" - file.puts "path = File.expand_path('..', __FILE__)" file.puts reverse_rubygems_kernel_mixin paths.each do |path| - file.puts %($:.unshift File.expand_path("\#{path}/#{path}")) + if Pathname.new(path).absolute? + file.puts %($:.unshift "#{path}") + else + file.puts %($:.unshift File.expand_path("\#{__dir__}/#{path}")) + end end end end @@ -28,14 +29,14 @@ module Bundler @specs.map do |spec| next if spec.name == "bundler" Array(spec.require_paths).map do |path| - gem_path(path, spec).sub(version_dir, '#{ruby_engine}/#{ruby_version}') + gem_path(path, spec).sub(version_dir, '#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}') # This is a static string intentionally. It's interpolated at a later time. end - end.flatten + end.flatten.compact end def version_dir - "#{Bundler::RubyVersion.system.engine}/#{RbConfig::CONFIG["ruby_version"]}" + "#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}" end def bundler_path @@ -44,7 +45,11 @@ module Bundler def gem_path(path, spec) full_path = Pathname.new(path).absolute? ? path : File.join(spec.full_gem_path, path) - Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s + if spec.source.instance_of?(Source::Path) + full_path + else + Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s + end rescue TypeError error_message = "#{spec.name} #{spec.version} has an invalid gemspec" raise Gem::InvalidSpecificationException.new(error_message) diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index a78b2db157..d26e2feb10 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -255,12 +255,6 @@ module Bundler next if name == "bundler" next unless search_for(requirement).empty? - cache_message = begin - " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist? - rescue GemfileNotFound - nil - end - if (base = @base[name]) && !base.empty? version = base.first.version message = "You have requested:\n" \ @@ -269,18 +263,17 @@ module Bundler "Try running `bundle update #{name}`\n\n" \ "If you are updating multiple gems in your Gemfile at once,\n" \ "try passing them all to `bundle update`" - elsif source = @source_requirements[name] + else + source = source_for(name) specs = source.specs.search(name) versions_with_platforms = specs.map {|s| [s.version, s.platform] } - message = String.new("Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in #{source}#{cache_message}.\n") - message << if versions_with_platforms.any? - "The source contains the following versions of '#{name}': #{formatted_versions_with_platforms(versions_with_platforms)}" - else - "The source does not contain any versions of '#{name}'" - end - else - message = "Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in any of the gem sources " \ - "listed in your Gemfile#{cache_message}." + cache_message = begin + " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist? + rescue GemfileNotFound + nil + end + message = String.new("Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in #{source.to_err}#{cache_message}.\n") + message << "The source contains the following versions of '#{name}': #{formatted_versions_with_platforms(versions_with_platforms)}" if versions_with_platforms.any? end raise GemNotFound, message end @@ -378,7 +371,7 @@ module Bundler o << if metadata_requirement "is not available in #{relevant_source}" else - "in #{relevant_source}.\n" + "in #{relevant_source.to_err}.\n" end end end, diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 03126f616c..abf7db21b4 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -430,6 +430,8 @@ module Bundler Pathname.new(ENV["BUNDLE_CONFIG"]) elsif ENV["BUNDLE_USER_CONFIG"] && !ENV["BUNDLE_USER_CONFIG"].empty? Pathname.new(ENV["BUNDLE_USER_CONFIG"]) + elsif ENV["BUNDLE_USER_HOME"] && !ENV["BUNDLE_USER_HOME"].empty? + Pathname.new(ENV["BUNDLE_USER_HOME"]).join("config") elsif Bundler.rubygems.user_home && !Bundler.rubygems.user_home.empty? Pathname.new(Bundler.rubygems.user_home).join(".bundle/config") end diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 5388a7681e..7bf493d73d 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -36,8 +36,6 @@ module Bundler def local!; end - def local_only!; end - def cached!; end def remote!; end @@ -67,6 +65,10 @@ module Bundler "#<#{self.class}:0x#{object_id} #{self}>" end + def to_err + to_s + end + def path? instance_of?(Bundler::Source::Path) end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 858a69a48b..298ff98e24 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -26,12 +26,6 @@ module Bundler Array(options["remotes"]).reverse_each {|r| add_remote(r) } end - def local_only! - @specs = nil - @allow_local = true - @allow_remote = false - end - def local! return if @allow_local @@ -50,6 +44,7 @@ module Bundler return if @allow_cached @specs = nil + @allow_local = true @allow_cached = true end @@ -96,11 +91,22 @@ module Bundler out << " specs:\n" end + def to_err + if remotes.empty? + "locally installed gems" + elsif @allow_remote + "rubygems repository #{remote_names} or installed locally" + elsif @allow_cached + "cached gems from rubygems repository #{remote_names} or installed locally" + else + "locally installed gems" + end + end + def to_s if remotes.empty? "locally installed gems" else - remote_names = remotes.map(&:to_s).join(", ") "rubygems repository #{remote_names} or installed locally" end end @@ -319,6 +325,10 @@ module Bundler protected + def remote_names + remotes.map(&:to_s).join(", ") + end + def credless_remotes remotes.map(&method(:suppress_configured_credentials)) end diff --git a/lib/bundler/source/rubygems_aggregate.rb b/lib/bundler/source/rubygems_aggregate.rb index 685bf7e90a..09cf4002ea 100644 --- a/lib/bundler/source/rubygems_aggregate.rb +++ b/lib/bundler/source/rubygems_aggregate.rb @@ -16,6 +16,10 @@ module Bundler @index end + def to_err + to_s + end + def to_s "any of the sources" end diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index d6310b78c0..b97206f497 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -136,10 +136,6 @@ module Bundler different_sources?(lock_sources, replacement_sources) end - def local_only! - all_sources.each(&:local_only!) - end - def cached! all_sources.each(&:cached!) end diff --git a/lib/bundler/templates/newgem/github/workflows/main.yml.tt b/lib/bundler/templates/newgem/github/workflows/main.yml.tt index 654978033f..83ddea25dc 100644 --- a/lib/bundler/templates/newgem/github/workflows/main.yml.tt +++ b/lib/bundler/templates/newgem/github/workflows/main.yml.tt @@ -1,16 +1,26 @@ name: Ruby -on: [push,pull_request] +on: + push: + - <%= config[:git_default_branch] %> + + pull_request: jobs: build: runs-on: ubuntu-latest + + strategy: + matrix: + ruby: + - <%= RUBY_VERSION %> + steps: - uses: actions/checkout@v2 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: <%= RUBY_VERSION %> + ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Run the default task run: bundle exec rake diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 91ce856bff..271d39dec5 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -25,7 +25,9 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } + `git ls-files -z`.split("\x0").reject do |f| + (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) + end end spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 4447aa401e..510953c543 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.2.25".freeze + VERSION = "2.2.26".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 900f98542e..8f46264d93 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -8,7 +8,7 @@ require 'rbconfig' module Gem - VERSION = "3.2.25".freeze + VERSION = "3.2.26".freeze end # Must be first since it unloads the prelude from 1.9.2 @@ -249,9 +249,6 @@ module Gem # you to specify specific gem versions. def self.bin_path(name, exec_name = nil, *requirements) - # TODO: fails test_self_bin_path_bin_file_gone_in_latest - # Gem::Specification.find_by_name(name, *requirements).bin_file exec_name - requirements = Gem::Requirement.default if requirements.empty? @@ -1053,7 +1050,9 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Find rubygems plugin files in the standard location and load them def self.load_plugins - load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir) + Gem.path.each do |gem_path| + load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir(gem_path)) + end end ## @@ -1112,26 +1111,21 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path) require 'rubygems/user_interaction' - Gem::DefaultUserInteraction.use_ui(ui) do - require "bundler" - begin - Bundler.ui.silence do - @gemdeps = Bundler.setup + require "bundler" + begin + Gem::DefaultUserInteraction.use_ui(ui) do + begin + Bundler.ui.silence do + @gemdeps = Bundler.setup + end + ensure + Gem::DefaultUserInteraction.ui.close end - ensure - Gem::DefaultUserInteraction.ui.close end - @gemdeps.requested_specs.map(&:to_spec).sort_by(&:name) - end - - rescue => e - case e - when Gem::LoadError, Gem::UnsatisfiableDependencyError, (defined?(Bundler::GemNotFound) ? Bundler::GemNotFound : Gem::LoadError) + rescue Bundler::BundlerError => e warn e.message - warn "You may need to `gem install -g` to install missing gems" + warn "You may need to `bundle install` to install missing gems" warn "" - else - raise end end @@ -1337,6 +1331,14 @@ begin require 'rubygems/defaults/operating_system' rescue LoadError + # Ignored +rescue StandardError => e + msg = "#{e.message}\n" \ + "Loading the rubygems/defaults/operating_system.rb file caused an error. " \ + "This file is owned by your OS, not by rubygems upstream. " \ + "Please find out which OS package this file belongs to and follow the guidelines from your OS to report " \ + "the problem and ask for help." + raise e.class, msg end begin @@ -1354,5 +1356,3 @@ Gem::Specification.load_defaults require 'rubygems/core_ext/kernel_gem' require 'rubygems/core_ext/kernel_require' require 'rubygems/core_ext/kernel_warn' - -Gem.use_gemdeps diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 8c286605e1..53c5fc7285 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -761,7 +761,7 @@ class Gem::Installer # require 'rubygems' - +#{gemdeps_load(spec.name)} version = "#{Gem::Requirement.default_prerelease}" str = ARGV.first @@ -782,6 +782,15 @@ end TEXT end + def gemdeps_load(name) + return '' if name == "bundler" + + <<-TEXT + +Gem.use_gemdeps +TEXT + end + ## # return the stub script text used to launch the true Ruby script diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index c9dd101f55..c5de12c211 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -111,22 +111,6 @@ RSpec.describe "bundle executable" do end end - context "when ENV['RUBYGEMS_GEMDEPS'] is set" do - it "displays a warning" do - gemfile bundled_app_gemfile, <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - G - - bundle :install, :env => { "RUBYGEMS_GEMDEPS" => "foo" } - expect(err).to include("RUBYGEMS_GEMDEPS") - expect(err).to include("conflict with Bundler") - - bundle :install, :env => { "RUBYGEMS_GEMDEPS" => "" } - expect(err).not_to include("RUBYGEMS_GEMDEPS") - end - end - context "with --verbose" do it "prints the running command" do gemfile "source \"#{file_uri_for(gem_repo1)}\"" diff --git a/spec/bundler/bundler/dsl_spec.rb b/spec/bundler/bundler/dsl_spec.rb index e6cd43ab59..4d14949c89 100644 --- a/spec/bundler/bundler/dsl_spec.rb +++ b/spec/bundler/bundler/dsl_spec.rb @@ -250,7 +250,7 @@ RSpec.describe Bundler::Dsl do warning = "This Gemfile does not include an explicit global source. " \ "Not using an explicit global source may result in a different lockfile being generated depending on " \ - "the gems you have installed locally before bundler is run." \ + "the gems you have installed locally before bundler is run. " \ "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"." expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, warning) diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index fb5da98bf3..c8eef55266 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -287,8 +287,6 @@ RSpec.describe "bundle binstubs <gem>" do end it "sets correct permissions for binstubs" do - skip "https://github.com/rubygems/rubygems/issues/3352" if Gem.win_platform? - with_umask(0o002) do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -297,7 +295,7 @@ RSpec.describe "bundle binstubs <gem>" do bundle "binstubs rack" binary = bundled_app("bin/rackup") - expect(File.stat(binary).mode.to_s(8)).to eq("100775") + expect(File.stat(binary).mode.to_s(8)).to eq(Gem.win_platform? ? "100644" : "100775") end end diff --git a/spec/bundler/commands/config_spec.rb b/spec/bundler/commands/config_spec.rb index 4e13a7903e..48f0ceab78 100644 --- a/spec/bundler/commands/config_spec.rb +++ b/spec/bundler/commands/config_spec.rb @@ -88,6 +88,16 @@ RSpec.describe ".bundle/config" do bundle "config get path", :env => { "BUNDLE_USER_CONFIG" => bundle_user_config } expect(out).to include("Set for the current user (#{bundle_user_config}): \"vendor\"") end + + context "when not explicitly configured, but BUNDLE_USER_HOME set" do + let(:bundle_user_home) { bundled_app(".bundle").to_s } + + it "uses the right location" do + bundle "config set path vendor", :env => { "BUNDLE_USER_HOME" => bundle_user_home } + bundle "config get path", :env => { "BUNDLE_USER_HOME" => bundle_user_home } + expect(out).to include("Set for the current user (#{bundle_user_home}/config): \"vendor\"") + end + end end describe "global" do diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb index 68c4726608..c6648f0a7a 100644 --- a/spec/bundler/commands/exec_spec.rb +++ b/spec/bundler/commands/exec_spec.rb @@ -836,7 +836,7 @@ RSpec.describe "bundle exec" do let(:exit_code) { Bundler::GemNotFound.new.status_code } let(:expected) { "" } let(:expected_err) { <<-EOS.strip } -Could not find gem 'rack (= 2)' in rubygems repository #{file_uri_for(gem_repo1)}/ or installed locally. +Could not find gem 'rack (= 2)' in locally installed gems. The source contains the following versions of 'rack': 0.9.1, 1.0.0 Run `bundle install` to install missing gems. EOS @@ -863,7 +863,7 @@ Run `bundle install` to install missing gems. let(:exit_code) { Bundler::GemNotFound.new.status_code } let(:expected) { "" } let(:expected_err) { <<-EOS.strip } -Could not find gem 'rack (= 2)' in rubygems repository #{file_uri_for(gem_repo1)}/ or installed locally. +Could not find gem 'rack (= 2)' in locally installed gems. The source contains the following versions of 'rack': 1.0.0 Run `bundle install` to install missing gems. EOS diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 412000341f..35c45b68b7 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -336,7 +336,7 @@ RSpec.describe "bundle install with gem sources" do expect(err).to include("This Gemfile does not include an explicit global source. " \ "Not using an explicit global source may result in a different lockfile being generated depending on " \ - "the gems you have installed locally before bundler is run." \ + "the gems you have installed locally before bundler is run. " \ "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\".") end @@ -759,4 +759,22 @@ RSpec.describe "bundle install with gem sources" do ) end end + + context "with --local flag" do + before do + system_gems "rack-1.0.0", :path => default_bundle_path + end + + it "respects installed gems without fetching any remote sources" do + install_gemfile <<-G, :local => true + source "#{file_uri_for(gem_repo1)}" + + source "https://not-existing-source" do + gem "rack" + end + G + + expect(last_command).to be_success + end + end end diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index 21eb6e5456..171ec1ba1d 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -86,7 +86,7 @@ RSpec.describe "bundle lock" do it "does not fetch remote specs when using the --local option" do bundle "lock --update --local", :raise_on_error => false - expect(err).to match(/installed locally/) + expect(err).to match(/locally installed gems/) end it "works with --gemfile flag" do diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index 5cdb3ed5e3..73ae721c69 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -29,36 +29,32 @@ RSpec.describe "bundle gem" do end describe "git repo initialization" do - shared_examples_for "a gem with an initial git repo" do - before do - bundle "gem #{gem_name} #{flags}" - end - - it "generates a gem skeleton with a .git folder", :readline do - gem_skeleton_assertions - expect(bundled_app("#{gem_name}/.git")).to exist - end + it "generates a gem skeleton with a .git folder", :readline do + bundle "gem #{gem_name}" + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/.git")).to exist end - context "when using the default" do - it_behaves_like "a gem with an initial git repo" do - let(:flags) { "" } - end + it "generates a gem skeleton with a .git folder when passing --git", :readline do + bundle "gem #{gem_name} --git" + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/.git")).to exist end - context "when explicitly passing --git" do - it_behaves_like "a gem with an initial git repo" do - let(:flags) { "--git" } - end + it "generates a gem skeleton without a .git folder when passing --no-git", :readline do + bundle "gem #{gem_name} --no-git" + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/.git")).not_to exist end - context "when passing --no-git", :readline do + context "on a path with spaces" do before do - bundle "gem #{gem_name} --no-git" + Dir.mkdir(bundled_app("path with spaces")) end - it "generates a gem skeleton without a .git folder" do - gem_skeleton_assertions - expect(bundled_app("#{gem_name}/.git")).not_to exist + + it "properly initializes git repo", :readline do + bundle "gem #{gem_name}", :dir => bundled_app("path with spaces") + expect(bundled_app("path with spaces/#{gem_name}/.git")).to exist end end end @@ -475,6 +471,14 @@ RSpec.describe "bundle gem" do expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/class Error < StandardError; end$/) end + it "does not include the gemspec file in files" do + bundle "gem #{gem_name}" + + bundler_gemspec = Bundler::GemHelper.new(gemspec_dir).gemspec + + expect(bundler_gemspec.files).not_to include("#{gem_name}.gemspec") + end + it "runs rake without problems" do bundle "gem #{gem_name}" diff --git a/spec/bundler/commands/post_bundle_message_spec.rb b/spec/bundler/commands/post_bundle_message_spec.rb index 72f8020b44..3050b87754 100644 --- a/spec/bundler/commands/post_bundle_message_spec.rb +++ b/spec/bundler/commands/post_bundle_message_spec.rb @@ -121,7 +121,6 @@ RSpec.describe "post bundle message" do G expect(err).to include <<-EOS.strip Could not find gem 'not-a-gem' in rubygems repository #{file_uri_for(gem_repo1)}/ or installed locally. -The source does not contain any versions of 'not-a-gem' EOS end diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index 8c225afb11..9885145662 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -347,7 +347,6 @@ RSpec.describe "bundle install with gems on multiple sources" do it "fails" do bundle :install, :artifice => "compact_index", :raise_on_error => false expect(err).to include("Could not find gem 'private_gem_1' in rubygems repository https://gem.repo2/ or installed locally.") - expect(err).to include("The source does not contain any versions of 'private_gem_1'") end end @@ -1281,7 +1280,7 @@ RSpec.describe "bundle install with gems on multiple sources" do expect(out).to include("Using example 0.1.0") end - it "fails inmmediately with a helpful error when a non retriable network error happens while resolving sources" do + it "fails inmmediately with a helpful error when a rubygems source does not exist and bundler/setup is required" do gemfile <<-G source "https://gem.repo1" @@ -1297,6 +1296,21 @@ RSpec.describe "bundle install with gems on multiple sources" do end expect(last_command).to be_failure + expect(err).to include("Could not find gem 'example' in locally installed gems.") + end + + it "fails inmmediately with a helpful error when a non retriable network error happens while resolving sources" do + gemfile <<-G + source "https://gem.repo1" + + source "https://gem.repo4" do + gem "example" + end + G + + bundle "install", :artifice => nil, :raise_on_error => false + + expect(last_command).to be_failure expect(err).to include("Could not reach host gem.repo4. Check your network connection and try again.") end diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index 6578997cd6..15ffc80e69 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -147,6 +147,36 @@ RSpec.shared_examples "bundle install --standalone" do end end + describe "with Gemfiles using path sources and resulting bundle moved to a folder hierarchy with different nesting" do + before do + build_lib "minitest", "1.0.0", :path => lib_path("minitest") + + Dir.mkdir bundled_app("app") + + gemfile bundled_app("app/Gemfile"), <<-G + source "#{file_uri_for(gem_repo1)}" + gem "minitest", :path => "#{lib_path("minitest")}" + G + + bundle "install", :standalone => true, :dir => bundled_app("app") + + Dir.mkdir tmp("one_more_level") + FileUtils.mv bundled_app, tmp("one_more_level") + end + + it "also works" do + ruby <<-RUBY, :dir => tmp("one_more_level/bundled_app/app") + require "./bundle/bundler/setup" + + require "minitest" + puts MINITEST + RUBY + + expect(out).to eq("1.0.0") + expect(err).to be_empty + end + end + describe "with gems with native extension", :ruby_repo do before do bundle "config set --local path #{bundled_app("bundle")}" @@ -159,7 +189,7 @@ RSpec.shared_examples "bundle install --standalone" do it "generates a bundle/bundler/setup.rb with the proper paths" do expected_path = bundled_app("bundle/bundler/setup.rb") extension_line = File.read(expected_path).each_line.find {|line| line.include? "/extensions/" }.strip - expect(extension_line).to start_with '$:.unshift File.expand_path("#{path}/../#{ruby_engine}/#{ruby_version}/extensions/' + expect(extension_line).to start_with '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}/extensions/' expect(extension_line).to end_with '/very_simple_binary-1.0")' end end diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index 459d777a8b..f97eefeef8 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -92,6 +92,18 @@ RSpec.describe "major deprecations" do end end + describe "bundle exec --no-keep-file-descriptors" do + before do + bundle "exec --no-keep-file-descriptors -e 1", :raise_on_error => false + end + + it "is deprecated", :bundler => "< 3" do + expect(deprecations).to include "The `--no-keep-file-descriptors` has been deprecated. `bundle exec` no longer mess with your file descriptors. Close them in the exec'd script if you need to" + end + + pending "is removed and shows a helpful error message about it", :bundler => "3" + end + describe "bundle update --quiet" do it "does not print any deprecations" do bundle :update, :quiet => true, :raise_on_error => false diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index 80b0ccff4d..4d558b9907 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -73,6 +73,7 @@ RSpec.configure do |config| Spec::Rubygems.test_setup ENV["BUNDLE_SPEC_RUN"] = "true" ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil + ENV["RUBYGEMS_GEMDEPS"] = nil ENV["XDG_CONFIG_HOME"] = nil ENV["GEMRC"] = nil diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb index bf4300edb2..91dd699b5f 100644 --- a/spec/bundler/support/indexes.rb +++ b/spec/bundler/support/indexes.rb @@ -17,7 +17,7 @@ module Spec def resolve(args = []) @platforms ||= ["ruby"] deps = [] - default_source = instance_double("Bundler::Source::Rubygems", :specs => @index) + default_source = instance_double("Bundler::Source::Rubygems", :specs => @index, :to_err => "locally install gems") source_requirements = { :default => default_source } @deps.each do |d| source_requirements[d.name] = d.source = default_source diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index c3befb535f..fd2763db41 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -1297,7 +1297,11 @@ Also, a list: end def ruby_with_rubygems_in_load_path - [Gem.ruby, "-I", File.expand_path("../../lib", __dir__)] + [Gem.ruby, "-I", rubygems_path] + end + + def rubygems_path + $LOAD_PATH.find{|p| p == File.dirname($LOADED_FEATURES.find{|f| f.end_with?("/rubygems.rb") }) } end def with_clean_path_to_ruby diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 79ea89e2fa..da154dac75 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -19,7 +19,6 @@ class TestGem < Gem::TestCase common_installer_setup - ENV.delete 'RUBYGEMS_GEMDEPS' @additional = %w[a b].map {|d| File.join @tempdir, d } util_remove_interrupt_command @@ -540,7 +539,6 @@ class TestGem < Gem::TestCase s.executables = [] end install_specs spec - # Should not find a-10's non-abin (bug) assert_equal @abin_path, Gem.bin_path('a', 'abin') end @@ -664,22 +662,22 @@ class TestGem < Gem::TestCase end def test_self_use_gemdeps - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-' + with_rubygems_gemdeps('-') do + FileUtils.mkdir_p 'detect/a/b' + FileUtils.mkdir_p 'detect/a/Isolate' - FileUtils.mkdir_p 'detect/a/b' - FileUtils.mkdir_p 'detect/a/Isolate' + FileUtils.touch 'detect/Isolate' - FileUtils.touch 'detect/Isolate' + begin + Dir.chdir 'detect/a/b' - begin - Dir.chdir 'detect/a/b' + Gem.use_gemdeps - assert_equal add_bundler_full_name([]), Gem.use_gemdeps.map(&:full_name) - ensure - Dir.chdir @tempdir + assert_equal add_bundler_full_name([]), loaded_spec_names + ensure + Dir.chdir @tempdir + end end - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps end def test_self_dir @@ -1580,6 +1578,31 @@ class TestGem < Gem::TestCase assert_equal %w[plugin], PLUGINS_LOADED end + def test_load_user_installed_plugins + plugin_path = File.join "lib", "rubygems_plugin.rb" + + Dir.chdir @tempdir do + FileUtils.mkdir_p 'lib' + File.open plugin_path, "w" do |fp| + fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end" + end + + foo = util_spec 'foo', '1' do |s| + s.files << plugin_path + end + + install_gem_user foo + end + + Gem.paths = { "GEM_PATH" => [Gem.dir, Gem.user_dir].join(File::PATH_SEPARATOR) } + + gem 'foo' + + Gem.load_plugins + + assert_equal %w[plugin], PLUGINS_LOADED + end + def test_load_env_plugins with_plugin('load') { Gem.load_env_plugins } assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil @@ -1689,11 +1712,11 @@ class TestGem < Gem::TestCase f.puts "gem 'c'" end - ENV['RUBYGEMS_GEMDEPS'] = path - - Gem.use_gemdeps + with_rubygems_gemdeps(path) do + Gem.use_gemdeps - assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names + assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names + end end def test_auto_activation_of_used_gemdeps_file @@ -1711,10 +1734,13 @@ class TestGem < Gem::TestCase f.puts "gem 'c'" end - ENV['RUBYGEMS_GEMDEPS'] = "-" + with_rubygems_gemdeps("-") do + expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name) + + Gem.use_gemdeps - expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact - assert_equal expected_specs, Gem.use_gemdeps.sort_by {|s| s.name } + assert_equal expected_specs, loaded_spec_names + end end BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) } @@ -1726,10 +1752,18 @@ class TestGem < Gem::TestCase names end - def test_looks_for_gemdeps_files_automatically_on_start + def test_looks_for_gemdeps_files_automatically_from_binstubs pend "Requiring bundler messes things up" if Gem.java_platform? - a = util_spec "a", "1", nil, "lib/a.rb" + a = util_spec "a", "1" do |s| + s.executables = %w[foo] + s.bindir = "exe" + end + + write_file File.join(@tempdir, 'exe', 'foo') do |fp| + fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort" + end + b = util_spec "b", "1", nil, "lib/b.rb" c = util_spec "c", "1", nil, "lib/c.rb" @@ -1741,31 +1775,44 @@ class TestGem < Gem::TestCase install_gem c, :install_dir => path ENV['GEM_PATH'] = path - ENV['RUBYGEMS_GEMDEPS'] = "-" - path = File.join @tempdir, "gem.deps.rb" - cmd = [*ruby_with_rubygems_in_load_path, - "-I#{BUNDLER_LIB_PATH}"] - cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort" + with_rubygems_gemdeps("-") do + new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) + new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}" - File.open path, "w" do |f| - f.puts "gem 'a'" - end - out0 = IO.popen(cmd, &:read).split(/\n/) + path = File.join @tempdir, "gem.deps.rb" - File.open path, "a" do |f| - f.puts "gem 'b'" - f.puts "gem 'c'" - end - out = IO.popen(cmd, &:read).split(/\n/) + File.open path, "w" do |f| + f.puts "gem 'a'" + end + out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do + IO.popen("foo", &:read).split(/\n/) + end + + File.open path, "a" do |f| + f.puts "gem 'b'" + f.puts "gem 'c'" + end + out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do + IO.popen("foo", &:read).split(/\n/) + end - assert_equal ["b-1", "c-1"], out - out0 + assert_equal ["b-1", "c-1"], out - out0 + end end - def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir + def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir pend "Requiring bundler messes things up" if Gem.java_platform? - a = util_spec "a", "1", nil, "lib/a.rb" + a = util_spec "a", "1" do |s| + s.executables = %w[foo] + s.bindir = "exe" + end + + write_file File.join(@tempdir, 'exe', 'foo') do |fp| + fp.puts "puts Gem.loaded_specs.values.map(&:full_name).sort" + end + b = util_spec "b", "1", nil, "lib/b.rb" c = util_spec "c", "1", nil, "lib/c.rb" @@ -1777,29 +1824,34 @@ class TestGem < Gem::TestCase install_gem c, :install_dir => path ENV['GEM_PATH'] = path - ENV['RUBYGEMS_GEMDEPS'] = "-" - Dir.mkdir "sub1" + with_rubygems_gemdeps("-") do + Dir.mkdir "sub1" - path = File.join @tempdir, "gem.deps.rb" - cmd = [*ruby_with_rubygems_in_load_path, "-Csub1", - "-I#{BUNDLER_LIB_PATH}"] - cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort" + new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) + new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}" - File.open path, "w" do |f| - f.puts "gem 'a'" - end - out0 = IO.popen(cmd, &:read).split(/\n/) + path = File.join @tempdir, "gem.deps.rb" - File.open path, "a" do |f| - f.puts "gem 'b'" - f.puts "gem 'c'" - end - out = IO.popen(cmd, &:read).split(/\n/) + File.open path, "w" do |f| + f.puts "gem 'a'" + end + out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do + IO.popen("foo", :chdir => "sub1", &:read).split(/\n/) + end + + File.open path, "a" do |f| + f.puts "gem 'b'" + f.puts "gem 'c'" + end + out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do + IO.popen("foo", :chdir => "sub1", &:read).split(/\n/) + end - Dir.rmdir "sub1" + Dir.rmdir "sub1" - assert_equal ["b-1", "c-1"], out - out0 + assert_equal ["b-1", "c-1"], out - out0 + end end def test_register_default_spec @@ -1863,21 +1915,19 @@ class TestGem < Gem::TestCase end def test_use_gemdeps_ENV - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil - - spec = util_spec 'a', 1 + with_rubygems_gemdeps(nil) do + spec = util_spec 'a', 1 - refute spec.activated? + refute spec.activated? - File.open 'gem.deps.rb', 'w' do |io| - io.write 'gem "a"' - end + File.open 'gem.deps.rb', 'w' do |io| + io.write 'gem "a"' + end - Gem.use_gemdeps + Gem.use_gemdeps - refute spec.activated? - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps + refute spec.activated? + end end def test_use_gemdeps_argument_missing @@ -1890,110 +1940,96 @@ class TestGem < Gem::TestCase end def test_use_gemdeps_argument_missing_match_ENV - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = - ENV['RUBYGEMS_GEMDEPS'], 'gem.deps.rb' + with_rubygems_gemdeps('gem.deps.rb') do + e = assert_raise ArgumentError do + Gem.use_gemdeps 'gem.deps.rb' + end - e = assert_raise ArgumentError do - Gem.use_gemdeps 'gem.deps.rb' + assert_equal 'Unable to find gem dependencies file at gem.deps.rb', + e.message end - - assert_equal 'Unable to find gem dependencies file at gem.deps.rb', - e.message - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps end def test_use_gemdeps_automatic - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-' - - spec = util_spec 'a', 1 - install_specs spec - spec = Gem::Specification.find {|s| s == spec } + with_rubygems_gemdeps('-') do + spec = util_spec 'a', 1 + install_specs spec + spec = Gem::Specification.find {|s| s == spec } - refute spec.activated? + refute spec.activated? - File.open 'Gemfile', 'w' do |io| - io.write 'gem "a"' - end + File.open 'Gemfile', 'w' do |io| + io.write 'gem "a"' + end - Gem.use_gemdeps + Gem.use_gemdeps - assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps + assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names + end end def test_use_gemdeps_automatic_missing - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-' + with_rubygems_gemdeps('-') do + Gem.use_gemdeps - Gem.use_gemdeps - - assert true # count - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps + assert true # count + end end def test_use_gemdeps_disabled - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '' + with_rubygems_gemdeps('') do + spec = util_spec 'a', 1 - spec = util_spec 'a', 1 + refute spec.activated? - refute spec.activated? - - File.open 'gem.deps.rb', 'w' do |io| - io.write 'gem "a"' - end + File.open 'gem.deps.rb', 'w' do |io| + io.write 'gem "a"' + end - Gem.use_gemdeps + Gem.use_gemdeps - refute spec.activated? - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps + refute spec.activated? + end end def test_use_gemdeps_missing_gem - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x' - - File.open 'x', 'w' do |io| - io.write 'gem "a"' - end + with_rubygems_gemdeps('x') do + File.open 'x', 'w' do |io| + io.write 'gem "a"' + end - expected = <<-EXPECTED + expected = <<-EXPECTED Could not find gem 'a' in locally installed gems. -The source does not contain any versions of 'a' -You may need to `gem install -g` to install missing gems +You may need to `bundle install` to install missing gems - EXPECTED + EXPECTED - Gem::Deprecate.skip_during do - actual_stdout, actual_stderr = capture_output do - Gem.use_gemdeps + Gem::Deprecate.skip_during do + actual_stdout, actual_stderr = capture_output do + Gem.use_gemdeps + end + assert_empty actual_stdout + assert_equal(expected, actual_stderr) end - assert_empty actual_stdout - assert_equal(expected, actual_stderr) end - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps end def test_use_gemdeps_specific - rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x' + with_rubygems_gemdeps('x') do + spec = util_spec 'a', 1 + install_specs spec - spec = util_spec 'a', 1 - install_specs spec - - spec = Gem::Specification.find {|s| s == spec } - refute spec.activated? + spec = Gem::Specification.find {|s| s == spec } + refute spec.activated? - File.open 'x', 'w' do |io| - io.write 'gem "a"' - end + File.open 'x', 'w' do |io| + io.write 'gem "a"' + end - Gem.use_gemdeps + Gem.use_gemdeps - assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names - ensure - ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps + assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names + end end def test_operating_system_defaults @@ -2111,4 +2147,22 @@ You may need to `gem install -g` to install missing gems def util_cache_dir File.join Gem.dir, "cache" end + + def with_path_and_rubyopt(path_value, rubyopt_value) + path, ENV['PATH'] = ENV['PATH'], path_value + rubyopt, ENV['RUBYOPT'] = ENV['RUBYOPT'], rubyopt_value + + yield + ensure + ENV['PATH'] = path + ENV['RUBYOPT'] = rubyopt + end + + def with_rubygems_gemdeps(value) + rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], value + + yield + ensure + ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps + end end diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index a2b390d639..988f14146d 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -33,6 +33,8 @@ class TestGemInstaller < Gem::InstallerTestCase require 'rubygems' +Gem.use_gemdeps + version = \">= 0.a\" str = ARGV.first diff --git a/test/rubygems/test_rubygems.rb b/test/rubygems/test_rubygems.rb new file mode 100644 index 0000000000..493b9fdf4a --- /dev/null +++ b/test/rubygems/test_rubygems.rb @@ -0,0 +1,44 @@ +require_relative 'helper' + +class GemTest < Gem::TestCase + def test_rubygems_normal_behaviour + _ = Gem::Util.popen(*ruby_with_rubygems_in_load_path, '-e', "'require \"rubygems\"'", {:err => [:child, :out]}).strip + assert $?.success? + end + + def test_operating_system_other_exceptions + pend "does not apply to truffleruby" if RUBY_ENGINE == 'truffleruby' + + path = util_install_operating_system_rb <<-RUBY + intentionally_not_implemented_method + RUBY + + output = Gem::Util.popen(*ruby_with_rubygems_and_fake_operating_system_in_load_path(path), '-e', "'require \"rubygems\"'", {:err => [:child, :out]}).strip + assert !$?.success? + assert_includes output, "undefined local variable or method `intentionally_not_implemented_method'" + assert_includes output, "Loading the rubygems/defaults/operating_system.rb file caused an error. " \ + "This file is owned by your OS, not by rubygems upstream. " \ + "Please find out which OS package this file belongs to and follow the guidelines from your OS to report " \ + "the problem and ask for help." + end + + private + + def util_install_operating_system_rb(content) + dir_lib = Dir.mktmpdir("test_operating_system_lib", @tempdir) + dir_lib_arg = File.join dir_lib + + dir_lib_rubygems_defaults_arg = File.join dir_lib_arg, "lib", "rubygems", "defaults" + FileUtils.mkdir_p dir_lib_rubygems_defaults_arg + + operating_system_rb = File.join dir_lib_rubygems_defaults_arg, "operating_system.rb" + + File.open(operating_system_rb, 'w') {|f| f.write content } + + File.join dir_lib_arg, "lib" + end + + def ruby_with_rubygems_and_fake_operating_system_in_load_path(operating_system_path) + [Gem.ruby, "-I", operating_system_path, "-I" , $LOAD_PATH.find{|p| p == File.dirname($LOADED_FEATURES.find{|f| f.end_with?("/rubygems.rb") }) }] + end +end diff --git a/tool/bundler/rubocop_gems.rb.lock b/tool/bundler/rubocop_gems.rb.lock index 45a33136bb..c95c6f15f5 100644 --- a/tool/bundler/rubocop_gems.rb.lock +++ b/tool/bundler/rubocop_gems.rb.lock @@ -57,4 +57,4 @@ DEPENDENCIES test-unit BUNDLED WITH - 2.2.25 + 2.2.26 diff --git a/tool/bundler/test_gems.rb.lock b/tool/bundler/test_gems.rb.lock index ae002ef2e4..f51d8a4b66 100644 --- a/tool/bundler/test_gems.rb.lock +++ b/tool/bundler/test_gems.rb.lock @@ -40,4 +40,4 @@ DEPENDENCIES webrick (= 1.7.0) BUNDLED WITH - 2.2.25 + 2.2.26 |