[rubygems/rubygems] Allow gem exec gem

https://github.com/rubygems/rubygems/commit/a767f7b9be
This commit is contained in:
Samuel Giddins 2023-02-13 18:39:08 -08:00 коммит произвёл git
Родитель 47d4f73ee7
Коммит 2dd9698350
2 изменённых файлов: 54 добавлений и 5 удалений

Просмотреть файл

@ -1,6 +1,7 @@
# frozen_string_literal: true
require_relative "../command"
require_relative "../dependency_installer"
require_relative "../gem_runner"
require_relative "../package"
require_relative "../version_option"
@ -60,7 +61,10 @@ to the same gem path as user-installed gems.
check_executable
print_command
if options[:conservative]
if options[:gem_name] == "gem" && options[:executable] == "gem"
Gem::GemRunner.new.run options[:args]
return
elsif options[:conservative]
install_if_needed
else
install
@ -135,15 +139,19 @@ to the same gem path as user-installed gems.
activate!
end
def install
gem_name = options[:gem_name]
gem_version = options[:version]
def set_gem_exec_install_paths
home = File.join(Gem.dir, "gem_exec")
ENV["GEM_PATH"] = ([home] + Gem.path).join(Gem.path_separator)
ENV["GEM_HOME"] = home
Gem.clear_paths
end
def install
set_gem_exec_install_paths
gem_name = options[:gem_name]
gem_version = options[:version]
install_options = options.merge(
minimal_deps: false,

Просмотреть файл

@ -701,4 +701,45 @@ class TestGemCommandsExecCommand < Gem::TestCase
assert_equal %w[b-2], @installed_specs.map(&:original_name)
end
end
def test_gem_exec_gem_uninstall
spec_fetcher do |fetcher|
fetcher.download "a", 2 do |s|
s.executables = %w[a]
s.files = %w[bin/a lib/a.rb]
s.add_runtime_dependency "b"
write_file File.join(*%W[gems #{s.original_name} bin a]) do |f|
f << "Gem.ui.say #{s.original_name.dump}"
end
end
fetcher.download "b", 2 do |s|
s.files = %w[lib/b.rb]
end
end
use_ui @ui do
invoke "a:2"
assert_equal "a-2\n", @ui.output
invoke "gem", "list", "--local"
assert_includes @ui.output, "a (2)\n"
assert_includes @ui.output, "b (2)\n"
invoke "gem", "uninstall", "--verbose", "-x", "a" rescue nil
refute_includes @ui.output, "running gem exec with"
assert_includes @ui.output, "Successfully uninstalled a-2\n"
invoke "--verbose", "gem", "uninstall", "b"
assert_includes @ui.output, "Successfully uninstalled b-2\n"
invoke "gem", "list", "--local"
assert_empty @ui.error
assert_match /\A\s*\** LOCAL GEMS \**\s*\z/m, @ui.output
invoke "gem", "env", "GEM_HOME"
assert_match /#{File::SEPARATOR}gem_exec$/, @ui.output
end
end
end