diff options
Diffstat (limited to 'test/rubygems')
-rw-r--r-- | test/rubygems/helper.rb | 8 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_install_command.rb | 59 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_pristine_command.rb | 54 | ||||
-rw-r--r-- | test/rubygems/test_gem_dependency_installer.rb | 58 | ||||
-rw-r--r-- | test/rubygems/test_gem_ext_cargo_builder.rb | 52 | ||||
-rw-r--r-- | test/rubygems/test_gem_installer.rb | 50 |
6 files changed, 206 insertions, 75 deletions
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index d847d3b35e..af78bab724 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -683,6 +683,14 @@ class Gem::TestCase < Test::Unit::TestCase path end + def write_dummy_extconf(gem_name) + write_file File.join(@tempdir, "extconf.rb") do |io| + io.puts "require 'mkmf'" + yield io if block_given? + io.puts "create_makefile '#{gem_name}'" + end + end + ## # Load a YAML string, the psych 3 way diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index 468aecde56..d05cfef653 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -647,17 +647,10 @@ ERROR: Possible alternatives: non_existent_with_hint @cmd.options[:args] = %w[a] use_ui @ui do - # Don't use Dir.chdir with a block, it warnings a lot because - # of a downstream Dir.chdir with a block - old = Dir.getwd - - begin - Dir.chdir @tempdir + Dir.chdir @tempdir do assert_raise Gem::MockGemUi::SystemExitException, @ui.error do @cmd.execute end - ensure - Dir.chdir old end end @@ -684,17 +677,10 @@ ERROR: Possible alternatives: non_existent_with_hint @cmd.options[:args] = %w[a] use_ui @ui do - # Don't use Dir.chdir with a block, it warnings a lot because - # of a downstream Dir.chdir with a block - old = Dir.getwd - - begin - Dir.chdir @tempdir + Dir.chdir @tempdir do assert_raise Gem::MockGemUi::SystemExitException, @ui.error do @cmd.execute end - ensure - Dir.chdir old end end @@ -720,17 +706,10 @@ ERROR: Possible alternatives: non_existent_with_hint @cmd.options[:args] = %w[a] use_ui @ui do - # Don't use Dir.chdir with a block, it warnings a lot because - # of a downstream Dir.chdir with a block - old = Dir.getwd - - begin - Dir.chdir @tempdir + Dir.chdir @tempdir do assert_raise Gem::MockGemUi::SystemExitException, @ui.error do @cmd.execute end - ensure - Dir.chdir old end end @@ -1005,6 +984,38 @@ ERROR: Possible alternatives: non_existent_with_hint assert_equal %W[a-3-#{local}], @cmd.installed_specs.map(&:full_name) end + def test_install_gem_platform_specificity_match + util_set_arch "arm64-darwin-20" + + spec_fetcher do |fetcher| + %w[ruby universal-darwin universal-darwin-20 x64-darwin-20 arm64-darwin-20].each do |platform| + fetcher.download "a", 3 do |s| + s.platform = platform + end + end + end + + @cmd.install_gem "a", ">= 0" + + assert_equal %w[a-3-arm64-darwin-20], @cmd.installed_specs.map(&:full_name) + end + + def test_install_gem_platform_specificity_match_reverse_order + util_set_arch "arm64-darwin-20" + + spec_fetcher do |fetcher| + %w[ruby universal-darwin universal-darwin-20 x64-darwin-20 arm64-darwin-20].reverse_each do |platform| + fetcher.download "a", 3 do |s| + s.platform = platform + end + end + end + + @cmd.install_gem "a", ">= 0" + + assert_equal %w[a-3-arm64-darwin-20], @cmd.installed_specs.map(&:full_name) + end + def test_install_gem_ignore_dependencies_specific_file spec = util_spec "a", 2 diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index 46c06db014..e9c4d32945 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -125,8 +125,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase @cmd.execute end - assert File.exist?(gem_bin) - assert File.exist?(gem_stub) + assert_path_exist gem_bin + assert_path_exist gem_stub out = @ui.output.split "\n" @@ -537,8 +537,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase @cmd.execute end - assert File.exist? gem_exec - refute File.exist? gem_lib + assert_path_exist gem_exec + assert_path_not_exist gem_lib end def test_execute_only_plugins @@ -572,9 +572,9 @@ class TestGemCommandsPristineCommand < Gem::TestCase @cmd.execute end - refute File.exist? gem_exec - assert File.exist? gem_plugin - refute File.exist? gem_lib + assert_path_not_exist gem_exec + assert_path_exist gem_plugin + assert_path_not_exist gem_lib end def test_execute_bindir @@ -606,8 +606,8 @@ class TestGemCommandsPristineCommand < Gem::TestCase @cmd.execute end - refute File.exist? gem_exec - assert File.exist? gem_bindir + assert_path_not_exist gem_exec + assert_path_exist gem_bindir end def test_execute_unknown_gem_at_remote_source @@ -659,6 +659,42 @@ class TestGemCommandsPristineCommand < Gem::TestCase refute_includes "ruby_executable_hooks", File.read(exe) end + def test_execute_default_gem_and_regular_gem + a_default = new_default_spec("a", "1.2.0") + + a = util_spec "a" do |s| + s.extensions << "ext/a/extconf.rb" + 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_default_gems a_default + install_gem a + + # Remove the extension files for a + FileUtils.rm_rf a.gem_build_complete_path + + @cmd.options[:args] = %w[a] + + use_ui @ui do + @cmd.execute + end + + assert_includes @ui.output, "Restored #{a.full_name}" + + # Check extension files for a were restored + assert_path_exist a.gem_build_complete_path + end + def test_execute_multi_platform a = util_spec "a" do |s| s.extensions << "ext/a/extconf.rb" diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 56b84160c4..f84881579a 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -382,13 +382,9 @@ class TestGemDependencyInstaller < Gem::TestCase FileUtils.mv f1_gem, @tempdir inst = nil - pwd = Dir.getwd - Dir.chdir @tempdir - begin + Dir.chdir @tempdir do inst = Gem::DependencyInstaller.new inst.install "f" - ensure - Dir.chdir pwd end assert_equal %w[f-1], inst.installed_gems.map(&:full_name) @@ -523,6 +519,58 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map(&:full_name) end + def test_install_local_with_extensions_already_installed + pend "needs investigation" if Gem.java_platform? + pend "ruby.h is not provided by ruby repo" if ruby_repo? + + @spec = quick_gem "a" do |s| + s.extensions << "extconf.rb" + s.files += %w[extconf.rb a.c] + end + + write_dummy_extconf "a" + + c_source_path = File.join(@tempdir, "a.c") + + write_file c_source_path do |io| + io.write <<-C + #include <ruby.h> + void Init_a() { } + C + end + + package_path = Gem::Package.build @spec + installer = Gem::Installer.at(package_path) + + # Make sure the gem is installed and backup the correct package + + installer.install + + package_bkp_path = "#{package_path}.bkp" + FileUtils.cp package_path, package_bkp_path + + # Break the extension, rebuild it, and try to install it + + write_file c_source_path do |io| + io.write "typo" + end + + Gem::Package.build @spec + + assert_raise Gem::Ext::BuildError do + installer.install + end + + # Make sure installing the good package again still works + + FileUtils.cp "#{package_path}.bkp", package_path + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new domain: :local + inst.install package_path + end + end + def test_install_minimal_deps util_setup_gems diff --git a/test/rubygems/test_gem_ext_cargo_builder.rb b/test/rubygems/test_gem_ext_cargo_builder.rb index 5035937544..b970e442c2 100644 --- a/test/rubygems/test_gem_ext_cargo_builder.rb +++ b/test/rubygems/test_gem_ext_cargo_builder.rb @@ -141,6 +141,58 @@ class TestGemExtCargoBuilder < Gem::TestCase end end + def test_linker_args + orig_cc = RbConfig::MAKEFILE_CONFIG["CC"] + RbConfig::MAKEFILE_CONFIG["CC"] = "clang" + + builder = Gem::Ext::CargoBuilder.new + args = builder.send(:linker_args) + + assert args[1], "linker=clang" + assert_nil args[2] + ensure + RbConfig::MAKEFILE_CONFIG["CC"] = orig_cc + end + + def test_linker_args_with_options + orig_cc = RbConfig::MAKEFILE_CONFIG["CC"] + RbConfig::MAKEFILE_CONFIG["CC"] = "gcc -Wl,--no-undefined" + + builder = Gem::Ext::CargoBuilder.new + args = builder.send(:linker_args) + + assert args[1], "linker=clang" + assert args[3], "link-args=-Wl,--no-undefined" + ensure + RbConfig::MAKEFILE_CONFIG["CC"] = orig_cc + end + + def test_linker_args_with_cachetools + orig_cc = RbConfig::MAKEFILE_CONFIG["CC"] + RbConfig::MAKEFILE_CONFIG["CC"] = "sccache clang" + + builder = Gem::Ext::CargoBuilder.new + args = builder.send(:linker_args) + + assert args[1], "linker=clang" + assert_nil args[2] + ensure + RbConfig::MAKEFILE_CONFIG["CC"] = orig_cc + end + + def test_linker_args_with_cachetools_and_options + orig_cc = RbConfig::MAKEFILE_CONFIG["CC"] + RbConfig::MAKEFILE_CONFIG["CC"] = "ccache gcc -Wl,--no-undefined" + + builder = Gem::Ext::CargoBuilder.new + args = builder.send(:linker_args) + + assert args[1], "linker=clang" + assert args[3], "link-args=-Wl,--no-undefined" + ensure + RbConfig::MAKEFILE_CONFIG["CC"] = orig_cc + end + private def skip_unsupported_platforms! diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index dfa8df283c..6d8a523507 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -1478,12 +1478,7 @@ end @spec = setup_base_spec @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| - io.write <<-RUBY - require "mkmf" - create_makefile("#{@spec.name}") - RUBY - end + write_dummy_extconf @spec.name @spec.files += %w[extconf.rb] @@ -1503,12 +1498,7 @@ end @spec = setup_base_spec @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| - io.write <<-RUBY - require "mkmf" - create_makefile("#{@spec.name}") - RUBY - end + write_dummy_extconf @spec.name @spec.files += %w[extconf.rb] @@ -1539,12 +1529,7 @@ end def test_install_user_extension_dir @spec = setup_base_spec @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| - io.write <<-RUBY - require "mkmf" - create_makefile("#{@spec.name}") - RUBY - end + write_dummy_extconf @spec.name @spec.files += %w[extconf.rb] @@ -1571,15 +1556,13 @@ end @spec = setup_base_spec @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| + write_dummy_extconf @spec.name do |io| io.write <<-RUBY - require "mkmf" CONFIG['CC'] = '$(TOUCH) $@ ||' CONFIG['LDSHARED'] = '$(TOUCH) $@ ||' $ruby = '#{Gem.ruby}' - create_makefile("#{@spec.name}") RUBY end @@ -1618,12 +1601,7 @@ end @spec = setup_base_spec @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| - io.write <<-RUBY - require "mkmf" - create_makefile("#{@spec.name}") - RUBY - end + write_dummy_extconf @spec.name rb = File.join("lib", "#{@spec.name}.rb") @spec.files += [rb] @@ -1663,15 +1641,13 @@ end @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| + write_dummy_extconf @spec.name do |io| io.write <<-RUBY - require "mkmf" CONFIG['CC'] = '$(TOUCH) $@ ||' CONFIG['LDSHARED'] = '$(TOUCH) $@ ||' $ruby = '#{Gem.ruby}' - create_makefile("#{@spec.name}") RUBY end @@ -1698,13 +1674,13 @@ end @spec.require_paths = ["."] @spec.extensions << "extconf.rb" - File.write File.join(@tempdir, "extconf.rb"), <<-RUBY - require "mkmf" - CONFIG['CC'] = '$(TOUCH) $@ ||' - CONFIG['LDSHARED'] = '$(TOUCH) $@ ||' - $ruby = '#{Gem.ruby}' - create_makefile("#{@spec.name}") - RUBY + write_dummy_extconf @spec.name do |io| + io.write <<~RUBY + CONFIG['CC'] = '$(TOUCH) $@ ||' + CONFIG['LDSHARED'] = '$(TOUCH) $@ ||' + $ruby = '#{Gem.ruby}' + RUBY + end # empty depend file for no auto dependencies @spec.files += %W[depend #{@spec.name}.c].each do |file| |