зеркало из https://github.com/github/ruby.git
[rubygems/rubygems] Allow gem exec gem
https://github.com/rubygems/rubygems/commit/a767f7b9be
This commit is contained in:
Родитель
47d4f73ee7
Коммит
2dd9698350
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче