2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/pristine_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsPristineCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
def setup
|
|
|
|
super
|
2015-08-13 10:43:14 -04:00
|
|
|
common_installer_setup
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd = Gem::Commands::PristineCommand.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
2013-11-11 19:16:41 -05:00
|
|
|
a = util_spec 'a' do |s|
|
2012-11-29 01:52:18 -05:00
|
|
|
s.executables = %w[foo]
|
|
|
|
s.files = %w[bin/foo lib/a.rb]
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
write_file File.join(@tempdir, 'lib', 'a.rb') do |fp|
|
|
|
|
fp.puts "puts __FILE__"
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
write_file File.join(@tempdir, 'bin', 'foo') do |fp|
|
2007-11-10 02:48:56 -05:00
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
|
|
|
|
a_rb_path = File.join @gemhome, 'gems', a.full_name, 'lib', 'a.rb'
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
write_file foo_path do |io|
|
2008-06-17 18:04:18 -04:00
|
|
|
io.puts 'I changed it!'
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
write_file a_rb_path do |io|
|
|
|
|
io.puts 'I changed it!'
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal "puts __FILE__\n", File.read(a_rb_path), a_rb_path
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal "Restoring gems to pristine condition...", out.shift
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_empty out, out.inspect
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2019-11-11 01:03:57 -05:00
|
|
|
def test_execute_user_install
|
|
|
|
FileUtils.chmod 0555, @gemhome
|
|
|
|
|
|
|
|
a = util_spec "a" do |s|
|
|
|
|
s.executables = %w[foo]
|
|
|
|
s.files = %w[bin/foo lib/a.rb]
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file File.join(@tempdir, "lib", "a.rb") do |fp|
|
|
|
|
fp.puts "puts __FILE__"
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file File.join(@tempdir, "bin", "foo") do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem_user(a)
|
|
|
|
|
|
|
|
Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
|
|
|
|
|
|
|
|
foo_path = File.join(Gem.user_dir, "gems", a.full_name, "bin", "foo")
|
|
|
|
a_rb_path = File.join(Gem.user_dir, "gems", a.full_name, "lib", "a.rb")
|
|
|
|
|
|
|
|
write_file foo_path do |io|
|
|
|
|
io.puts("I changed it!")
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file a_rb_path do |io|
|
|
|
|
io.puts("I changed it!")
|
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
|
|
|
|
assert_equal "puts __FILE__\n", File.read(a_rb_path), a_rb_path
|
|
|
|
|
|
|
|
out = @ui.output.split("\n")
|
|
|
|
|
|
|
|
assert_equal "Restoring gems to pristine condition...", out.shift
|
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
ensure
|
|
|
|
FileUtils.chmod(0755, @gemhome)
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_all
|
2019-02-14 07:59:03 -05:00
|
|
|
a = util_spec 'a' do |s|
|
|
|
|
s.executables = %w[foo]
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
write_file File.join(@tempdir, 'bin', 'foo') do |fp|
|
2007-11-10 02:48:56 -05:00
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
|
|
|
|
gem_stub = File.join @gemhome, 'bin', 'foo'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
FileUtils.rm gem_bin
|
2012-11-29 01:52:18 -05:00
|
|
|
FileUtils.rm gem_stub
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
@cmd.handle_options %w[--all]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert File.exist?(gem_bin)
|
2012-11-29 01:52:18 -05:00
|
|
|
assert File.exist?(gem_stub)
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_equal "Restoring gems to pristine condition...", out.shift
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_empty out, out.inspect
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def test_execute_env_shebang
|
2013-11-11 19:16:41 -05:00
|
|
|
a = util_spec 'a' do |s|
|
2013-09-14 04:59:02 -04:00
|
|
|
s.executables = %w[foo]
|
|
|
|
s.files = %w[bin/foo]
|
|
|
|
end
|
|
|
|
write_file File.join(@tempdir, 'bin', 'foo') do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
|
|
|
gem_exec = File.join @gemhome, 'bin', 'foo'
|
|
|
|
|
|
|
|
FileUtils.rm gem_exec
|
|
|
|
|
|
|
|
@cmd.handle_options %w[--all --env-shebang]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist gem_exec
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
ruby_exec = sprintf Gem.default_exec_format, 'ruby'
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
bin_env = win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " "
|
2020-03-24 04:21:55 -04:00
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(gem_exec)
|
2013-09-14 04:59:02 -04:00
|
|
|
end
|
|
|
|
|
2013-09-18 17:29:41 -04:00
|
|
|
def test_execute_extensions_explicit
|
2019-02-14 07:59:03 -05:00
|
|
|
a = util_spec 'a' do |s|
|
|
|
|
s.extensions << 'ext/a/extconf.rb'
|
|
|
|
end
|
2013-09-18 17:29:41 -04:00
|
|
|
|
|
|
|
ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
|
|
|
|
write_file ext_path do |io|
|
|
|
|
io.write <<-'RUBY'
|
|
|
|
File.open "Makefile", "w" do |f|
|
2013-10-15 20:14:16 -04:00
|
|
|
f.puts "clean:\n\techo cleaned\n"
|
2013-09-18 17:29:41 -04:00
|
|
|
f.puts "all:\n\techo built\n"
|
2013-10-15 20:14:16 -04:00
|
|
|
f.puts "install:\n\techo installed\n"
|
2013-09-18 17:29:41 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
b = util_spec 'b'
|
2013-09-18 17:29:41 -04:00
|
|
|
|
|
|
|
install_gem a
|
|
|
|
install_gem b
|
|
|
|
|
|
|
|
@cmd.options[:extensions] = true
|
|
|
|
@cmd.options[:extensions_set] = true
|
|
|
|
@cmd.options[:args] = []
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal 'Restoring gems to pristine condition...', out.shift
|
2017-10-07 21:32:18 -04:00
|
|
|
assert_equal 'Building native extensions. This could take a while...',
|
2013-09-18 17:29:41 -04:00
|
|
|
out.shift
|
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_execute_no_extension
|
2019-02-14 07:59:03 -05:00
|
|
|
a = util_spec 'a' do |s|
|
|
|
|
s.extensions << 'ext/a/extconf.rb'
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
|
|
|
|
write_file ext_path do |io|
|
2015-07-01 17:50:14 -04:00
|
|
|
io.write "# extconf.rb\nrequire 'mkmf'; create_makefile 'a'"
|
2011-03-07 03:44:45 -05:00
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
install_gem a
|
2011-03-07 03:44:45 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
@cmd.options[:extensions] = false
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal 'Restoring gems to pristine condition...', out.shift
|
|
|
|
assert_equal "Skipped #{a.full_name}, it needs to compile an extension",
|
|
|
|
out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_execute_with_extension_with_build_args
|
2019-02-14 07:59:03 -05:00
|
|
|
a = util_spec 'a' do |s|
|
|
|
|
s.extensions << 'ext/a/extconf.rb'
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
|
|
|
|
write_file ext_path do |io|
|
|
|
|
io.write <<-'RUBY'
|
|
|
|
File.open "Makefile", "w" do |f|
|
2013-10-15 20:14:16 -04:00
|
|
|
f.puts "clean:\n\techo cleaned\n"
|
2012-11-29 01:52:18 -05:00
|
|
|
f.puts "all:\n\techo built\n"
|
2013-10-15 20:14:16 -04:00
|
|
|
f.puts "install:\n\techo installed\n"
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
build_args = %w[--with-awesome=true --sweet]
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
install_gem a, :build_args => build_args
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal 'Restoring gems to pristine condition...', out.shift
|
|
|
|
assert_equal "Building native extensions with: '--with-awesome=true --sweet'", out.shift
|
|
|
|
assert_equal "This could take a while...", out.shift
|
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_execute_many
|
2013-11-11 19:16:41 -05:00
|
|
|
a = util_spec 'a'
|
|
|
|
b = util_spec 'b'
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
install_gem a
|
|
|
|
install_gem b
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a b]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal "Restoring gems to pristine condition...", out.shift
|
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
|
|
|
assert_equal "Restored #{b.full_name}", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
end
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
def test_skip
|
|
|
|
a = util_spec 'a'
|
|
|
|
b = util_spec 'b'
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
install_gem b
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a b]
|
|
|
|
@cmd.options[:skip] = 'a'
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal "Restoring gems to pristine condition...", out.shift
|
|
|
|
assert_equal "Skipped #{a.full_name}, it was given through options", out.shift
|
|
|
|
assert_equal "Restored #{b.full_name}", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
def test_skip_many_gems
|
|
|
|
a = util_spec 'a'
|
|
|
|
b = util_spec 'b'
|
|
|
|
c = util_spec 'c'
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
install_gem b
|
|
|
|
install_gem c
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a b c]
|
|
|
|
@cmd.options[:skip] = ['a', 'c']
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal "Restoring gems to pristine condition...", out.shift
|
|
|
|
assert_equal "Skipped #{a.full_name}, it was given through options", out.shift
|
|
|
|
assert_equal "Restored #{b.full_name}", out.shift
|
|
|
|
assert_equal "Skipped #{c.full_name}, it was given through options", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_execute_many_multi_repo
|
2013-11-11 19:16:41 -05:00
|
|
|
a = util_spec 'a'
|
2007-11-10 02:48:56 -05:00
|
|
|
install_gem a
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
Gem.clear_paths
|
|
|
|
gemhome2 = File.join @tempdir, 'gemhome2'
|
2015-01-09 09:20:10 -05:00
|
|
|
Gem.use_paths gemhome2, [gemhome2, @gemhome]
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
b = util_spec 'b'
|
2011-05-31 23:45:05 -04:00
|
|
|
install_gem b
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a b]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal "Restoring gems to pristine condition...", out.shift
|
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
|
|
|
assert_equal "Restored #{b.full_name}", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist File.join(@gemhome, "gems", 'a-2')
|
|
|
|
assert_path_not_exist File.join(gemhome2, "gems", 'a-2')
|
|
|
|
assert_path_exist File.join(gemhome2, "gems", 'b-2')
|
|
|
|
assert_path_not_exist File.join(@gemhome, "gems", 'b-2')
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_missing_cache_gem
|
2013-11-11 19:16:41 -05:00
|
|
|
specs = spec_fetcher do |fetcher|
|
|
|
|
fetcher.gem 'a', 1
|
|
|
|
fetcher.gem 'a', 2
|
|
|
|
fetcher.gem 'a', 3
|
|
|
|
fetcher.gem 'a', '3.a'
|
2011-03-07 03:44:45 -05:00
|
|
|
end
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
FileUtils.rm specs['a-2'].cache_file
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
[
|
2011-05-31 23:45:05 -04:00
|
|
|
"Restoring gems to pristine condition...",
|
2011-03-07 03:44:45 -05:00
|
|
|
"Restored a-1",
|
|
|
|
"Cached gem for a-2 not found, attempting to fetch...",
|
|
|
|
"Restored a-2",
|
2011-05-31 23:45:05 -04:00
|
|
|
"Restored a-3.a",
|
|
|
|
"Restored a-3",
|
2011-03-07 03:44:45 -05:00
|
|
|
].each do |line|
|
|
|
|
assert_equal line, out.shift
|
|
|
|
end
|
2011-03-07 03:39:39 -05:00
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
assert_empty out, out.inspect
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2014-12-06 19:53:01 -05:00
|
|
|
def test_execute_missing_cache_gem_when_multi_repo
|
|
|
|
specs = spec_fetcher do |fetcher|
|
|
|
|
fetcher.gem 'a', 1
|
|
|
|
fetcher.gem 'b', 1
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.rm_rf File.join(@gemhome, 'gems', 'a-1')
|
|
|
|
FileUtils.rm_rf File.join(@gemhome, 'gems', 'b-1')
|
|
|
|
|
|
|
|
install_gem specs["a-1"]
|
|
|
|
FileUtils.rm File.join(@gemhome, 'cache', 'a-1.gem')
|
|
|
|
|
|
|
|
Gem.clear_paths
|
|
|
|
gemhome2 = File.join(@tempdir, 'gemhome2')
|
2015-01-09 09:20:10 -05:00
|
|
|
Gem.use_paths gemhome2, [gemhome2, @gemhome]
|
2014-12-06 19:53:01 -05:00
|
|
|
|
|
|
|
install_gem specs["b-1"]
|
|
|
|
FileUtils.rm File.join(gemhome2, 'cache', 'b-1.gem')
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a b]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
[
|
|
|
|
"Restoring gems to pristine condition...",
|
|
|
|
"Cached gem for a-1 not found, attempting to fetch...",
|
|
|
|
"Restored a-1",
|
|
|
|
"Cached gem for b-1 not found, attempting to fetch...",
|
|
|
|
"Restored b-1",
|
|
|
|
].each do |line|
|
|
|
|
assert_equal line, out.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
assert_empty @ui.error
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist File.join(@gemhome, "cache", 'a-1.gem')
|
|
|
|
assert_path_not_exist File.join(gemhome2, "cache", 'a-2.gem')
|
|
|
|
assert_path_exist File.join(@gemhome, "gems", 'a-1')
|
|
|
|
assert_path_not_exist File.join(gemhome2, "gems", 'a-1')
|
2014-12-06 19:53:01 -05:00
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist File.join(gemhome2, "cache", 'b-1.gem')
|
|
|
|
assert_path_not_exist File.join(@gemhome, "cache", 'b-2.gem')
|
|
|
|
assert_path_exist File.join(gemhome2, "gems", 'b-1')
|
|
|
|
assert_path_not_exist File.join(@gemhome, "gems", 'b-1')
|
2014-12-06 19:53:01 -05:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_no_gem
|
|
|
|
@cmd.options[:args] = %w[]
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::CommandLineError do
|
2007-11-10 02:48:56 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{at least one gem name}, e.message
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_execute_only_executables
|
2013-11-11 19:16:41 -05:00
|
|
|
a = util_spec 'a' do |s|
|
2012-11-29 01:52:18 -05:00
|
|
|
s.executables = %w[foo]
|
|
|
|
s.files = %w[bin/foo lib/a.rb]
|
|
|
|
end
|
|
|
|
write_file File.join(@tempdir, 'lib', 'a.rb') do |fp|
|
|
|
|
fp.puts "puts __FILE__"
|
|
|
|
end
|
|
|
|
write_file File.join(@tempdir, 'bin', 'foo') do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
|
|
|
gem_lib = File.join @gemhome, 'gems', a.full_name, 'lib', 'a.rb'
|
|
|
|
gem_exec = File.join @gemhome, 'bin', 'foo'
|
|
|
|
|
|
|
|
FileUtils.rm gem_exec
|
|
|
|
FileUtils.rm gem_lib
|
|
|
|
|
|
|
|
@cmd.handle_options %w[--all --only-executables]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert File.exist? gem_exec
|
|
|
|
refute File.exist? gem_lib
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
def test_execute_only_plugins
|
|
|
|
a = util_spec 'a' do |s|
|
|
|
|
s.executables = %w[foo]
|
|
|
|
s.files = %w[bin/foo lib/a.rb lib/rubygems_plugin.rb]
|
|
|
|
end
|
|
|
|
write_file File.join(@tempdir, 'lib', 'a.rb') do |fp|
|
|
|
|
fp.puts "puts __FILE__"
|
|
|
|
end
|
|
|
|
write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |fp|
|
|
|
|
fp.puts "puts __FILE__"
|
|
|
|
end
|
|
|
|
write_file File.join(@tempdir, 'bin', 'foo') do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
|
|
|
gem_lib = File.join @gemhome, 'gems', a.full_name, 'lib', 'a.rb'
|
|
|
|
gem_plugin = File.join @gemhome, 'plugins', 'a_plugin.rb'
|
|
|
|
gem_exec = File.join @gemhome, 'bin', 'foo'
|
|
|
|
|
|
|
|
FileUtils.rm gem_exec
|
|
|
|
FileUtils.rm gem_plugin
|
|
|
|
FileUtils.rm gem_lib
|
|
|
|
|
|
|
|
@cmd.handle_options %w[--all --only-plugins]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
refute File.exist? gem_exec
|
|
|
|
assert File.exist? gem_plugin
|
|
|
|
refute File.exist? gem_lib
|
|
|
|
end
|
|
|
|
|
2018-08-27 06:05:04 -04:00
|
|
|
def test_execute_bindir
|
|
|
|
a = util_spec 'a' do |s|
|
|
|
|
s.name = "test_gem"
|
|
|
|
s.executables = %w[foo]
|
|
|
|
s.files = %w[bin/foo]
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file File.join(@tempdir, 'bin', 'foo') do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file File.join(@tempdir, 'test_bin', 'foo') do |fp|
|
|
|
|
fp.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
|
|
|
|
gem_exec = File.join @gemhome, 'bin', 'foo'
|
|
|
|
gem_bindir = File.join @tempdir, 'test_bin', 'foo'
|
|
|
|
|
|
|
|
FileUtils.rm gem_exec
|
|
|
|
FileUtils.rm gem_bindir
|
|
|
|
|
|
|
|
@cmd.handle_options ["--all", "--only-executables", "--bindir", "#{gem_bindir}"]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
refute File.exist? gem_exec
|
|
|
|
assert File.exist? gem_bindir
|
|
|
|
end
|
|
|
|
|
2014-12-06 19:53:01 -05:00
|
|
|
def test_execute_unknown_gem_at_remote_source
|
2015-07-01 17:50:14 -04:00
|
|
|
install_specs util_spec 'a'
|
2014-12-06 19:53:01 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal([
|
|
|
|
"Restoring gems to pristine condition...",
|
|
|
|
"Cached gem for a-2 not found, attempting to fetch...",
|
2020-12-08 02:33:39 -05:00
|
|
|
"Skipped a-2, it was not found from cache and remote sources",
|
2014-12-06 19:53:01 -05:00
|
|
|
], @ui.output.split("\n"))
|
|
|
|
|
|
|
|
assert_empty @ui.error
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_execute_default_gem
|
|
|
|
default_gem_spec = new_default_spec("default", "2.0.0.0",
|
|
|
|
nil, "default/gem.rb")
|
2020-12-08 02:33:39 -05:00
|
|
|
install_default_gems(default_gem_spec)
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[default]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2018-10-21 20:27:02 -04:00
|
|
|
assert_equal(
|
|
|
|
[
|
|
|
|
"Restoring gems to pristine condition...",
|
|
|
|
"Skipped default-2.0.0.0, it is a default gem",
|
|
|
|
],
|
|
|
|
@ui.output.split("\n")
|
|
|
|
)
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_empty(@ui.error)
|
|
|
|
end
|
2013-09-18 17:29:41 -04:00
|
|
|
|
2019-03-07 06:24:48 -05:00
|
|
|
def test_execute_multi_platform
|
|
|
|
a = util_spec 'a' do |s|
|
|
|
|
s.extensions << 'ext/a/extconf.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
b = util_spec 'b' do |s|
|
|
|
|
s.extensions << 'ext/a/extconf.rb'
|
|
|
|
s.platform = Gem::Platform.new("java")
|
|
|
|
end
|
|
|
|
|
|
|
|
ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
|
|
|
|
write_file ext_path do |io|
|
|
|
|
io.write <<-'RUBY'
|
|
|
|
File.open "Makefile", "w" do |f|
|
|
|
|
f.puts "clean:\n\techo cleaned\n"
|
|
|
|
f.puts "all:\n\techo built\n"
|
|
|
|
f.puts "install:\n\techo installed\n"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
install_gem a
|
|
|
|
install_gem b
|
|
|
|
|
|
|
|
@cmd.options[:extensions] = true
|
|
|
|
@cmd.options[:extensions_set] = true
|
|
|
|
@cmd.options[:args] = []
|
|
|
|
|
2019-04-02 07:48:18 -04:00
|
|
|
util_set_arch "x86_64-darwin" do
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
2019-03-07 06:24:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
out = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal 'Restoring gems to pristine condition...', out.shift
|
|
|
|
assert_equal 'Building native extensions. This could take a while...',
|
|
|
|
out.shift
|
|
|
|
assert_equal "Restored #{a.full_name}", out.shift
|
|
|
|
assert_empty out, out.inspect
|
|
|
|
end
|
|
|
|
|
2013-09-18 17:29:41 -04:00
|
|
|
def test_handle_options
|
|
|
|
@cmd.handle_options %w[]
|
|
|
|
|
|
|
|
refute @cmd.options[:all]
|
|
|
|
|
|
|
|
assert @cmd.options[:extensions]
|
|
|
|
refute @cmd.options[:extensions_set]
|
|
|
|
|
|
|
|
assert_equal Gem::Requirement.default, @cmd.options[:version]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_options_extensions
|
|
|
|
@cmd.handle_options %w[--extensions]
|
|
|
|
|
|
|
|
assert @cmd.options[:extensions]
|
|
|
|
assert @cmd.options[:extensions_set]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|