2013-07-08 18:41:03 -04:00
|
|
|
# coding: UTF-8
|
2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-07-08 18:41:03 -04:00
|
|
|
|
2012-11-29 23:30:12 -05:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems/commands/setup_command'
|
|
|
|
|
|
|
|
class TestGemCommandsSetupCommand < Gem::TestCase
|
|
|
|
|
2018-02-16 03:08:06 -05:00
|
|
|
bundler_gemspec = File.expand_path("../../../bundler/lib/bundler/version.rb", __FILE__)
|
|
|
|
if File.exist?(bundler_gemspec)
|
|
|
|
BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1]
|
|
|
|
else
|
2019-01-22 01:28:04 -05:00
|
|
|
BUNDLER_VERS = "2.0.1".freeze
|
2018-02-16 03:08:06 -05:00
|
|
|
end
|
2018-02-05 21:58:35 -05:00
|
|
|
|
2012-11-29 23:30:12 -05:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@install_dir = File.join @tempdir, 'install'
|
|
|
|
@cmd = Gem::Commands::SetupCommand.new
|
|
|
|
@cmd.options[:prefix] = @install_dir
|
|
|
|
|
|
|
|
FileUtils.mkdir_p 'bin'
|
2016-04-06 02:01:14 -04:00
|
|
|
FileUtils.mkdir_p 'lib/rubygems/ssl_certs/rubygems.org'
|
2012-11-29 23:30:12 -05:00
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
File.open 'bin/gem', 'w' do
|
|
|
|
|io| io.puts '# gem'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open 'lib/rubygems.rb', 'w' do |io|
|
|
|
|
io.puts '# rubygems.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open 'lib/rubygems/test_case.rb', 'w' do |io|
|
|
|
|
io.puts '# test_case.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open 'lib/rubygems/ssl_certs/rubygems.org/foo.pem', 'w' do |io|
|
|
|
|
io.puts 'PEM'
|
|
|
|
end
|
2017-10-07 21:32:18 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p 'bundler/exe'
|
|
|
|
FileUtils.mkdir_p 'bundler/lib/bundler'
|
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
File.open 'bundler/exe/bundle', 'w' do |io|
|
|
|
|
io.puts '# bundle'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open 'bundler/lib/bundler.rb', 'w' do |io|
|
|
|
|
io.puts '# bundler.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open 'bundler/lib/bundler/b.rb', 'w' do |io|
|
|
|
|
io.puts '# b.rb'
|
|
|
|
end
|
2017-11-28 17:30:28 -05:00
|
|
|
|
|
|
|
FileUtils.mkdir_p 'default/gems'
|
|
|
|
|
|
|
|
gemspec = Gem::Specification.new
|
|
|
|
gemspec.name = "bundler"
|
2018-02-05 21:58:35 -05:00
|
|
|
gemspec.version = BUNDLER_VERS
|
2017-11-28 17:30:28 -05:00
|
|
|
gemspec.bindir = "exe"
|
|
|
|
gemspec.executables = ["bundle"]
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open 'bundler/bundler.gemspec', 'w' do |io|
|
2017-11-28 17:30:28 -05:00
|
|
|
io.puts gemspec.to_ruby
|
|
|
|
end
|
|
|
|
|
|
|
|
open(File.join(Gem::Specification.default_specifications_dir, "bundler-1.15.4.gemspec"), 'w') do |io|
|
2017-12-22 19:38:52 -05:00
|
|
|
gemspec.version = "1.15.4"
|
|
|
|
io.puts gemspec.to_ruby
|
2017-11-28 17:30:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mkdir_p File.join(Gem.default_dir, "specifications")
|
2018-02-05 21:58:35 -05:00
|
|
|
|
|
|
|
open(File.join(Gem.default_dir, "specifications", "bundler-#{BUNDLER_VERS}.gemspec"), 'w') do |io|
|
|
|
|
io.puts "# bundler-#{BUNDLER_VERS}"
|
|
|
|
end
|
|
|
|
|
2017-11-28 17:30:28 -05:00
|
|
|
open(File.join(Gem.default_dir, "specifications", "bundler-audit-1.0.0.gemspec"), 'w') do |io|
|
|
|
|
io.puts '# bundler-audit'
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mkdir_p 'default/gems/bundler-1.15.4'
|
|
|
|
FileUtils.mkdir_p 'default/gems/bundler-audit-1.0.0'
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_install(name)
|
2017-11-28 17:30:28 -05:00
|
|
|
gem = util_spec name do |s|
|
|
|
|
s.executables = [name]
|
|
|
|
s.files = %W[bin/#{name}]
|
|
|
|
end
|
|
|
|
write_file File.join @tempdir, 'bin', name do |f|
|
|
|
|
f.puts '#!/usr/bin/ruby'
|
|
|
|
end
|
|
|
|
install_gem gem
|
|
|
|
File.join @gemhome, 'bin', name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_regenerate_binstubs
|
|
|
|
gem_bin_path = gem_install 'a'
|
|
|
|
write_file gem_bin_path do |io|
|
|
|
|
io.puts 'I changed it!'
|
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:document] = []
|
|
|
|
@cmd.execute
|
|
|
|
|
|
|
|
assert_match %r{\A#!}, File.read(gem_bin_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_no_regenerate_binstubs
|
|
|
|
gem_bin_path = gem_install 'a'
|
|
|
|
write_file gem_bin_path do |io|
|
|
|
|
io.puts 'I changed it!'
|
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:document] = []
|
|
|
|
@cmd.options[:regenerate_binstubs] = false
|
|
|
|
@cmd.execute
|
|
|
|
|
|
|
|
assert_equal "I changed it!\n", File.read(gem_bin_path)
|
2013-03-06 23:06:30 -05:00
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
def test_env_shebang_flag
|
|
|
|
gem_bin_path = gem_install 'a'
|
|
|
|
write_file gem_bin_path do |io|
|
|
|
|
io.puts 'I changed it!'
|
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:document] = []
|
|
|
|
@cmd.options[:env_shebang] = true
|
|
|
|
@cmd.execute
|
|
|
|
|
2018-12-19 02:20:17 -05:00
|
|
|
gem_exec = sprintf Gem.default_exec_format, 'gem'
|
|
|
|
default_gem_bin_path = File.join @install_dir, 'bin', gem_exec
|
2018-05-30 09:03:47 -04:00
|
|
|
if Gem::USE_BUNDLER_FOR_GEMDEPS
|
2018-12-19 02:20:17 -05:00
|
|
|
bundle_exec = sprintf Gem.default_exec_format, 'bundle'
|
|
|
|
default_bundle_bin_path = File.join @install_dir, 'bin', bundle_exec
|
2018-05-30 09:03:47 -04:00
|
|
|
end
|
2018-05-30 09:01:35 -04:00
|
|
|
|
|
|
|
ruby_exec = sprintf Gem.default_exec_format, 'ruby'
|
|
|
|
|
|
|
|
if Gem.win_platform?
|
|
|
|
assert_match %r%\A#!\s*#{ruby_exec}%, File.read(default_gem_bin_path)
|
2018-05-30 09:03:47 -04:00
|
|
|
if Gem::USE_BUNDLER_FOR_GEMDEPS
|
|
|
|
assert_match %r%\A#!\s*#{ruby_exec}%, File.read(default_bundle_bin_path)
|
|
|
|
end
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_match %r%\A#!\s*#{ruby_exec}%, File.read(gem_bin_path)
|
|
|
|
else
|
|
|
|
assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(default_gem_bin_path)
|
2018-05-30 09:03:47 -04:00
|
|
|
if Gem::USE_BUNDLER_FOR_GEMDEPS
|
|
|
|
assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(default_bundle_bin_path)
|
|
|
|
end
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(gem_bin_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-06 23:06:30 -05:00
|
|
|
def test_pem_files_in
|
2016-04-06 02:01:14 -04:00
|
|
|
assert_equal %w[rubygems/ssl_certs/rubygems.org/foo.pem],
|
2013-03-06 23:06:30 -05:00
|
|
|
@cmd.pem_files_in('lib').sort
|
2012-11-29 23:30:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rb_files_in
|
|
|
|
assert_equal %w[rubygems.rb rubygems/test_case.rb],
|
|
|
|
@cmd.rb_files_in('lib').sort
|
|
|
|
end
|
|
|
|
|
2013-03-06 23:06:30 -05:00
|
|
|
def test_install_lib
|
|
|
|
@cmd.extend FileUtils
|
|
|
|
|
|
|
|
Dir.mktmpdir 'lib' do |dir|
|
|
|
|
@cmd.install_lib dir
|
|
|
|
|
|
|
|
assert_path_exists File.join(dir, 'rubygems.rb')
|
2016-04-06 02:01:14 -04:00
|
|
|
assert_path_exists File.join(dir, 'rubygems/ssl_certs/rubygems.org/foo.pem')
|
2017-10-07 21:32:18 -04:00
|
|
|
|
|
|
|
if Gem::USE_BUNDLER_FOR_GEMDEPS
|
|
|
|
assert_path_exists File.join(dir, 'bundler.rb')
|
|
|
|
assert_path_exists File.join(dir, 'bundler/b.rb')
|
|
|
|
end
|
2013-03-06 23:06:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-28 17:30:28 -05:00
|
|
|
def test_install_default_bundler_gem
|
|
|
|
@cmd.extend FileUtils
|
|
|
|
|
|
|
|
@cmd.install_default_bundler_gem
|
|
|
|
|
|
|
|
if Gem.win_platform?
|
|
|
|
bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
|
|
|
|
default_spec_path = File.join(Gem::Specification.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
|
|
|
|
spec = Gem::Specification.load(default_spec_path)
|
|
|
|
|
|
|
|
spec.executables.each do |e|
|
|
|
|
assert_path_exists File.join(spec.bin_dir, "#{e}.bat")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
default_dir = Gem::Specification.default_specifications_dir
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
# expect to remove other versions of bundler gemspecs on default specification directory.
|
2017-11-28 17:30:28 -05:00
|
|
|
refute_path_exists File.join(default_dir, "bundler-1.15.4.gemspec")
|
2018-02-05 21:58:35 -05:00
|
|
|
assert_path_exists File.join(default_dir, "bundler-#{BUNDLER_VERS}.gemspec")
|
2017-11-28 17:30:28 -05:00
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
# expect to not remove bundler-* gemspecs.
|
2017-11-28 17:30:28 -05:00
|
|
|
assert_path_exists File.join(Gem.default_dir, "specifications", "bundler-audit-1.0.0.gemspec")
|
2018-02-05 21:58:35 -05:00
|
|
|
|
|
|
|
# expect to remove normal gem that was same version. because it's promoted default gems.
|
|
|
|
refute_path_exists File.join(Gem.default_dir, "specifications", "bundler-#{BUNDLER_VERS}.gemspec")
|
|
|
|
|
|
|
|
# expect to install default gems. It location was `site_ruby` directory on real world.
|
|
|
|
assert_path_exists "default/gems/bundler-#{BUNDLER_VERS}"
|
|
|
|
|
|
|
|
# expect to not remove other versions of bundler on `site_ruby`
|
|
|
|
assert_path_exists 'default/gems/bundler-1.15.4'
|
|
|
|
|
|
|
|
# TODO: We need to assert to remove same version of bundler on gem_dir directory(It's not site_ruby dir)
|
|
|
|
|
|
|
|
# expect to not remove bundler-* direcotyr.
|
2017-11-28 17:30:28 -05:00
|
|
|
assert_path_exists 'default/gems/bundler-audit-1.0.0'
|
|
|
|
end if Gem::USE_BUNDLER_FOR_GEMDEPS
|
|
|
|
|
2012-11-29 23:30:12 -05:00
|
|
|
def test_remove_old_lib_files
|
2013-03-11 17:29:32 -04:00
|
|
|
lib = File.join @install_dir, 'lib'
|
|
|
|
lib_rubygems = File.join lib, 'rubygems'
|
2017-10-07 21:32:18 -04:00
|
|
|
lib_bundler = File.join lib, 'bundler'
|
2013-03-11 17:29:32 -04:00
|
|
|
lib_rubygems_defaults = File.join lib_rubygems, 'defaults'
|
2012-11-29 23:30:12 -05:00
|
|
|
|
2013-03-11 17:29:32 -04:00
|
|
|
securerandom_rb = File.join lib, 'securerandom.rb'
|
2012-11-29 23:30:12 -05:00
|
|
|
|
2013-03-11 17:29:32 -04:00
|
|
|
engine_defaults_rb = File.join lib_rubygems_defaults, 'jruby.rb'
|
|
|
|
os_defaults_rb = File.join lib_rubygems_defaults, 'operating_system.rb'
|
2012-11-29 23:30:12 -05:00
|
|
|
|
2013-03-11 17:29:32 -04:00
|
|
|
old_builder_rb = File.join lib_rubygems, 'builder.rb'
|
|
|
|
old_format_rb = File.join lib_rubygems, 'format.rb'
|
2017-10-07 21:32:18 -04:00
|
|
|
old_bundler_c_rb = File.join lib_bundler, 'c.rb'
|
2013-03-11 17:29:32 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir_p lib_rubygems_defaults
|
2017-10-07 21:32:18 -04:00
|
|
|
FileUtils.mkdir_p lib_bundler
|
2013-03-11 17:29:32 -04:00
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
File.open securerandom_rb, 'w' do |io|
|
|
|
|
io.puts '# securerandom.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open old_builder_rb, 'w' do |io|
|
|
|
|
io.puts '# builder.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open old_format_rb, 'w' do |io|
|
|
|
|
io.puts '# format.rb'
|
|
|
|
end
|
2013-03-11 17:29:32 -04:00
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
File.open old_bundler_c_rb, 'w' do |io|
|
|
|
|
io.puts '# c.rb'
|
|
|
|
end
|
2013-03-11 17:29:32 -04:00
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
File.open engine_defaults_rb, 'w' do |io|
|
|
|
|
io.puts '# jruby.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
File.open os_defaults_rb, 'w' do |io|
|
|
|
|
io.puts '# operating_system.rb'
|
|
|
|
end
|
2012-11-29 23:30:12 -05:00
|
|
|
|
|
|
|
@cmd.remove_old_lib_files lib
|
|
|
|
|
|
|
|
refute_path_exists old_builder_rb
|
|
|
|
refute_path_exists old_format_rb
|
2017-10-07 21:32:18 -04:00
|
|
|
refute_path_exists old_bundler_c_rb if Gem::USE_BUNDLER_FOR_GEMDEPS
|
2013-03-11 17:29:32 -04:00
|
|
|
|
|
|
|
assert_path_exists securerandom_rb
|
|
|
|
assert_path_exists engine_defaults_rb
|
|
|
|
assert_path_exists os_defaults_rb
|
2012-11-29 23:30:12 -05:00
|
|
|
end
|
|
|
|
|
2013-07-08 18:41:03 -04:00
|
|
|
def test_show_release_notes
|
2018-05-30 09:01:35 -04:00
|
|
|
@default_external = @ui.outs.external_encoding
|
|
|
|
@ui.outs.set_encoding Encoding::US_ASCII
|
2013-07-08 18:41:03 -04:00
|
|
|
|
|
|
|
@cmd.options[:previous_version] = Gem::Version.new '2.0.2'
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open 'History.txt', 'w' do |io|
|
2013-07-08 18:41:03 -04:00
|
|
|
io.puts <<-History_txt
|
|
|
|
# coding: UTF-8
|
|
|
|
|
|
|
|
=== #{Gem::VERSION} / 2013-03-26
|
|
|
|
|
|
|
|
* Bug fixes:
|
|
|
|
* Fixed release note display for LANG=C when installing rubygems
|
|
|
|
* π is tasty
|
|
|
|
|
|
|
|
=== 2.0.2 / 2013-03-06
|
|
|
|
|
|
|
|
* Bug fixes:
|
|
|
|
* Other bugs fixed
|
|
|
|
|
|
|
|
=== 2.0.1 / 2013-03-05
|
|
|
|
|
|
|
|
* Bug fixes:
|
|
|
|
* Yet more bugs fixed
|
|
|
|
History_txt
|
|
|
|
end
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.show_release_notes
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EXPECTED
|
2014-09-13 23:30:02 -04:00
|
|
|
=== #{Gem::VERSION} / 2013-03-26
|
|
|
|
|
|
|
|
* Bug fixes:
|
|
|
|
* Fixed release note display for LANG=C when installing rubygems
|
|
|
|
* π is tasty
|
|
|
|
|
2013-07-08 18:41:03 -04:00
|
|
|
=== 2.0.2 / 2013-03-06
|
|
|
|
|
|
|
|
* Bug fixes:
|
|
|
|
* Other bugs fixed
|
|
|
|
|
|
|
|
EXPECTED
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
output = @ui.output
|
2018-05-30 09:01:35 -04:00
|
|
|
output.force_encoding Encoding::UTF_8
|
2014-09-13 23:30:02 -04:00
|
|
|
|
2014-09-18 03:30:19 -04:00
|
|
|
assert_equal expected, output
|
2013-07-08 18:41:03 -04:00
|
|
|
ensure
|
2014-09-18 03:30:19 -04:00
|
|
|
@ui.outs.set_encoding @default_external if @default_external
|
2013-07-08 18:41:03 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 23:30:12 -05:00
|
|
|
end
|