diff options
author | Hiroshi SHIBATA <[email protected]> | 2019-06-01 12:45:11 +0300 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2019-06-01 13:50:41 +0300 |
commit | 56660de3c6df7a4ff8667ef4047d30d0de169935 () | |
tree | dd1e526075687b4b24e089cee50eabc21a6143cc /test | |
parent | 560cd5b1f04f30542a294b3d77527d3b12f7cc15 (diff) |
Merge rubygems master from upstream.
I picked the commit from 3c469e0da538428a0ddd94f99aa73c32da22e8ba
37 files changed, 734 insertions, 584 deletions
@@ -465,55 +465,43 @@ class TestGem < Gem::TestCase end def test_default_path - orig_vendordir = RbConfig::CONFIG['vendordir'] - RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor' - FileUtils.rm_rf Gem.user_home - expected = [Gem.default_dir] - - assert_equal expected, Gem.default_path - ensure - RbConfig::CONFIG['vendordir'] = orig_vendordir end def test_default_path_missing_vendor - orig_vendordir = RbConfig::CONFIG['vendordir'] - RbConfig::CONFIG.delete 'vendordir' - - FileUtils.rm_rf Gem.user_home - expected = [Gem.default_dir] - assert_equal expected, Gem.default_path - ensure - RbConfig::CONFIG['vendordir'] = orig_vendordir end def test_default_path_user_home - orig_vendordir = RbConfig::CONFIG['vendordir'] - RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor' - expected = [Gem.user_dir, Gem.default_dir] - - assert_equal expected, Gem.default_path - ensure - RbConfig::CONFIG['vendordir'] = orig_vendordir end def test_default_path_vendor_dir - orig_vendordir = RbConfig::CONFIG['vendordir'] - RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor' - - FileUtils.mkdir_p Gem.vendor_dir - FileUtils.rm_rf Gem.user_home - expected = [Gem.default_dir, Gem.vendor_dir] - assert_equal expected, Gem.default_path - ensure - RbConfig::CONFIG['vendordir'] = orig_vendordir end def test_self_default_sources @@ -706,7 +694,7 @@ class TestGem < Gem::TestCase assert_equal expected, Gem.find_files('sff/discover').sort assert_equal expected, Gem.find_files('sff/**.rb').sort, '[ruby-core:31730]' ensure - assert_equal cwd, actual_load_path.shift end def test_self_find_latest_files @@ -1232,10 +1220,12 @@ class TestGem < Gem::TestCase refute Gem.try_activate 'nonexistent' end - expected = "Ignoring ext-1 because its extensions are not built. " + - "Try: gem pristine ext --version 1\n" - assert_equal expected, err end def test_self_use_paths_with_nils @@ -1303,7 +1293,6 @@ class TestGem < Gem::TestCase end def test_self_needs - util_clear_gems a = util_spec "a", "1" b = util_spec "b", "1", "c" => nil c = util_spec "c", "2" @@ -1322,7 +1311,6 @@ class TestGem < Gem::TestCase def test_self_needs_picks_up_unresolved_deps save_loaded_features do - util_clear_gems a = util_spec "a", "1" b = util_spec "b", "1", "c" => nil c = util_spec "c", "2" @@ -1364,11 +1352,13 @@ class TestGem < Gem::TestCase end def test_self_vendor_dir - expected = - File.join RbConfig::CONFIG['vendordir'], 'gems', - RbConfig::CONFIG['ruby_version'] - assert_equal expected, Gem.vendor_dir end def test_self_vendor_dir_ENV_GEM_VENDOR @@ -1379,12 +1369,9 @@ class TestGem < Gem::TestCase end def test_self_vendor_dir_missing - orig_vendordir = RbConfig::CONFIG['vendordir'] - RbConfig::CONFIG.delete 'vendordir' - - assert_nil Gem.vendor_dir - ensure - RbConfig::CONFIG['vendordir'] = orig_vendordir end def test_load_plugins @@ -1514,8 +1501,6 @@ class TestGem < Gem::TestCase end def test_auto_activation_of_specific_gemdeps_file - util_clear_gems - a = util_spec "a", "1", nil, "lib/a.rb" b = util_spec "b", "1", nil, "lib/b.rb" c = util_spec "c", "1", nil, "lib/c.rb" @@ -1538,8 +1523,6 @@ class TestGem < Gem::TestCase end def test_auto_activation_of_used_gemdeps_file - util_clear_gems - a = util_spec "a", "1", nil, "lib/a.rb" b = util_spec "b", "1", nil, "lib/b.rb" c = util_spec "c", "1", nil, "lib/c.rb" @@ -1571,7 +1554,7 @@ class TestGem < Gem::TestCase end def test_looks_for_gemdeps_files_automatically_on_start - util_clear_gems a = util_spec "a", "1", nil, "lib/a.rb" b = util_spec "b", "1", nil, "lib/b.rb" @@ -1607,7 +1590,7 @@ class TestGem < Gem::TestCase end def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir - util_clear_gems a = util_spec "a", "1", nil, "lib/a.rb" b = util_spec "b", "1", nil, "lib/b.rb" @@ -1674,33 +1657,6 @@ class TestGem < Gem::TestCase assert_nil Gem.find_unresolved_default_spec("README") end - def test_default_gems_use_full_paths - begin - if defined?(RUBY_ENGINE) - engine = RUBY_ENGINE - Object.send :remove_const, :RUBY_ENGINE - end - Object.const_set :RUBY_ENGINE, 'ruby' - - refute Gem.default_gems_use_full_paths? - ensure - Object.send :remove_const, :RUBY_ENGINE - Object.const_set :RUBY_ENGINE, engine if engine - end - - begin - if defined?(RUBY_ENGINE) - engine = RUBY_ENGINE - Object.send :remove_const, :RUBY_ENGINE - end - Object.const_set :RUBY_ENGINE, 'jruby' - assert Gem.default_gems_use_full_paths? - ensure - Object.send :remove_const, :RUBY_ENGINE - Object.const_set :RUBY_ENGINE, engine if engine - end - end - def test_use_gemdeps gem_deps_file = 'gem.deps.rb'.untaint spec = util_spec 'a', 1 @@ -281,7 +281,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase end def test_build_signed_gem - skip 'openssl is missing' unless defined?(OpenSSL::SSL) trust_dir = Gem::Security.trust_dir @@ -308,7 +308,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase end def test_build_signed_gem_with_cert_expiration_length_days - skip 'openssl is missing' unless defined?(OpenSSL::SSL) gem_path = File.join Gem.user_home, ".gem" Dir.mkdir gem_path @@ -352,7 +352,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase end def test_build_auto_resign_cert - skip 'openssl is missing' unless defined?(OpenSSL::SSL) gem_path = File.join Gem.user_home, ".gem" Dir.mkdir gem_path @@ -389,7 +389,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase output = @ui.output.split "\n" assert_equal "INFO: Your certificate has expired, trying to re-sign it...", output.shift assert_equal "INFO: Your cert: #{tmp_expired_cert_file } has been auto re-signed with the key: #{tmp_private_key_file}", output.shift - assert_match /INFO: Your expired cert will be located at: .+\Wgem-public_cert\.pem\.expired\.[0-9]+/, output.shift end end @@ -6,6 +6,10 @@ unless defined?(OpenSSL::SSL) warn 'Skipping `gem cert` tests. openssl not found.' end class TestGemCommandsCertCommand < Gem::TestCase ALTERNATE_CERT = load_cert 'alternate' @@ -793,4 +797,4 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis e.message end -end if defined?(OpenSSL::SSL) @@ -459,7 +459,28 @@ pl (1 i386-linux) EOF assert_equal expected, @stub_ui.output - assert_equal "WARNING: prereleases are always shown locally\n", @stub_ui.error end def test_execute_remote @@ -569,7 +590,7 @@ pl (1 i386-linux) @cmd.options[:domain] = :remote use_ui @stub_ui do - @cmd.send :show_gems, /a/i, false end assert_match %r%^a %, @stub_ui.output @@ -189,7 +189,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase assert_path_exists File.join(bin_dir, "#{e}.bat") end - assert_path_exists File.join bin_dir, e end default_dir = Gem::Specification.default_specifications_dir @@ -323,4 +323,4 @@ class TestGemCommandsSetupCommand < Gem::TestCase @ui.outs.set_encoding @default_external if @default_external end -end @@ -7,11 +7,17 @@ class TestGemCommandsSourcesCommand < Gem::TestCase def setup super - spec_fetcher - @cmd = Gem::Commands::SourcesCommand.new @new_repo = "http://beta-gems.example.com" end def test_initialize_proxy @@ -69,6 +75,8 @@ class TestGemCommandsSourcesCommand < Gem::TestCase end def test_execute_add_nonexistent_source uri = "http://beta-gems.example.com/specs.#{@marshal_version}.gz" @fetcher.data[uri] = proc do raise Gem::RemoteFetcher::FetchError.new('it died', uri) @@ -92,6 +100,8 @@ Error fetching http://beta-gems.example.com: end def test_execute_add_redundant_source @cmd.handle_options %W[--add #{@gem_repo}] use_ui @ui do @@ -109,6 +119,8 @@ source #{@gem_repo} already present in the cache end def test_execute_add_redundant_source_trailing_slash # Remove pre-existing gem source (w/ slash) repo_with_slash = "http://gems.example.com/" @cmd.handle_options %W[--remove #{repo_with_slash}] @@ -266,6 +278,8 @@ beta-gems.example.com is not a URI end def test_execute_remove_no_network @cmd.handle_options %W[--remove #{@gem_repo}] @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do @@ -6,19 +6,13 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase def setup super - common_installer_setup - - build_rake_in do - use_ui @ui do - @installer.install - end - end - @cmd = Gem::Commands::UninstallCommand.new @executable = File.join(@gemhome, 'bin', 'executable') end def test_execute_all_named util_make_gems default = new_default_spec 'default', '1' @@ -48,6 +42,8 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_dependency_order c = quick_gem 'c' do |spec| spec.add_dependency 'a' end @@ -76,15 +72,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_removes_executable - ui = Gem::MockGemUi.new - - util_setup_gem ui - - build_rake_in do - use_ui ui do - @installer.install - end - end if win_platform? assert File.exist?(@executable) @@ -113,12 +101,14 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_removes_formatted_executable FileUtils.rm_f @executable # Wish this didn't happen in #setup Gem::Installer.exec_format = 'foo-%s-bar' - @installer.format_executable = true - @installer.install formatted_executable = File.join @gemhome, 'bin', 'foo-executable-bar' assert_equal true, File.exist?(formatted_executable) @@ -137,11 +127,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase @gem = File.join @tempdir, @spec.file_name FileUtils.touch @gem - util_setup_gem build_rake_in do use_ui @ui do - @installer.install end end @@ -157,10 +147,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_with_version_leaves_non_matching_versions ui = Gem::MockGemUi.new util_make_gems - util_setup_gem ui assert_equal 3, Gem::Specification.find_all_by_name('a').length @@ -178,10 +169,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_with_version_specified_as_colon ui = Gem::MockGemUi.new "y\n" util_make_gems - util_setup_gem ui assert_equal 3, Gem::Specification.find_all_by_name('a').length @@ -254,6 +246,8 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_with_force_and_without_version_uninstalls_everything ui = Gem::MockGemUi.new "y\n" a_1, = util_gem 'a', 1 @@ -262,8 +256,6 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase a_3a, = util_gem 'a', '3.a' install_gem a_3a - util_setup_gem ui - assert_equal 3, Gem::Specification.find_all_by_name('a').length @cmd.options[:force] = true @@ -279,10 +271,11 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_with_force_ignores_dependencies ui = Gem::MockGemUi.new util_make_gems - util_setup_gem ui assert Gem::Specification.find_all_by_name('dep_x').length > 0 assert Gem::Specification.find_all_by_name('x').length > 0 @@ -359,20 +352,22 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_handle_options_vendor - use_ui @ui do - @cmd.handle_options %w[--vendor] - end - assert @cmd.options[:vendor] - assert_equal Gem.vendor_dir, @cmd.options[:install_dir] - assert_empty @ui.output - expected = <<-EXPECTED WARNING: Use your OS package manager to uninstall vendor gems - EXPECTED - assert_match expected, @ui.error end def test_execute_two_version @@ -395,21 +390,17 @@ WARNING: Use your OS package manager to uninstall vendor gems end def test_handle_options_vendor_missing - orig_vendordir = RbConfig::CONFIG['vendordir'] - RbConfig::CONFIG.delete 'vendordir' - - e = assert_raises OptionParser::InvalidOption do - @cmd.handle_options %w[--vendor] - end - - assert_equal 'invalid option: --vendor your platform is not supported', - e.message - refute @cmd.options[:vendor] - refute @cmd.options[:install_dir] - ensure - RbConfig::CONFIG['vendordir'] = orig_vendordir end def test_execute_with_gem_not_installed @@ -425,6 +416,8 @@ WARNING: Use your OS package manager to uninstall vendor gems end def test_execute_with_gem_uninstall_error util_make_gems @cmd.options[:args] = %w[a] @@ -451,4 +444,17 @@ WARNING: Use your OS package manager to uninstall vendor gems assert_match %r!Error: unable to successfully uninstall '#{@spec.name}'!, @ui.error end end @@ -504,25 +504,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_equal '--prefix', arguments.shift assert_equal Gem.prefix, arguments.shift - assert_equal '--no-rdoc', arguments.shift - assert_equal '--no-ri', arguments.shift assert_equal '--previous-version', arguments.shift assert_equal Gem::VERSION, arguments.shift assert_empty arguments end - def test_update_rubygems_arguments_1_8_x - @cmd.options[:system] = '1.8.26' - - arguments = @cmd.update_rubygems_arguments - - assert_equal '--prefix', arguments.shift - assert_equal Gem.prefix, arguments.shift - assert_equal '--no-rdoc', arguments.shift - assert_equal '--no-ri', arguments.shift - assert_empty arguments - end - def test_explain spec_fetcher do |fetcher| fetcher.download 'a', 2 @@ -45,7 +45,6 @@ class TestGemDependencyInstaller < Gem::TestCase s.add_development_dependency 'c' end - util_clear_gems util_reset_gems end @@ -133,7 +132,6 @@ class TestGemDependencyInstaller < Gem::TestCase p1a, gem = util_gem 'a', '10.a' util_setup_spec_fetcher(p1a, @a1, @a1_pre) - util_clear_gems p1a_data = Gem.read_binary(gem) @@ -172,7 +170,6 @@ class TestGemDependencyInstaller < Gem::TestCase p1a, gem = util_gem 'p', '1.a' util_setup_spec_fetcher(p1a) - util_clear_gems p1a_data = Gem.read_binary(gem) @@ -192,7 +189,6 @@ class TestGemDependencyInstaller < Gem::TestCase util_setup_gems util_setup_spec_fetcher(@a1, @a1_pre) - util_clear_gems p1a_data = Gem.read_binary(@a1_gem) @@ -213,8 +209,6 @@ class TestGemDependencyInstaller < Gem::TestCase s.add_dependency 'b' end - util_clear_gems - FileUtils.mv @a1_gem, @tempdir FileUtils.mv @b1_gem, @tempdir FileUtils.mv e1_gem, @tempdir @@ -575,8 +569,6 @@ class TestGemDependencyInstaller < Gem::TestCase s.add_dependency 'a' end - util_clear_gems - FileUtils.mv @a1_gem, @tempdir FileUtils.mv @b1_gem, @tempdir FileUtils.mv b2_gem, @tempdir @@ -877,8 +869,6 @@ class TestGemDependencyInstaller < Gem::TestCase si = util_setup_spec_fetcher @a1, a2_o - util_clear_gems - @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml a1_data = nil @@ -1274,8 +1264,6 @@ class TestGemDependencyInstaller < Gem::TestCase util_setup_spec_fetcher(*[@a1, @a1_pre, @b1, @c1_pre, @d1, @d2, @x1_m, @x1_o, @w1, @y1, @y1_1_p, @z1].compact) - - util_clear_gems end end @@ -7,8 +7,6 @@ class TestGemDependencyList < Gem::TestCase def setup super - util_clear_gems - @deplist = Gem::DependencyList.new # TODO: switch to util_spec @@ -124,8 +122,6 @@ class TestGemDependencyList < Gem::TestCase end def test_ok_eh - util_clear_gems - assert @deplist.ok?, 'no dependencies' @deplist.add @b2 @@ -138,8 +134,6 @@ class TestGemDependencyList < Gem::TestCase end def test_why_not_ok_eh - util_clear_gems - assert_equal({}, @deplist.why_not_ok?) @deplist.add @b2 @@ -229,8 +223,6 @@ class TestGemDependencyList < Gem::TestCase end def test_remove_by_name - util_clear_gems - @deplist.add @a1, @b2 @deplist.remove_by_name "a-1" @@ -329,4 +329,4 @@ install: assert_equal %w[--with-foo-dir=/nonexistent], builder.build_args end -end @@ -10,6 +10,8 @@ class TestGemExtCmakeBuilder < Gem::TestCase # Details: https://.com/rubygems/rubygems/issues/1270#issuecomment-177368340 skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform? system('cmake', out: IO::NULL, err: [:child, :out]) skip 'cmake not present' unless $?.success? @@ -18,6 +18,10 @@ class TestGemExtConfigureBuilder < Gem::TestCase end def test_self_build skip("test_self_build skipped on MS Windows (VC++)") if vc_windows? File.open File.join(@ext, './configure'), 'w' do |configure| @@ -45,6 +49,10 @@ class TestGemExtConfigureBuilder < Gem::TestCase end def test_self_build_fail skip("test_self_build_fail skipped on MS Windows (VC++)") if vc_windows? output = [] @@ -17,6 +17,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase end def test_class_build if vc_windows? && !nmake_found? skip("test_class_build skipped - nmake not found") end @@ -45,6 +49,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase end def test_class_build_rbconfig_make_prog configure_args do File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf| @@ -68,6 +76,10 @@ class TestGemExtExtConfBuilder < Gem::TestCase env_make = ENV.delete 'MAKE' ENV['MAKE'] = 'anothermake' configure_args '' do File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf| extconf.puts "require 'mkmf'\ncreate_makefile 'foo'" @@ -11,7 +11,6 @@ class TestGemIndexer < Gem::TestCase def setup super - util_clear_gems util_make_gems @d2_0 = util_spec 'd', '2.0' do |s| @@ -28,30 +27,23 @@ class TestGemIndexer < Gem::TestCase @default = new_default_spec 'default', 2 install_default_gems @default - @tempdir = File.join(@tempdir, 'indexer') - gems = File.join(@tempdir, 'gems') FileUtils.mkdir_p gems FileUtils.mv Dir[File.join(@gemhome, "cache", '*.gem')], gems - @indexer = Gem::Indexer.new(@tempdir) - end - - def teardown - super - - util_clear_gems - util_clear_default_gems end def test_initialize - assert_equal @tempdir, @indexer.dest_directory assert_match %r{#{Dir.mktmpdir('gem_generate_index').match(/.*-/)}}, @indexer.directory - indexer = Gem::Indexer.new @tempdir assert indexer.build_modern - indexer = Gem::Indexer.new @tempdir, :build_modern => true assert indexer.build_modern end @@ -100,7 +92,7 @@ class TestGemIndexer < Gem::TestCase @indexer.generate_index end - quickdir = File.join @tempdir, 'quick' marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" assert_directory_exists quickdir @@ -111,11 +103,11 @@ class TestGemIndexer < Gem::TestCase refute_indexed marshal_quickdir, File.basename(@c1_2.spec_file) - assert_indexed @tempdir, "specs.#{@marshal_version}" - assert_indexed @tempdir, "specs.#{@marshal_version}.gz" - assert_indexed @tempdir, "latest_specs.#{@marshal_version}" - assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" end def test_generate_index_modern @@ -125,12 +117,12 @@ class TestGemIndexer < Gem::TestCase @indexer.generate_index end - refute_indexed @tempdir, 'yaml' - refute_indexed @tempdir, 'yaml.Z' - refute_indexed @tempdir, "Marshal.#{@marshal_version}" - refute_indexed @tempdir, "Marshal.#{@marshal_version}.Z" - quickdir = File.join @tempdir, 'quick' marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" assert_directory_exists quickdir, 'quickdir should be directory' @@ -156,11 +148,11 @@ class TestGemIndexer < Gem::TestCase refute_indexed quickdir, "#{File.basename(@c1_2.spec_file)}" refute_indexed marshal_quickdir, "#{File.basename(@c1_2.spec_file)}" - assert_indexed @tempdir, "specs.#{@marshal_version}" - assert_indexed @tempdir, "specs.#{@marshal_version}.gz" - assert_indexed @tempdir, "latest_specs.#{@marshal_version}" - assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" end def test_generate_index_modern_back_to_back @@ -170,13 +162,13 @@ class TestGemIndexer < Gem::TestCase @indexer.generate_index end - @indexer = Gem::Indexer.new @tempdir @indexer.build_modern = true use_ui @ui do @indexer.generate_index end - quickdir = File.join @tempdir, 'quick' marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" assert_directory_exists quickdir @@ -185,11 +177,11 @@ class TestGemIndexer < Gem::TestCase assert_indexed marshal_quickdir, "#{File.basename(@a1.spec_file)}.rz" assert_indexed marshal_quickdir, "#{File.basename(@a2.spec_file)}.rz" - assert_indexed @tempdir, "specs.#{@marshal_version}" - assert_indexed @tempdir, "specs.#{@marshal_version}.gz" - assert_indexed @tempdir, "latest_specs.#{@marshal_version}" - assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz" end def test_generate_index_ui @@ -215,7 +207,7 @@ class TestGemIndexer < Gem::TestCase @indexer.generate_index end - specs_path = File.join @tempdir, "specs.#{@marshal_version}" specs_dump = Gem.read_binary specs_path specs = Marshal.load specs_dump @@ -252,7 +244,7 @@ class TestGemIndexer < Gem::TestCase @indexer.generate_index end - latest_specs_path = File.join @tempdir, "latest_specs.#{@marshal_version}" latest_specs_dump = Gem.read_binary latest_specs_path latest_specs = Marshal.load latest_specs_dump @@ -282,7 +274,7 @@ class TestGemIndexer < Gem::TestCase @indexer.generate_index end - prerelease_specs_path = File.join @tempdir, "prerelease_specs.#{@marshal_version}" prerelease_specs_dump = Gem.read_binary prerelease_specs_path prerelease_specs = Marshal.load prerelease_specs_dump @@ -311,7 +303,7 @@ class TestGemIndexer < Gem::TestCase @indexer.generate_index end - quickdir = File.join @tempdir, 'quick' marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}" assert_directory_exists quickdir @@ -325,7 +317,7 @@ class TestGemIndexer < Gem::TestCase util_build_gem @d2_1_a @d2_1_a_tuple = [@d2_1_a.name, @d2_1_a.version, @d2_1_a.original_platform] - gems = File.join @tempdir, 'gems' FileUtils.mv @d2_1.cache_file, gems FileUtils.mv @d2_1_a.cache_file, gems @@ -26,10 +26,11 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase -f -i /install_to -w - --vendor --post-install-message ] args.concat %w[-P HighSecurity] if defined?(OpenSSL::SSL) assert @cmd.handles?(args) @@ -111,6 +112,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase end def test_user_install_enabled @cmd.handle_options %w[--user-install] assert @cmd.options[:user_install] @@ -122,6 +130,13 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase end def test_user_install_disabled_read_only if win_platform? skip('test_user_install_disabled_read_only test skipped on MS Windows') elsif Process.uid.zero? @@ -145,28 +160,26 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase end def test_vendor - @cmd.handle_options %w[--vendor] - assert @cmd.options[:vendor] - assert_equal Gem.vendor_dir, @cmd.options[:install_dir] end def test_vendor_missing - orig_vendordir = RbConfig::CONFIG['vendordir'] - RbConfig::CONFIG.delete 'vendordir' - - e = assert_raises OptionParser::InvalidOption do - @cmd.handle_options %w[--vendor] - end - - assert_equal 'invalid option: --vendor your platform is not supported', - e.message - refute @cmd.options[:vendor] - refute @cmd.options[:install_dir] - ensure - RbConfig::CONFIG['vendordir'] = orig_vendordir end def test_post_install_message_no @@ -22,11 +22,6 @@ class TestGemInstaller < Gem::InstallerTestCase super common_installer_setup - if (self.class.method_defined?(:__name__) ? __name__ : name) =~ /\Atest_install(_|\Z)/ - FileUtils.rm_r @spec.gem_dir - FileUtils.rm_r @user_spec.gem_dir - end - @config = Gem.configuration end @@ -39,6 +34,8 @@ class TestGemInstaller < Gem::InstallerTestCase end def test_app_script_text util_make_exec @spec, '' expected = <<-EOF @@ -71,12 +68,14 @@ load Gem.bin_path("a", "executable", version) end EOF - wrapper = @installer.app_script_text 'executable' assert_equal expected, wrapper end def test_check_executable_overwrite - @installer.generate_bin @spec = Gem::Specification.new do |s| s.files = ['lib/code.rb'] @@ -88,9 +87,9 @@ end end util_make_exec - @installer.gem_dir = @spec.gem_dir - @installer.wrappers = true - @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' assert_path_exists installed_exec @@ -100,6 +99,8 @@ end end def test_check_executable_overwrite_default_bin_dir if defined?(RUBY_FRAMEWORK_VERSION) orig_RUBY_FRAMEWORK_VERSION = RUBY_FRAMEWORK_VERSION Object.send :remove_const, :RUBY_FRAMEWORK_VERSION @@ -112,7 +113,7 @@ end ui = Gem::MockGemUi.new "n\n" use_ui ui do e = assert_raises Gem::InstallError do - @installer.generate_bin end conflicted = File.join @gemhome, 'bin', 'executable' @@ -130,7 +131,9 @@ end end def test_check_executable_overwrite_format_executable - @installer.generate_bin @spec = Gem::Specification.new do |s| s.files = ['lib/code.rb'] @@ -153,11 +156,11 @@ gem 'other', version util_make_exec Gem::Installer.exec_format = 'foo-%s-bar' - @installer.gem_dir = @spec.gem_dir - @installer.wrappers = true - @installer.format_executable = true - @installer.generate_bin # should not raise installed_exec = File.join util_inst_bindir, 'foo-executable-bar' assert_path_exists installed_exec @@ -169,13 +172,15 @@ gem 'other', version end def test_check_executable_overwrite_other_gem util_conflict_executable true ui = Gem::MockGemUi.new "n\n" use_ui ui do e = assert_raises Gem::InstallError do - @installer.generate_bin end assert_equal '"executable" from a conflicts with installed executable from conflict', @@ -184,11 +189,13 @@ gem 'other', version end def test_check_executable_overwrite_other_gem_force util_conflict_executable true - @installer.wrappers = true - @installer.force = true - @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' assert_path_exists installed_exec @@ -198,10 +205,12 @@ gem 'other', version end def test_check_executable_overwrite_other_non_gem util_conflict_executable false - @installer.wrappers = true - @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' assert_path_exists installed_exec @@ -211,7 +220,9 @@ gem 'other', version end unless Gem.win_platform? def test_check_that_user_bin_dir_is_in_path - bin_dir = @installer.bin_dir if Gem.win_platform? bin_dir = bin_dir.downcase.gsub(File::SEPARATOR, File::ALT_SEPARATOR) @@ -221,7 +232,7 @@ gem 'other', version ENV['PATH'], [ENV['PATH'], bin_dir].join(File::PATH_SEPARATOR) use_ui @ui do - @installer.check_that_user_bin_dir_is_in_path end assert_empty @ui.error @@ -235,10 +246,11 @@ gem 'other', version orig_PATH, ENV['PATH'] = ENV['PATH'], [ENV['PATH'], '~/bin'].join(File::PATH_SEPARATOR) - @installer.bin_dir.replace File.join @userhome, 'bin' use_ui @ui do - @installer.check_that_user_bin_dir_is_in_path end assert_empty @ui.error @@ -247,11 +259,13 @@ gem 'other', version end def test_check_that_user_bin_dir_is_in_path_not_in_path use_ui @ui do - @installer.check_that_user_bin_dir_is_in_path end - expected = @installer.bin_dir if Gem.win_platform? expected = expected.downcase.gsub(File::SEPARATOR, File::ALT_SEPARATOR) @@ -261,14 +275,16 @@ gem 'other', version end def test_ensure_dependency util_spec 'a' dep = Gem::Dependency.new 'a', '>= 2' - assert @installer.ensure_dependency(@spec, dep) dep = Gem::Dependency.new 'b', '> 2' e = assert_raises Gem::InstallError do - @installer.ensure_dependency @spec, dep end assert_equal 'a requires b (> 2)', e.message @@ -305,26 +321,30 @@ gem 'other', version end def test_extract_files - @installer.extract_files assert_path_exists File.join @spec.gem_dir, 'bin/executable' end def test_generate_bin_bindir - @installer.wrappers = true @spec.executables = %w[executable] @spec.bindir = 'bin' - exec_file = @installer.formatted_program_filename 'executable' exec_path = File.join @spec.gem_dir, exec_file File.open exec_path, 'w' do |f| f.puts '#!/usr/bin/ruby' end - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin assert_directory_exists util_inst_bindir installed_exec = File.join(util_inst_bindir, 'executable') @@ -362,11 +382,13 @@ gem 'other', version end def test_generate_bin_script - @installer.wrappers = true util_make_exec - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin assert_directory_exists util_inst_bindir installed_exec = File.join util_inst_bindir, 'executable' assert_path_exists installed_exec @@ -377,13 +399,15 @@ gem 'other', version end def test_generate_bin_script_format - @installer.format_executable = true - @installer.wrappers = true util_make_exec - @installer.gem_dir = @spec.gem_dir Gem::Installer.exec_format = 'foo-%s-bar' - @installer.generate_bin assert_directory_exists util_inst_bindir installed_exec = File.join util_inst_bindir, 'foo-executable-bar' assert_path_exists installed_exec @@ -392,12 +416,14 @@ gem 'other', version end def test_generate_bin_script_format_disabled - @installer.wrappers = true util_make_exec - @installer.gem_dir = @spec.gem_dir Gem::Installer.exec_format = 'foo-%s-bar' - @installer.generate_bin assert_directory_exists util_inst_bindir installed_exec = File.join util_inst_bindir, 'executable' assert_path_exists installed_exec @@ -406,7 +432,9 @@ gem 'other', version end def test_generate_bin_script_install_dir - @installer.wrappers = true gem_dir = File.join("#{@gemhome}2", "gems", @spec.full_name) gem_bindir = File.join gem_dir, 'bin' @@ -415,11 +443,11 @@ gem 'other', version f.puts "#!/bin/ruby" end - @installer.gem_home = "#{@gemhome}2" - @installer.gem_dir = gem_dir - @installer.bin_dir = File.join "#{@gemhome}2", 'bin' - @installer.generate_bin installed_exec = File.join("#{@gemhome}2", "bin", 'executable') assert_path_exists installed_exec @@ -430,16 +458,20 @@ gem 'other', version end def test_generate_bin_script_no_execs - util_execless - @installer.wrappers = true - @installer.generate_bin refute_path_exists util_inst_bindir, 'bin dir was created when not needed' end def test_generate_bin_script_no_perms - @installer.wrappers = true util_make_exec Dir.mkdir util_inst_bindir @@ -452,7 +484,7 @@ gem 'other', version FileUtils.chmod 0000, util_inst_bindir assert_raises Gem::FilePermissionError do - @installer.generate_bin end end ensure @@ -460,7 +492,9 @@ gem 'other', version end def test_generate_bin_script_no_shebang - @installer.wrappers = true @spec.executables = %w[executable] gem_dir = File.join @gemhome, 'gems', @spec.full_name @@ -470,7 +504,7 @@ gem 'other', version f.puts "blah blah blah" end - @installer.generate_bin installed_exec = File.join @gemhome, 'bin', 'executable' assert_path_exists installed_exec @@ -483,9 +517,11 @@ gem 'other', version end def test_generate_bin_script_wrappers - @installer.wrappers = true util_make_exec - @installer.gem_dir = @spec.gem_dir installed_exec = File.join(util_inst_bindir, 'executable') real_exec = File.join @spec.gem_dir, 'bin', 'executable' @@ -496,7 +532,7 @@ gem 'other', version FileUtils.ln_s real_exec, installed_exec end - @installer.generate_bin assert_directory_exists util_inst_bindir assert_path_exists installed_exec assert_equal mask, File.stat(installed_exec).mode unless win_platform? @@ -510,11 +546,13 @@ gem 'other', version def test_generate_bin_symlink return if win_platform? #Windows FS do not support symlinks - @installer.wrappers = false util_make_exec - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin assert_directory_exists util_inst_bindir installed_exec = File.join util_inst_bindir, 'executable' assert_equal true, File.symlink?(installed_exec) @@ -523,18 +561,22 @@ gem 'other', version end def test_generate_bin_symlink_no_execs - util_execless - @installer.wrappers = false - @installer.generate_bin refute_path_exists util_inst_bindir end def test_generate_bin_symlink_no_perms - @installer.wrappers = false util_make_exec - @installer.gem_dir = @spec.gem_dir Dir.mkdir util_inst_bindir @@ -546,7 +588,7 @@ gem 'other', version FileUtils.chmod 0000, util_inst_bindir assert_raises Gem::FilePermissionError do - @installer.generate_bin end end ensure @@ -556,11 +598,13 @@ gem 'other', version def test_generate_bin_symlink_update_newer return if win_platform? #Windows FS do not support symlinks - @installer.wrappers = false util_make_exec - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin installed_exec = File.join(util_inst_bindir, 'executable') assert_equal(File.join(@spec.gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) @@ -575,8 +619,8 @@ gem 'other', version end util_make_exec - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin installed_exec = File.join(util_inst_bindir, 'executable') assert_equal(@spec.bin_file('executable'), File.readlink(installed_exec), @@ -586,11 +630,13 @@ gem 'other', version def test_generate_bin_symlink_update_older return if !symlink_supported? - @installer.wrappers = false util_make_exec - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin installed_exec = File.join(util_inst_bindir, 'executable') assert_equal(File.join(@spec.gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) @@ -607,10 +653,10 @@ gem 'other', version util_make_exec one = @spec.dup one.version = 1 - @installer = Gem::Installer.for_spec spec - @installer.gem_dir = one.gem_dir - @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' expected = File.join @spec.gem_dir, 'bin', 'executable' @@ -622,11 +668,13 @@ gem 'other', version def test_generate_bin_symlink_update_remove_wrapper return if !symlink_supported? - @installer.wrappers = true util_make_exec - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' assert_path_exists installed_exec @@ -642,10 +690,10 @@ gem 'other', version util_make_exec util_installer @spec, @gemhome - @installer.wrappers = false - @installer.gem_dir = @spec.gem_dir - @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' assert_equal(@spec.bin_file('executable'), @@ -659,12 +707,15 @@ gem 'other', version old_alt_separator = File::ALT_SEPARATOR File.__send__(:remove_const, :ALT_SEPARATOR) File.const_set(:ALT_SEPARATOR, '\\') - @installer.wrappers = false util_make_exec - @installer.gem_dir = @spec.gem_dir use_ui @ui do - @installer.generate_bin end assert_directory_exists util_inst_bindir @@ -690,10 +741,12 @@ gem 'other', version def test_generate_bin_uses_default_shebang return if !symlink_supported? - @installer.wrappers = true util_make_exec - @installer.generate_bin default_shebang = Gem.ruby shebang_line = open("#{@gemhome}/bin/executable") { |f| f.readlines.first } @@ -719,6 +772,8 @@ gem 'other', version end def test_initialize_user_install installer = Gem::Installer.at @gem, :user_install => true assert_equal File.join(Gem.user_dir, 'gems', @spec.full_name), @@ -727,6 +782,8 @@ gem 'other', version end def test_initialize_user_install_bin_dir installer = Gem::Installer.at @gem, :user_install => true, :bin_dir => @tempdir @@ -736,9 +793,7 @@ gem 'other', version end def test_install - Dir.mkdir util_inst_bindir - util_setup_gem - util_clear_gems gemdir = File.join @gemhome, 'gems', @spec.full_name cache_file = File.join @gemhome, 'cache', @spec.file_name @@ -746,13 +801,13 @@ gem 'other', version rakefile = File.join gemdir, 'ext', 'a', 'Rakefile' spec_file = File.join @gemhome, 'specifications', @spec.spec_name - Gem.pre_install do |installer| refute_path_exists cache_file, 'cache file must not exist yet' refute_path_exists spec_file, 'spec file must not exist yet' true end - Gem.post_build do |installer| assert_path_exists gemdir, 'gem install dir must exist' assert_path_exists rakefile, 'gem executable must exist' refute_path_exists stub_exe, 'gem executable must not exist' @@ -760,7 +815,7 @@ gem 'other', version true end - Gem.post_install do |installer| assert_path_exists cache_file, 'cache file must exist' assert_path_exists spec_file, 'spec file must exist' end @@ -768,7 +823,7 @@ gem 'other', version @newspec = nil build_rake_in do use_ui @ui do - @newspec = @installer.install end end @@ -786,29 +841,25 @@ gem 'other', version assert_path_exists rakefile - spec_file = File.join(@gemhome, 'specifications', @spec.spec_name) - assert_equal spec_file, @newspec.loaded_from assert_path_exists spec_file - assert_same @installer, @post_build_hook_arg - assert_same @installer, @post_install_hook_arg - assert_same @installer, @pre_install_hook_arg end def test_install_creates_working_binstub - Dir.mkdir util_inst_bindir - util_setup_gem - util_clear_gems - @installer.wrappers = true gemdir = File.join @gemhome, 'gems', @spec.full_name @newspec = nil build_rake_in do use_ui @ui do - @newspec = @installer.install end end @@ -822,11 +873,10 @@ gem 'other', version end def test_conflicting_binstubs - Dir.mkdir util_inst_bindir - util_clear_gems # build old version that has a bin file - util_setup_gem do |spec| File.open File.join('bin', 'executable'), 'w' do |f| f.puts "require 'code'" end @@ -835,17 +885,17 @@ gem 'other', version end end - @installer.wrappers = true build_rake_in do use_ui @ui do - @newspec = @installer.install end end - old_bin_file = File.join @installer.bin_dir, 'executable' # build new version that doesn't have a bin file - util_setup_gem do |spec| FileUtils.rm File.join('bin', 'executable') spec.files.delete File.join('bin', 'executable') spec.executables.delete 'executable' @@ -857,7 +907,7 @@ gem 'other', version build_rake_in do use_ui @ui do - @newspec = @installer.install end end @@ -871,16 +921,14 @@ gem 'other', version end def test_install_creates_binstub_that_understand_version - Dir.mkdir util_inst_bindir - util_setup_gem - util_clear_gems - @installer.wrappers = true @newspec = nil build_rake_in do use_ui @ui do - @newspec = @installer.install end end @@ -902,23 +950,21 @@ gem 'other', version end def test_install_creates_binstub_that_prefers_user_installed_gem_to_default - Dir.mkdir util_inst_bindir - install_default_gems new_default_spec('default', '2') - util_setup_gem do |spec| spec.name = 'default' spec.version = '2' end util_clear_gems - @installer.wrappers = true @newspec = nil build_rake_in do use_ui @ui do - @newspec = @installer.install end end @@ -932,16 +978,14 @@ gem 'other', version end def test_install_creates_binstub_that_dont_trust_encoding - Dir.mkdir util_inst_bindir - util_setup_gem - util_clear_gems - @installer.wrappers = true @newspec = nil build_rake_in do use_ui @ui do - @newspec = @installer.install end end @@ -964,20 +1008,19 @@ gem 'other', version end def test_install_with_no_prior_files - Dir.mkdir util_inst_bindir - util_clear_gems - util_setup_gem build_rake_in do use_ui @ui do - assert_equal @spec, @installer.install end end gemdir = File.join(@gemhome, 'gems', @spec.full_name) assert_path_exists File.join gemdir, 'lib', 'code.rb' - util_setup_gem # Morph spec to have lib/other.rb instead of code.rb and recreate @spec.files = File.join('lib', 'other.rb') Dir.chdir @tempdir do @@ -990,10 +1033,10 @@ gem 'other', version Gem::Package.build @spec end end - @installer = Gem::Installer.at @gem build_rake_in do use_ui @ui do - assert_equal @spec, @installer.install end end @@ -1013,12 +1056,14 @@ gem 'other', version end def test_install_missing_dirs FileUtils.rm_f File.join(Gem.dir, 'cache') FileUtils.rm_f File.join(Gem.dir, 'doc') FileUtils.rm_f File.join(Gem.dir, 'specifications') use_ui @ui do - @installer.install end assert_directory_exists File.join(Gem.dir, 'cache') @@ -1030,7 +1075,7 @@ gem 'other', version end def test_install_post_build_false - util_clear_gems Gem.post_build do false @@ -1038,7 +1083,7 @@ gem 'other', version use_ui @ui do e = assert_raises Gem::InstallError do - @installer.install end location = "#{__FILE__}:#{__LINE__ - 9}" @@ -1054,14 +1099,14 @@ gem 'other', version end def test_install_post_build_nil - util_clear_gems Gem.post_build do nil end use_ui @ui do - @installer.install end spec_file = File.join @gemhome, 'specifications', @spec.spec_name @@ -1072,7 +1117,7 @@ gem 'other', version end def test_install_pre_install_false - util_clear_gems Gem.pre_install do false @@ -1080,7 +1125,7 @@ gem 'other', version use_ui @ui do e = assert_raises Gem::InstallError do - @installer.install end location = "#{__FILE__}:#{__LINE__ - 9}" @@ -1093,14 +1138,14 @@ gem 'other', version end def test_install_pre_install_nil - util_clear_gems Gem.pre_install do nil end use_ui @ui do - @installer.install end spec_file = File.join @gemhome, 'specifications', @spec.spec_name @@ -1108,26 +1153,28 @@ gem 'other', version end def test_install_with_message @spec.post_install_message = 'I am a shiny gem!' use_ui @ui do path = Gem::Package.build @spec - @installer = Gem::Installer.at path - @installer.install end assert_match %r|I am a shiny gem!|, @ui.output end def test_install_with_skipped_message @spec.post_install_message = 'I am a shiny gem!' use_ui @ui do path = Gem::Package.build @spec - @installer = Gem::Installer.at path, :post_install_message => false - @installer.install end refute_match %r|I am a shiny gem!|, @ui.output @@ -1136,6 +1183,7 @@ gem 'other', version def test_install_extension_dir gemhome2 = "#{@gemhome}2" @spec.extensions << "extconf.rb" write_file File.join(@tempdir, "extconf.rb") do |io| io.write <<-RUBY @@ -1159,6 +1207,8 @@ gem 'other', version end def test_install_extension_dir_is_removed_on_reinstall @spec.extensions << "extconf.rb" write_file File.join(@tempdir, "extconf.rb") do |io| io.write <<-RUBY @@ -1194,6 +1244,7 @@ gem 'other', version end def test_install_user_extension_dir @spec.extensions << "extconf.rb" write_file File.join(@tempdir, "extconf.rb") do |io| io.write <<-RUBY @@ -1223,6 +1274,9 @@ gem 'other', version end def test_find_lib_file_after_install @spec.extensions << "extconf.rb" write_file File.join(@tempdir, "extconf.rb") do |io| io.write <<-RUBY @@ -1266,6 +1320,9 @@ gem 'other', version end def test_install_extension_and_script @spec.extensions << "extconf.rb" write_file File.join(@tempdir, "extconf.rb") do |io| io.write <<-RUBY @@ -1296,14 +1353,17 @@ gem 'other', version use_ui @ui do path = Gem::Package.build @spec - @installer = Gem::Installer.at path - @installer.install end assert_path_exists File.join @spec.gem_dir, rb assert_path_exists File.join @spec.gem_dir, rb2 end def test_install_extension_flat @spec.require_paths = ["."] @spec.extensions << "extconf.rb" @@ -1330,8 +1390,8 @@ gem 'other', version use_ui @ui do path = Gem::Package.build @spec - @installer = Gem::Installer.at path - @installer.install end assert_path_exists so rescue @@ -1350,49 +1410,56 @@ gem 'other', version end def test_installation_satisfies_dependency_eh util_spec 'a' dep = Gem::Dependency.new 'a', '>= 2' - assert @installer.installation_satisfies_dependency?(dep) dep = Gem::Dependency.new 'a', '> 2' - refute @installer.installation_satisfies_dependency?(dep) end def test_installation_satisfies_dependency_eh_development - @installer.options[:development] = true - @installer.options[:dev_shallow] = true util_spec 'a' dep = Gem::Dependency.new 'a', :development - assert @installer.installation_satisfies_dependency?(dep) end def test_pre_install_checks_dependencies @spec.add_dependency 'b', '> 5' - util_setup_gem use_ui @ui do assert_raises Gem::InstallError do - @installer.install end end end def test_pre_install_checks_dependencies_ignore @spec.add_dependency 'b', '> 5' - @installer.ignore_dependencies = true build_rake_in do use_ui @ui do - assert @installer.pre_install_checks end end end def test_pre_install_checks_dependencies_install_dir gemhome2 = "#{@gemhome}2" @spec.add_dependency 'd' quick_gem 'd', 2 @@ -1455,9 +1522,9 @@ gem 'other', version gem = File.join(@gemhome, 'cache', spec.file_name) use_ui @ui do - @installer = Gem::Installer.at gem e = assert_raises Gem::RuntimeRequirementNotMetError do - @installer.pre_install_checks end rgv = Gem::VERSION assert_equal "old_rubygems_required requires RubyGems version < 0. The current RubyGems version is #{rgv}. " + @@ -1477,9 +1544,9 @@ gem 'other', version gem = File.join(@gemhome, 'cache', spec.file_name) use_ui @ui do - @installer = Gem::Installer.at gem e = assert_raises Gem::InstallError do - @installer.pre_install_checks end assert_equal '#<Gem::Specification name=../malicious version=1> has an invalid name', e.message end @@ -1497,9 +1564,9 @@ gem 'other', version gem = File.join(@gemhome, 'cache', spec.file_name) use_ui @ui do - @installer = Gem::Installer.at gem e = assert_raises Gem::InstallError do - @installer.pre_install_checks end assert_equal "#<Gem::Specification name=malicious\n::Object.const_set(:FROM_EVAL, true)# version=1> has an invalid name", e.message end @@ -1519,9 +1586,9 @@ gem 'other', version gem = File.join(@gemhome, 'cache', spec.file_name) use_ui @ui do - @installer = Gem::Installer.at gem e = assert_raises Gem::InstallError do - @installer.pre_install_checks end assert_equal "#<Gem::Specification name=malicious version=1> has an invalid require_paths", e.message end @@ -1542,9 +1609,9 @@ gem 'other', version gem = File.join(@gemhome, 'cache', spec.file_name) use_ui @ui do - @installer = Gem::Installer.at gem e = assert_raises Gem::InstallError do - @installer.pre_install_checks end assert_equal "#<Gem::Specification name=malicious version=1> has an invalid extensions", e.message end @@ -1563,9 +1630,9 @@ gem 'other', version gem = File.join(@gemhome, 'cache', spec.file_name) use_ui @ui do - @installer = Gem::Installer.at gem e = assert_raises Gem::InstallError do - @installer.pre_install_checks end assert_equal "#<Gem::Specification name=malicious version=1> has an invalid specification_version", e.message end @@ -1584,75 +1651,90 @@ gem 'other', version gem = File.join(@gemhome, 'cache', spec.file_name) use_ui @ui do - @installer = Gem::Installer.at gem - @installer.ignore_dependencies = true e = assert_raises Gem::InstallError do - @installer.pre_install_checks end assert_equal "#<Gem::Specification name=malicious version=1> has an invalid dependencies", e.message end end def test_shebang util_make_exec @spec, "#!/usr/bin/ruby" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_process_options - assert_nil @installer.build_root - assert_equal File.join(@gemhome, 'bin'), @installer.bin_dir - assert_equal @gemhome, @installer.gem_home end def test_process_options_build_root build_root = File.join @tempdir, 'build_root' - @installer = Gem::Installer.at @gem, :build_root => build_root - assert_equal Pathname(build_root), @installer.build_root - assert_equal File.join(build_root, @gemhome, 'bin'), @installer.bin_dir - assert_equal File.join(build_root, @gemhome), @installer.gem_home end def test_shebang_arguments util_make_exec @spec, "#!/usr/bin/ruby -ws" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_empty util_make_exec @spec, '' - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env util_make_exec @spec, "#!/usr/bin/env ruby" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env_arguments util_make_exec @spec, "#!/usr/bin/env ruby -ws" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_env_shebang util_make_exec @spec, '' - @installer.env_shebang = true - shebang = @installer.shebang 'executable' env_shebang = "/usr/bin/env" unless Gem.win_platform? @@ -1661,54 +1743,68 @@ gem 'other', version end def test_shebang_nested util_make_exec @spec, "#!/opt/local/ruby/bin/ruby" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_nested_arguments util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version util_make_exec @spec, "#!/usr/bin/ruby18" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_arguments util_make_exec @spec, "#!/usr/bin/ruby18 -ws" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version_env util_make_exec @spec, "#!/usr/bin/env ruby18" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_env_arguments util_make_exec @spec, "#!/usr/bin/env ruby18 -ws" - shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_custom conf = Gem::ConfigFile.new [] conf[:custom_shebang] = 'test' @@ -1716,12 +1812,14 @@ gem 'other', version util_make_exec @spec, "#!/usr/bin/ruby" - shebang = @installer.shebang 'executable' assert_equal "#!test", shebang end def test_shebang_custom_with_expands bin_env = win_platform? ? '' : '/usr/bin/env' conf = Gem::ConfigFile.new [] conf[:custom_shebang] = '1 $env 2 $ruby 3 $exec 4 $name' @@ -1730,12 +1828,14 @@ gem 'other', version util_make_exec @spec, "#!/usr/bin/ruby" - shebang = @installer.shebang 'executable' assert_equal "#!1 #{bin_env} 2 #{Gem.ruby} 3 executable 4 a", shebang end def test_shebang_custom_with_expands_and_arguments bin_env = win_platform? ? '' : '/usr/bin/env' conf = Gem::ConfigFile.new [] conf[:custom_shebang] = '1 $env 2 $ruby 3 $exec' @@ -1744,18 +1844,18 @@ gem 'other', version util_make_exec @spec, "#!/usr/bin/ruby -ws" - shebang = @installer.shebang 'executable' assert_equal "#!1 #{bin_env} 2 #{Gem.ruby} -ws 3 executable", shebang end def test_unpack - util_setup_gem dest = File.join @gemhome, 'gems', @spec.full_name Gem::Deprecate.skip_during do - @installer.unpack dest end assert_path_exists File.join dest, 'lib', 'code.rb' @@ -1763,13 +1863,15 @@ gem 'other', version end def test_write_build_info_file refute_path_exists @spec.build_info_file - @installer.build_args = %w[ --with-libyaml-dir /usr/local/Cellar/libyaml/0.1.4 ] - @installer.write_build_info_file assert_path_exists @spec.build_info_file @@ -1779,14 +1881,17 @@ gem 'other', version end def test_write_build_info_file_empty refute_path_exists @spec.build_info_file - @installer.write_build_info_file refute_path_exists @spec.build_info_file end def test_write_build_info_file_install_dir installer = Gem::Installer.at @gem, :install_dir => "#{@gemhome}2" installer.build_args = %w[ @@ -1801,6 +1906,7 @@ gem 'other', version end def test_write_cache_file cache_file = File.join @gemhome, 'cache', @spec.file_name gem = File.join @gemhome, @spec.file_name @@ -1816,13 +1922,14 @@ gem 'other', version end def test_write_spec FileUtils.rm @spec.spec_file refute_path_exists @spec.spec_file - @installer = Gem::Installer.for_spec @spec - @installer.gem_home = @gemhome - @installer.write_spec assert_path_exists @spec.spec_file @@ -1834,15 +1941,16 @@ gem 'other', version end def test_write_spec_writes_cached_spec FileUtils.rm @spec.spec_file refute_path_exists @spec.spec_file @spec.files = %w[a.rb b.rb c.rb] - @installer = Gem::Installer.for_spec @spec - @installer.gem_home = @gemhome - @installer.write_spec # cached specs have no file manifest: @spec.files = [] @@ -1851,7 +1959,9 @@ gem 'other', version end def test_dir - assert_match %r!/gemhome/gems/a-2$!, @installer.dir end def test_default_gem_loaded_from @@ -1862,14 +1972,16 @@ gem 'other', version end def test_default_gem_without_wrappers FileUtils.rm_f File.join(Gem.dir, 'specifications') - @installer.wrappers = false - @installer.options[:install_as_default] = true - @installer.gem_dir = @spec.gem_dir use_ui @ui do - @installer.install end assert_directory_exists File.join(@spec.gem_dir, 'bin') @@ -1893,14 +2005,14 @@ gem 'other', version end def test_default_gem_with_wrappers - FileUtils.rm_f File.join(Gem.dir, 'specifications') - @installer.wrappers = true - @installer.options[:install_as_default] = true - @installer.gem_dir = @spec.gem_dir use_ui @ui do - @installer.install end assert_directory_exists util_inst_bindir @@ -1913,8 +2025,6 @@ gem 'other', version end def test_default_gem_with_exe_as_bindir - FileUtils.rm_f File.join(Gem.dir, 'specifications') - @spec = quick_gem 'c' do |spec| util_make_exec spec, '#!/usr/bin/ruby', 'exe' end @@ -1958,7 +2068,7 @@ gem 'other', version @spec = util_spec 'z' util_build_gem @spec - @installer = util_installer @spec, @gemhome end def util_conflict_executable(wrappers) @@ -2,7 +2,6 @@ # frozen_string_literal: true require 'rubygems/package/tar_test_case' -require 'rubygems/simple_gem' class TestGemPackage < Gem::Package::TarTestCase @@ -24,6 +23,8 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_class_new_old_format File.open 'old_format.gem', 'wb' do |io| io.write SIMPLE_GEM end @@ -839,6 +840,7 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_corrupt tf = Tempfile.open 'corrupt' do |io| data = Gem::Util.gzip 'a' * 10 io.write \ @@ -1,89 +1,92 @@ # frozen_string_literal: true require 'rubygems/test_case' -require 'rubygems/simple_gem' -class TestGemPackageOld < Gem::TestCase - def setup - super - File.open 'old_format.gem', 'wb' do |io| - io.write SIMPLE_GEM - end - @package = Gem::Package::Old.new 'old_format.gem' - @destination = File.join @tempdir, 'extract' - FileUtils.mkdir_p @destination - end - def test_contents - assert_equal %w[lib/foo.rb lib/test.rb lib/test/wow.rb], @package.contents - end - def test_contents_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @package.security_policy = Gem::Security::AlmostNoSecurity - assert_raises Gem::Security::Exception do - @package.contents end - end - def test_extract_files - @package.extract_files @destination - extracted = File.join @destination, 'lib/foo.rb' - assert_path_exists extracted - mask = 0100644 & (~File.umask) - assert_equal mask, File.stat(extracted).mode unless win_platform? - end - def test_extract_files_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @package.security_policy = Gem::Security::AlmostNoSecurity - assert_raises Gem::Security::Exception do - @package.extract_files @destination end - end - def test_spec - assert_equal 'testing', @package.spec.name - end - def test_spec_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @package.security_policy = Gem::Security::AlmostNoSecurity - assert_raises Gem::Security::Exception do - @package.spec end - end - def test_verify - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - assert @package.verify - @package.security_policy = Gem::Security::NoSecurity - assert @package.verify - @package.security_policy = Gem::Security::AlmostNoSecurity - e = assert_raises Gem::Security::Exception do - @package.verify end - assert_equal 'old format gems do not contain signatures ' + - 'and cannot be verified', - e.message end - end @@ -164,4 +164,45 @@ group\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000 end end end @@ -76,6 +76,7 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase end def test_full_name_null @entry.header.prefix << "\000" e = assert_raises Gem::Package::TarInvalidError do @@ -40,17 +40,19 @@ class TestGemPathSupport < Gem::TestCase end def test_initialize_path - ps = Gem::PathSupport.new ENV.to_hash.merge("GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator)) - assert_equal ENV["GEM_HOME"], ps.home - expected = [ - File.join(@tempdir, 'foo'), - File.join(@tempdir, 'bar'), - ENV["GEM_HOME"], - ] - assert_equal expected, ps.path end def test_initialize_regexp_path_separator @@ -90,13 +92,15 @@ class TestGemPathSupport < Gem::TestCase end def test_initialize_home_path - ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo", - "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator)) - assert_equal File.join(@tempdir, "foo"), ps.home - expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')] - assert_equal expected, ps.path end def util_path @@ -785,6 +785,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def test_ssl_client_cert_auth_connection skip 'openssl is missing' unless defined?(OpenSSL::SSL) ssl_server = self.class.start_ssl_server({ :SSLVerifyClient => @@ -1050,12 +1051,4 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== end - def test_correct_for_windows_path - path = "/C:/WINDOWS/Temp/gems" - assert_equal "C:/WINDOWS/Temp/gems", @fetcher.correct_for_windows_path(path) - - path = "/home/skillet" - assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path) - end - end if defined?(OpenSSL::SSL) @@ -328,6 +328,7 @@ class TestGemRequest < Gem::TestCase end def test_verify_certificate store = OpenSSL::X509::Store.new context = OpenSSL::X509::StoreContext.new store context.error = OpenSSL::X509::V_ERR_OUT_OF_MEM @@ -341,6 +342,7 @@ class TestGemRequest < Gem::TestCase end def test_verify_certificate_extra_message store = OpenSSL::X509::Store.new context = OpenSSL::X509::StoreContext.new store context.error = OpenSSL::X509::V_ERR_INVALID_CA @@ -856,4 +856,4 @@ end engine end -end @@ -97,7 +97,7 @@ class TestGemResolver < Gem::TestCase r1 = Gem::Resolver::DependencyRequest.new dep('a', '= 1'), nil - act = Gem::Resolver::ActivationRequest.new a1, r1, false res = Gem::Resolver.new [a1] @@ -118,7 +118,7 @@ class TestGemResolver < Gem::TestCase r1 = Gem::Resolver::DependencyRequest.new dep('a', '= 1'), nil - act = Gem::Resolver::ActivationRequest.new spec, r1, false res = Gem::Resolver.new [act] res.development = true @@ -137,7 +137,7 @@ class TestGemResolver < Gem::TestCase r1 = Gem::Resolver::DependencyRequest.new dep('a', '= 1'), nil - act = Gem::Resolver::ActivationRequest.new a1, r1, false res = Gem::Resolver.new [a1] res.ignore_dependencies = true @@ -13,11 +13,9 @@ class TestGemResolverActivationRequest < Gem::TestCase source = Gem::Source::Local.new platform = Gem::Platform::RUBY - @a1 = @DR::IndexSpecification.new nil, 'a', v(1), source, platform - @a2 = @DR::IndexSpecification.new nil, 'a', v(2), source, platform @a3 = @DR::IndexSpecification.new nil, 'a', v(3), source, platform - @req = @DR::ActivationRequest.new @a3, @dep, [@a1, @a2] end def test_development_eh @@ -25,7 +23,7 @@ class TestGemResolverActivationRequest < Gem::TestCase dep_req = @DR::DependencyRequest.new dep('a', '>= 0', :development), nil - act_req = @DR::ActivationRequest.new @a3, dep_req, [@a1, @a2] assert act_req.development? end @@ -33,41 +31,14 @@ class TestGemResolverActivationRequest < Gem::TestCase def test_inspect assert_match 'a-3', @req.inspect assert_match 'from a (>= 0)', @req.inspect - assert_match '(others possible: a-1, a-2)', @req.inspect - end - - def test_inspect_legacy - req = @DR::ActivationRequest.new @a3, @dep, true - - assert_match '(others possible)', req.inspect - - req = @DR::ActivationRequest.new @a3, @dep, false - - refute_match '(others possible)', req.inspect end def test_installed_eh v_spec = Gem::Resolver::VendorSpecification.new nil, @a3 - @req = @DR::ActivationRequest.new v_spec, @dep, [@a1, @a2] assert @req.installed? end - def test_others_possible_eh - assert @req.others_possible? - - req = @DR::ActivationRequest.new @a3, @dep, [] - - refute req.others_possible? - - req = @DR::ActivationRequest.new @a3, @dep, true - - assert req.others_possible? - - req = @DR::ActivationRequest.new @a3, @dep, false - - refute req.others_possible? - end - end @@ -63,6 +63,7 @@ class TestGemResolverGitSpecification < Gem::TestCase # functional test for Gem::Ext::Builder def test_install_extension name, _, repository, = git_gem 'a', 1 do |s| s.extensions << 'ext/extconf.rb' end @@ -6,6 +6,10 @@ unless defined?(OpenSSL::SSL) warn 'Skipping Gem::Security tests. openssl not found.' end class TestGemSecurity < Gem::TestCase CHILD_KEY = load_key 'child' @@ -307,4 +311,4 @@ class TestGemSecurity < Gem::TestCase assert_equal key.to_pem, key_from_file.to_pem end -end if defined?(OpenSSL::SSL) @@ -143,6 +143,7 @@ toqvglr0kdbknSRRjBVLK6tsgr07aLT9gNP7mTW2PA== end def test_sign_expired_auto_update FileUtils.mkdir_p File.join(Gem.user_home, '.gem'), :mode => 0700 private_key_path = File.join(Gem.user_home, '.gem', 'gem-private_key.pem') @@ -236,11 +236,6 @@ class TestGemSourceGit < Gem::TestCase system @git, 'add', 'b.gemspec' system @git, 'commit', '--quiet', '-m', 'add b/b.gemspec' end - - FileUtils.touch 'c.gemspec' - - system @git, 'add', 'c.gemspec' - system @git, 'commit', '--quiet', '-m', 'add c.gemspec' end specs = nil @@ -1441,6 +1441,7 @@ dependencies: [] end def test_build_args ext_spec assert_empty @ext.build_args @@ -1459,6 +1460,7 @@ dependencies: [] end def test_build_extensions ext_spec refute_path_exists @ext.extension_dir, 'sanity check' @@ -1494,6 +1496,7 @@ dependencies: [] end def test_build_extensions_built ext_spec refute_empty @ext.extensions, 'sanity check' @@ -1532,6 +1535,7 @@ dependencies: [] end def test_build_extensions_error ext_spec refute_empty @ext.extensions, 'sanity check' @@ -1545,6 +1549,7 @@ dependencies: [] skip 'chmod not supported' if Gem.win_platform? skip 'skipped in root privilege' if Process.uid.zero? ext_spec refute_empty @ext.extensions, 'sanity check' @@ -1569,7 +1574,7 @@ dependencies: [] @ext.build_extensions refute_path_exists @ext.extension_dir ensure - unless ($DEBUG or win_platform? or Process.uid.zero?) FileUtils.chmod 0755, File.join(@ext.base_dir, 'extensions') FileUtils.chmod 0755, @ext.base_dir end @@ -1577,7 +1582,7 @@ dependencies: [] def test_build_extensions_no_extensions_dir_unwritable skip 'chmod not supported' if Gem.win_platform? - ext_spec refute_empty @ext.extensions, 'sanity check' @@ -1616,6 +1621,7 @@ dependencies: [] end def test_build_extensions_old ext_spec refute_empty @ext.extensions, 'sanity check' @@ -1629,6 +1635,7 @@ dependencies: [] end def test_build_extensions_preview ext_spec extconf_rb = File.join @ext.gem_dir, @ext.extensions.first @@ -1663,6 +1670,7 @@ dependencies: [] end def test_contains_requirable_file_eh_extension ext_spec _, err = capture_io do @@ -3623,6 +3631,7 @@ end end def test_missing_extensions_eh ext_spec assert @ext.missing_extensions? @@ -67,6 +67,7 @@ class TestStubSpecification < Gem::TestCase end def test_contains_requirable_file_eh_extension stub_with_extension do |stub| _, err = capture_io do refute stub.contains_requirable_file? 'nonexistent' @@ -123,6 +124,7 @@ class TestStubSpecification < Gem::TestCase end def test_missing_extensions_eh stub = stub_with_extension do |s| extconf_rb = File.join s.gem_dir, s.extensions.first FileUtils.mkdir_p File.dirname extconf_rb @@ -6,6 +6,8 @@ class TestGemUninstaller < Gem::InstallerTestCase def setup super common_installer_setup build_rake_in do @@ -5,6 +5,7 @@ require 'rubygems/util' class TestGemUtil < Gem::TestCase def test_class_popen assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'p 0') assert_raises Errno::ECHILD do @@ -13,6 +14,7 @@ class TestGemUtil < Gem::TestCase end def test_silent_system assert_silent do Gem::Util.silent_system Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'puts "hello"; warn "hello"' end @@ -30,7 +32,7 @@ class TestGemUtil < Gem::TestCase end def test_traverse_parents_does_not_crash_on_permissions_error - skip 'skipped on MS Windows (chmod has no effect)' if win_platform? FileUtils.mkdir_p 'd/e/f' # remove 'execute' permission from "e" directory and make it @@ -47,7 +49,7 @@ class TestGemUtil < Gem::TestCase assert_equal File.realpath("..", Dir.tmpdir), paths[3] ensure # restore default permissions, allow the directory to be removed - FileUtils.chmod(0775, 'd/e') unless win_platform? end def test_linked_list_find @@ -75,4 +77,12 @@ class TestGemUtil < Gem::TestCase assert_equal expected_paths.to_set, files_with_relative_base.to_set end end @@ -1,14 +1,13 @@ # frozen_string_literal: true -require 'rubygems/test_case' -require "rubygems/simple_gem" -require 'rubygems/validator' class TestGemValidator < Gem::TestCase def setup super - @simple_gem = SIMPLE_GEM @validator = Gem::Validator.new end @@ -162,6 +162,10 @@ class TestGemRequire < Gem::TestCase end def test_activate_via_require_respects_loaded_files a1 = util_spec "a", "1", {"b" => ">= 1"}, "lib/test_gem_require_a.rb" b1 = util_spec "b", "1", nil, "lib/benchmark.rb" b2 = util_spec "b", "2", nil, "lib/benchmark.rb" @@ -431,7 +435,8 @@ class TestGemRequire < Gem::TestCase end end - if RUBY_VERSION >= "2.5" def test_no_kernel_require_in_warn_with_uplevel lib = File.realpath("../../../lib", __FILE__) Dir.mktmpdir("warn_test") do |dir| |