From eb807d42eca121df22f72b95465bba52a4e7fefa Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 7 Mar 2011 08:39:39 +0000 Subject: * gc.c (rb_gc_set_params): allow GC parameter configuration by environment variables. based on a patch from funny-falcon at https://gist.github.com/856296, but honors safe level. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/test_gem.rb | 422 ++------------------- test/rubygems/test_gem_builder.rb | 2 +- test/rubygems/test_gem_command_manager.rb | 4 +- test/rubygems/test_gem_commands_build_command.rb | 2 +- test/rubygems/test_gem_commands_cert_command.rb | 3 +- .../test_gem_commands_dependency_command.rb | 11 +- test/rubygems/test_gem_commands_fetch_command.rb | 8 +- test/rubygems/test_gem_commands_install_command.rb | 39 +- test/rubygems/test_gem_commands_lock_command.rb | 2 +- .../rubygems/test_gem_commands_outdated_command.rb | 7 +- .../rubygems/test_gem_commands_pristine_command.rb | 36 +- .../test_gem_commands_specification_command.rb | 16 +- test/rubygems/test_gem_commands_stale_command.rb | 6 +- .../test_gem_commands_uninstall_command.rb | 27 +- test/rubygems/test_gem_commands_unpack_command.rb | 18 +- test/rubygems/test_gem_commands_update_command.rb | 202 +--------- test/rubygems/test_gem_config_file.rb | 14 - test/rubygems/test_gem_dependency.rb | 39 -- test/rubygems/test_gem_dependency_installer.rb | 305 +++++---------- test/rubygems/test_gem_dependency_list.rb | 54 +-- test/rubygems/test_gem_doc_manager.rb | 9 +- test/rubygems/test_gem_format.rb | 4 +- test/rubygems/test_gem_indexer.rb | 19 +- test/rubygems/test_gem_install_update_options.rb | 2 + test/rubygems/test_gem_installer.rb | 229 ++++------- test/rubygems/test_gem_package_tar_output.rb | 3 - test/rubygems/test_gem_remote_fetcher.rb | 37 +- test/rubygems/test_gem_source_index.rb | 33 +- test/rubygems/test_gem_spec_fetcher.rb | 7 +- test/rubygems/test_gem_specification.rb | 118 ++---- test/rubygems/test_gem_uninstaller.rb | 80 +--- test/rubygems/test_gem_validator.rb | 2 +- test/rubygems/test_kernel.rb | 2 +- 33 files changed, 389 insertions(+), 1373 deletions(-) (limited to 'test/rubygems') diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 98d37a807e..06f25d4775 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -26,352 +26,6 @@ class TestGem < Gem::TestCase util_remove_interrupt_command end - def assert_activate expected, *specs - specs.each do |spec| - case spec - when Array - Gem.activate(*spec) - when String - Gem.activate spec - else - Gem.activate spec.name - end - end - - loaded = Gem.loaded_specs.values.map(&:full_name) - - assert_equal expected.sort, loaded.sort if expected - end - - def test_self_activate - foo = util_spec 'foo', '1' - - assert_activate %w[foo-1], foo - end - - def loaded_spec_names - Gem.loaded_specs.values.map(&:full_name).sort - end - - def unresolved_names - Gem.unresolved_deps.values.map(&:to_s).sort - end - - def test_self_activate_via_require - a1 = new_spec "a", "1", "b" => "= 1" - b1 = new_spec "b", "1", nil, "lib/b/c.rb" - b2 = new_spec "b", "2", nil, "lib/b/c.rb" - - Gem.activate "a", "= 1" - require "b/c" - - assert_equal %w(a-1 b-1), loaded_spec_names - end - - def test_self_activate_deep_unambiguous - a1 = new_spec "a", "1", "b" => "= 1" - b1 = new_spec "b", "1", "c" => "= 1" - b2 = new_spec "b", "2", "c" => "= 2" - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1 b-1 c-1), loaded_spec_names - end - - def save_loaded_features - old_loaded_features = $LOADED_FEATURES.dup - yield - ensure - $LOADED_FEATURES.replace old_loaded_features - end - - def test_self_activate_ambiguous_direct - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec("b", "1", { "c" => ">= 1" }, "lib/d.rb") - b2 = new_spec("b", "2", { "c" => ">= 2" }, "lib/d.rb") - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 b-2 c-2), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_self_activate_ambiguous_indirect - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1", nil, "lib/d.rb" - c2 = new_spec "c", "2", nil, "lib/d.rb" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 b-2 c-2), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_self_activate_ambiguous_unrelated - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - d1 = new_spec "d", "1", nil, "lib/d.rb" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 d-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - end - end - - def test_self_activate_ambiguous_indirect_conflict - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - a2 = new_spec "a", "2", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1", nil, "lib/d.rb" - c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2 - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 2" - assert_equal %w(a-2), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-2 b-1 c-1), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_require_missing - save_loaded_features do - assert_raises ::LoadError do - require "q" - end - end - end - - def test_self_activate_loaded - util_spec 'foo', '1' - - assert Gem.activate 'foo' - refute Gem.activate 'foo' - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] depends on nothing - - def test_self_activate_unrelated - a = util_spec 'a', '1.0', 'b' => '>= 1.0' - util_spec 'b', '1.0' - c = util_spec 'c', '1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] = 1.0 depends on - # [B] ~> 1.0 - # - # and should resolve using b-1.0 - - def test_self_activate_over - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1' - util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '~> 1.0' - - Gem.activate "a" - - assert_equal %w[a-1.0 c-1.0], loaded_spec_names - assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.1) - # [C] = 1.0 depends on - # [B] = 1.0 - # - # and should resolve using b-1.0 - # - # TODO: this is not under, but over... under would require depth - # first resolve through a dependency that is later pruned. - - def test_self_activate_under - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - ## - # [A1] depends on - # [B] > 0 (satisfied by 2.0) - # [B1] depends on - # [C] > 0 (satisfied by 1.0) - # [B2] depends on nothing! - # [C1] depends on nothing - - def test_self_activate_dropped - a1, = util_spec 'a', '1', 'b' => nil - util_spec 'b', '1', 'c' => nil - util_spec 'b', '2' - util_spec 'c', '1' - - assert_activate %w[b-2 a-1], a1, "b" - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 1.1) depends on - # [Z] - # [C] >= 1.0 depends on - # [B] = 1.0 - # - # and should backtrack to resolve using b-1.0, pruning Z from the - # resolve. - - def test_self_activate_raggi_the_edgecase_generator - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1', 'z' => '>= 1.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - def test_self_activate_conflict - util_spec 'b', '1.0' - util_spec 'b', '2.0' - - gem "b", "= 1.0" - - assert_raises Gem::LoadError do - gem "b", "= 2.0" - end - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.0) - # [C] = 1.0 depends on - # [B] = 2.0 - - def test_self_activate_divergent - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 2.0' - - e = assert_raises Gem::LoadError do - assert_activate nil, a, c, "b" - end - - assert_match(/Unable to activate c-1.0,/, e.message) - assert_match(/because b-1.0 conflicts with b .= 2.0/, e.message) - end - - ## - # DOC - - def test_self_activate_platform_alternate - @x1_m = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @x1_o = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu other_platform 1] - end - - @w1 = util_spec 'w', '1', 'x' => nil - - util_set_arch 'cpu-my_platform1' - - assert_activate %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m - end - - ## - # DOC - - def test_self_activate_platform_bump - @y1 = util_spec 'y', '1' - - @y1_1_p = util_spec 'y', '1.1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @z1 = util_spec 'z', '1', 'y' => nil - - assert_activate %w[y-1 z-1], @z1, @y1 - end - - ## - # [C] depends on - # [A] = 1.a - # [B] = 1.0 depends on - # [A] >= 0 (satisfied by 1.a) - - def test_self_activate_prerelease - @c1_pre = util_spec 'c', '1.a', "a" => "1.a", "b" => "1" - @a1_pre = util_spec 'a', '1.a' - @b1 = util_spec 'b', '1' do |s| - s.add_dependency 'a' - s.add_development_dependency 'aa' - end - - assert_activate %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1 - end - - ## - # DOC - - def test_self_activate_old_required - e1, = util_spec 'e', '1', 'd' => '= 1' - @d1 = util_spec 'd', '1' - @d2 = util_spec 'd', '2' - - assert_activate %w[d-1 e-1], e1, "d" - end - def test_self_all_load_paths util_make_gems @@ -417,7 +71,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_nonexistent_binfile - quick_spec 'a', '2' do |s| + quick_gem 'a', '2' do |s| s.executables = ['exec'] end assert_raises(Gem::GemNotFoundException) do @@ -426,7 +80,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_no_bin_file - quick_spec 'a', '1' + quick_gem 'a', '1' assert_raises(Gem::Exception) do Gem.bin_path('a', nil, '1') end @@ -440,7 +94,7 @@ class TestGem < Gem::TestCase def test_self_bin_path_bin_file_gone_in_latest util_exec_gem - quick_spec 'a', '10' do |s| + quick_gem 'a', '10' do |s| s.executables = [] s.default_executable = nil end @@ -496,7 +150,7 @@ class TestGem < Gem::TestCase fp.puts 'blah' end - foo = quick_spec 'foo' do |s| s.files = %w[data/foo.txt] end + foo = quick_gem 'foo' do |s| s.files = %w[data/foo.txt] end install_gem foo end @@ -558,7 +212,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories @gemhome - assert File.directory?(Gem.cache_dir(@gemhome)) + assert File.directory?(File.join(@gemhome, "cache")) end def test_self_ensure_gem_directories_missing_parents @@ -570,7 +224,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - assert File.directory?(Gem.cache_dir(gemdir)) + assert File.directory?("#{gemdir}/cache") end unless win_platform? then # only for FS that support write protection @@ -584,7 +238,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?(Gem.cache_dir(gemdir)) + refute File.exist?("#{gemdir}/cache") ensure FileUtils.chmod 0600, gemdir end @@ -601,7 +255,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?(Gem.cache_dir(gemdir)) + refute File.exist?("#{gemdir}/cache") ensure FileUtils.chmod 0600, parent end @@ -622,8 +276,8 @@ class TestGem < Gem::TestCase def test_self_find_files discover_path = File.join 'lib', 'sff', 'discover.rb' - cwd = File.expand_path("test/rubygems", @@project_dir) - $LOAD_PATH.unshift cwd + cwd = File.expand_path '..', __FILE__ + $LOAD_PATH.unshift cwd.dup foo1 = quick_gem 'sff', '1' do |s| s.files << discover_path @@ -647,7 +301,7 @@ class TestGem < Gem::TestCase Gem.searcher = nil expected = [ - File.expand_path('test/rubygems/sff/discover.rb', @@project_dir), + File.expand_path('../sff/discover.rb', __FILE__), File.join(foo2.full_gem_path, discover_path), File.join(foo1.full_gem_path, discover_path), ] @@ -673,7 +327,7 @@ class TestGem < Gem::TestCase end def test_self_loaded_specs - foo = quick_spec 'foo' + foo = quick_gem 'foo' install_gem foo Gem.source_index = nil @@ -776,12 +430,22 @@ class TestGem < Gem::TestCase end def test_self_prefix - assert_equal @@project_dir, Gem.prefix + file_name = File.expand_path __FILE__ + + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + assert_equal prefix, Gem.prefix end def test_self_prefix_libdir orig_libdir = Gem::ConfigMap[:libdir] - Gem::ConfigMap[:libdir] = @@project_dir + + file_name = File.expand_path __FILE__ + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + Gem::ConfigMap[:libdir] = prefix assert_nil Gem.prefix ensure @@ -790,7 +454,12 @@ class TestGem < Gem::TestCase def test_self_prefix_sitelibdir orig_sitelibdir = Gem::ConfigMap[:sitelibdir] - Gem::ConfigMap[:sitelibdir] = @@project_dir + + file_name = File.expand_path __FILE__ + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + Gem::ConfigMap[:sitelibdir] = prefix assert_nil Gem.prefix ensure @@ -954,20 +623,6 @@ class TestGem < Gem::TestCase end end - def test_self_cache_dir - util_ensure_gem_dirs - - assert_equal File.join(@gemhome, 'cache'), Gem.cache_dir - assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache'), Gem.cache_dir(Gem.user_dir) - end - - def test_self_cache_gem - util_ensure_gem_dirs - - assert_equal File.join(@gemhome, 'cache', 'test.gem'), Gem.cache_gem('test.gem') - assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache', 'test.gem'), Gem.cache_gem('test.gem', Gem.user_dir) - end - if Gem.win_platform? then def test_self_user_home_userprofile skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION @@ -1019,10 +674,10 @@ class TestGem < Gem::TestCase Dir.chdir @tempdir do FileUtils.mkdir_p 'lib' File.open plugin_path, "w" do |fp| - fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end" + fp.puts "TestGem::TEST_SPEC_PLUGIN_LOAD = :loaded" end - foo = quick_spec 'foo', '1' do |s| + foo = quick_gem 'foo', '1' do |s| s.files << plugin_path end @@ -1030,7 +685,6 @@ class TestGem < Gem::TestCase end Gem.source_index = nil - Gem.searcher = nil gem 'foo' @@ -1041,24 +695,23 @@ class TestGem < Gem::TestCase def test_load_env_plugins with_plugin('load') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil + assert_equal :loaded, TEST_PLUGIN_LOAD util_remove_interrupt_command # Should attempt to cause a StandardError with_plugin('standarderror') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_STANDARDERROR rescue nil + assert_equal :loaded, TEST_PLUGIN_STANDARDERROR util_remove_interrupt_command # Should attempt to cause an Exception with_plugin('exception') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil + assert_equal :loaded, TEST_PLUGIN_EXCEPTION end def with_plugin(path) - test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}", - @@project_dir) + test_plugin_path = File.expand_path "../plugin/#{path}", __FILE__ # A single test plugin should get loaded once only, in order to preserve # sane test semantics. @@ -1080,7 +733,7 @@ class TestGem < Gem::TestCase end def util_exec_gem - spec, _ = quick_spec 'a', '4' do |s| + spec, _ = quick_gem 'a', '4' do |s| s.default_executable = 'exec' s.executables = ['exec', 'abin'] end @@ -1124,5 +777,6 @@ class TestGem < Gem::TestCase Gem::Commands.send :remove_const, :InterruptCommand if Gem::Commands.const_defined? :InterruptCommand end + end diff --git a/test/rubygems/test_gem_builder.rb b/test/rubygems/test_gem_builder.rb index f95472f626..d146c843bb 100644 --- a/test/rubygems/test_gem_builder.rb +++ b/test/rubygems/test_gem_builder.rb @@ -10,7 +10,7 @@ require 'rubygems/builder' class TestGemBuilder < Gem::TestCase def test_build - builder = Gem::Builder.new quick_spec('a') + builder = Gem::Builder.new quick_gem('a') use_ui @ui do Dir.chdir @tempdir do diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index 3769c250d5..daadf2520e 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -17,7 +17,7 @@ class TestGemCommandManager < Gem::TestCase def test_run_interrupt old_load_path = $:.dup - $: << File.expand_path("test/rubygems", @@project_dir) + $: << "test/rubygems" Gem.load_env_plugins use_ui @ui do @@ -33,7 +33,7 @@ class TestGemCommandManager < Gem::TestCase def test_run_crash_command old_load_path = $:.dup - $: << File.expand_path("test/rubygems", @@project_dir) + $: << "test/rubygems" @command_manager.register_command :crash use_ui @ui do diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index 5c38a1a5e8..5c9c5eeb6e 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -13,7 +13,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase def setup super - @gem = quick_spec 'some_gem' do |s| + @gem = quick_gem 'some_gem' do |s| s.rubyforge_project = 'example' end diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index a514ea41f2..9d5fc1eada 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -6,7 +6,6 @@ require 'rubygems/test_case' require 'rubygems/commands/cert_command' -require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9" unless defined? OpenSSL then warn "`gem cert` tests are being skipped, module OpenSSL not found" @@ -22,7 +21,7 @@ class TestGemCommandsCertCommand < Gem::TestCase @cmd = Gem::Commands::CertCommand.new - root = File.expand_path(File.dirname(__FILE__), @@project_dir) + root = File.expand_path(File.dirname(__FILE__)) FileUtils.cp File.join(root, 'data', 'gem-private_key.pem'), @tempdir FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb index 665cd98c4d..40d96f729a 100644 --- a/test/rubygems/test_gem_commands_dependency_command.rb +++ b/test/rubygems/test_gem_commands_dependency_command.rb @@ -32,7 +32,7 @@ class TestGemCommandsDependencyCommand < Gem::TestCase @cmd.execute end - assert_equal "Gem foo-2\n bar (> 1)\n baz (> 1)\n\n", + assert_equal "Gem foo-2\n bar (> 1, runtime)\n baz (> 1, runtime)\n\n", @ui.output assert_equal '', @ui.error end @@ -83,7 +83,7 @@ Gem pl-1-x86-linux end def test_execute_pipe_format - quick_spec 'foo' do |gem| + quick_gem 'foo' do |gem| gem.add_dependency 'bar', '> 1' end @@ -127,7 +127,6 @@ Gem b-2 end def test_execute_reverse - # FIX: this shouldn't need to write out, but fails if you switch it quick_gem 'foo' do |gem| gem.add_dependency 'bar', '> 1' end @@ -147,9 +146,9 @@ Gem b-2 expected = <<-EOF Gem foo-2 - bar (> 1) + bar (> 1, runtime) Used by - baz-2 (foo (>= 0)) + baz-2 (foo (>= 0, runtime)) EOF @@ -195,7 +194,7 @@ ERROR: Only reverse dependencies for local gems are supported. @cmd.execute end - assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output + assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output assert_equal '', @ui.error end diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb index 173a33572f..657e8e9f80 100644 --- a/test/rubygems/test_gem_commands_fetch_command.rb +++ b/test/rubygems/test_gem_commands_fetch_command.rb @@ -22,7 +22,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase util_setup_spec_fetcher @a2 @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - File.read(Gem.cache_gem(@a2.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a2.file_name)) @cmd.options[:args] = [@a2.name] @@ -41,9 +41,9 @@ class TestGemCommandsFetchCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - File.read(Gem.cache_gem(@a2.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - File.read(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a2_pre.file_name)) @cmd.options[:args] = [@a2.name] @cmd.options[:prerelease] = true @@ -63,7 +63,7 @@ class TestGemCommandsFetchCommand < Gem::TestCase util_setup_spec_fetcher @a1, @a2 @fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] = - File.read(Gem.cache_gem(@a1.file_name, @gemhome)) + File.read(File.join(@gemhome, 'cache', @a1.file_name)) @cmd.options[:args] = [@a2.name] @cmd.options[:version] = Gem::Requirement.new '1' diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index adc66aa911..a3ceb81ab7 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -7,12 +7,6 @@ require 'rubygems/test_case' require 'rubygems/commands/install_command' -begin - gem "rdoc" -rescue Gem::LoadError - # ignore -end - class TestGemCommandsInstallCommand < Gem::TestCase def setup @@ -28,9 +22,9 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) @cmd.options[:args] = [@a2.name] @@ -50,12 +44,11 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) - @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s, - "--no-ri", "--no-rdoc"] + @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s] assert @cmd.options[:prerelease] assert @cmd.options[:version].satisfied_by?(@a2_pre.version) @@ -92,7 +85,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_fake_fetcher @cmd.options[:domain] = :local - FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), + File.join(@tempdir) @cmd.options[:args] = [@a2.name] @@ -121,7 +115,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_fake_fetcher @cmd.options[:user_install] = false - FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), + File.join(@tempdir) @cmd.options[:args] = [@a2.name] @@ -188,7 +183,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase correctly_spelled = "non_existent_with_hint" util_setup_fake_fetcher - util_setup_spec_fetcher quick_spec(correctly_spelled, '2') + util_setup_spec_fetcher quick_gem(correctly_spelled, '2') @cmd.options[:args] = [misspelled] @@ -212,9 +207,9 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) @cmd.options[:prerelease] = true @cmd.options[:args] = [@a2_pre.name] @@ -238,7 +233,7 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @a2 @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @a2.file_name)) @cmd.options[:args] = [@a2.name] @@ -265,9 +260,11 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_fake_fetcher @cmd.options[:domain] = :local - FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), + File.join(@tempdir) - FileUtils.mv Gem.cache_gem(@b2.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', @b2.file_name), + File.join(@tempdir) @cmd.options[:args] = [@a2.name, @b2.name] @@ -296,7 +293,7 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @b2 @fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = - read_binary(Gem.cache_gem(@b2.file_name, @gemhome)) + read_binary(File.join(@gemhome, 'cache', @b2.file_name)) uninstall_gem(@b2) diff --git a/test/rubygems/test_gem_commands_lock_command.rb b/test/rubygems/test_gem_commands_lock_command.rb index bb3134661d..25b033af5d 100644 --- a/test/rubygems/test_gem_commands_lock_command.rb +++ b/test/rubygems/test_gem_commands_lock_command.rb @@ -51,7 +51,7 @@ gem 'a', '= 1' expected = <<-EXPECTED require 'rubygems' gem 'd', '= 1' -# Unable to satisfy 'z (>= 0)' from currently installed gems +# Unable to satisfy 'z (>= 0, runtime)' from currently installed gems EXPECTED assert_equal expected, @ui.output diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb index 632e9a5548..6f99f33e99 100644 --- a/test/rubygems/test_gem_commands_outdated_command.rb +++ b/test/rubygems/test_gem_commands_outdated_command.rb @@ -22,11 +22,14 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase def test_execute quick_gem 'foo', '0.1' quick_gem 'foo', '0.2' - remote_10 = quick_spec 'foo', '1.0' - remote_20 = quick_spec 'foo', '2.0' + remote_10 = quick_gem 'foo', '1.0' + remote_20 = quick_gem 'foo', '2.0' remote_spec_file = File.join @gemhome, 'specifications', remote_10.spec_name + FileUtils.rm remote_spec_file + remote_spec_file = File.join @gemhome, 'specifications', remote_20.spec_name + FileUtils.rm remote_spec_file @fetcher = Gem::FakeFetcher.new Gem::RemoteFetcher.fetcher = @fetcher diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index 4decdf81b9..9cab574a1f 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -15,7 +15,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute - a = quick_spec 'a' do |s| s.executables = %w[foo] end + a = quick_gem 'a' do |s| s.executables = %w[foo] end FileUtils.mkdir_p File.join(@tempdir, 'bin') File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| fp.puts "#!/usr/bin/ruby" @@ -45,7 +45,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_all - a = quick_spec 'a' do |s| s.executables = %w[foo] end + a = quick_gem 'a' do |s| s.executables = %w[foo] end FileUtils.mkdir_p File.join(@tempdir, 'bin') File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| fp.puts "#!/usr/bin/ruby" @@ -73,29 +73,15 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_missing_cache_gem - a = quick_spec 'a' do |s| - s.executables = %w[foo] - end - + a = quick_gem 'a' do |s| s.executables = %w[foo] end FileUtils.mkdir_p File.join(@tempdir, 'bin') - File.open File.join(@tempdir, 'bin', 'foo'), 'w' do |fp| fp.puts "#!/usr/bin/ruby" end install_gem a - a_data = nil - open File.join(@gemhome, 'cache', a.file_name), 'rb' do |fp| - a_data = fp.read - end - - util_setup_fake_fetcher - util_setup_spec_fetcher a - - Gem::RemoteFetcher.fetcher.data["http://gems.example.com/gems/#{a.file_name}"] = a_data - - FileUtils.rm Gem.cache_gem(a.file_name, @gemhome) + FileUtils.rm File.join(@gemhome, 'cache', a.file_name) @cmd.options[:args] = %w[a] @@ -105,17 +91,11 @@ class TestGemCommandsPristineCommand < Gem::TestCase out = @ui.output.split "\n" - [ - "Restoring gem\(s\) to pristine condition...", - "Restored a-1", - "Cached gem for a-2 not found, attempting to fetch...", - "Restored a-2", - "Restored a-3.a" - ].each do |line| - assert_equal line, out.shift - end - + assert_equal "Restoring gem\(s\) to pristine condition...", out.shift assert_empty out, out.inspect + + assert_equal "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n", + @ui.error end def test_execute_no_gem diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb index 767992f240..ca210059fd 100644 --- a/test/rubygems/test_gem_commands_specification_command.rb +++ b/test/rubygems/test_gem_commands_specification_command.rb @@ -16,7 +16,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo] @@ -31,8 +31,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_all - quick_spec 'foo', '0.0.1' - quick_spec 'foo', '0.0.2' + quick_gem 'foo', '0.0.1' + quick_gem 'foo', '0.0.2' @cmd.options[:args] = %w[foo] @cmd.options[:all] = true @@ -62,8 +62,8 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_exact_match - quick_spec 'foo' - quick_spec 'foo_bar' + quick_gem 'foo' + quick_gem 'foo_bar' @cmd.options[:args] = %w[foo] @@ -77,7 +77,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_field - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo name] @@ -90,7 +90,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_marshal - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo] @@ -126,7 +126,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_ruby - foo = quick_spec 'foo' + foo = quick_gem 'foo' Gem.source_index.add_spec foo @cmd.options[:args] = %w[foo] diff --git a/test/rubygems/test_gem_commands_stale_command.rb b/test/rubygems/test_gem_commands_stale_command.rb index d5aad6ce0c..f3876d90db 100644 --- a/test/rubygems/test_gem_commands_stale_command.rb +++ b/test/rubygems/test_gem_commands_stale_command.rb @@ -16,11 +16,10 @@ class TestGemCommandsStaleCommand < Gem::TestCase def test_execute_sorts files = %w[lib/foo_bar.rb Rakefile] - foo_bar = quick_spec 'foo_bar' do |gem| + foo_bar = quick_gem 'foo_bar' do |gem| gem.files = files end - - bar_baz = quick_spec 'bar_baz' do |gem| + bar_baz = quick_gem 'bar_baz' do |gem| gem.files = files end @@ -37,7 +36,6 @@ class TestGemCommandsStaleCommand < Gem::TestCase use_ui @ui do @cmd.execute end - lines = @ui.output.split("\n") assert_equal("#{foo_bar.name}-#{foo_bar.version}", lines[0].split.first) assert_equal("#{bar_baz.name}-#{bar_baz.version}", lines[1].split.first) diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 47f4960145..c5be3beb90 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -33,7 +33,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end end - if win_platform? then + if win_platform? assert File.exist?(@executable) else assert File.symlink?(@executable) @@ -42,9 +42,9 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase # Evil hack to prevent false removal success FileUtils.rm_f @executable - open @executable, "wb+" do |f| f.puts "binary" end + open(@executable, "wb+") {|f| f.puts "binary"} - @cmd.options[:args] = [@spec.name] + @cmd.options[:args] = Array(@spec.name) use_ui @ui do @cmd.execute end @@ -56,25 +56,6 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert_nil output.shift, "UI output should have contained only two lines" 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) - - @cmd.options[:format_executable] = true - @cmd.execute - - assert_equal false, File.exist?(formatted_executable) - rescue - Gem::Installer.exec_format = nil - end - def test_execute_not_installed @cmd.options[:args] = ["foo"] e = assert_raises Gem::InstallError do @@ -89,7 +70,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_prerelease - @spec = quick_spec "pre", "2.b" + @spec = quick_gem "pre", "2.b" @gem = File.join @tempdir, @spec.file_name FileUtils.touch @gem diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb index 8291a6b949..0fb4ef3843 100644 --- a/test/rubygems/test_gem_commands_unpack_command.rb +++ b/test/rubygems/test_gem_commands_unpack_command.rb @@ -22,7 +22,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase assert_equal( @cmd.find_in_cache(@a1.file_name), - Gem.cache_gem(@a1.file_name, @gemhome), + File.join(@gemhome, 'cache', @a1.file_name), 'found a-1.gem in the cache' ) end @@ -34,7 +34,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase a1_data = nil - open Gem.cache_gem(@a1.file_name, @gemhome), 'rb' do |fp| + open File.join(@gemhome, 'cache', @a1.file_name), 'rb' do |fp| a1_data = fp.read end @@ -44,15 +44,15 @@ class TestGemCommandsUnpackCommand < Gem::TestCase dep = Gem::Dependency.new(@a1.name, @a1.version) assert_equal( @cmd.get_path(dep), - Gem.cache_gem(@a1.file_name, @gemhome), + File.join(@gemhome, 'cache', @a1.file_name), 'fetches a-1 and returns the cache path' ) - FileUtils.rm Gem.cache_gem(@a1.file_name, @gemhome) + FileUtils.rm File.join(@gemhome, 'cache', @a1.file_name) assert_equal( @cmd.get_path(dep), - Gem.cache_gem(@a1.file_name, @gemhome), + File.join(@gemhome, 'cache', @a1.file_name), 'when removed from cache, refetches a-1' ) end @@ -74,8 +74,6 @@ class TestGemCommandsUnpackCommand < Gem::TestCase def test_execute_gem_path util_make_gems - util_setup_spec_fetcher - util_setup_fake_fetcher Gem.clear_paths @@ -123,7 +121,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase util_clear_gems a2_data = nil - open Gem.cache_gem(@a2.file_name, @gemhome), 'rb' do |fp| + open File.join(@gemhome, 'cache', @a2.file_name), 'rb' do |fp| a2_data = fp.read end @@ -177,8 +175,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase end def test_execute_exact_match - foo_spec = quick_spec 'foo' - foo_bar_spec = quick_spec 'foo_bar' + foo_spec = quick_gem 'foo' + foo_bar_spec = quick_gem 'foo_bar' use_ui @ui do Dir.chdir @tempdir do diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index 24966a3a84..6c16713130 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -7,12 +7,6 @@ require 'rubygems/test_case' require 'rubygems/commands/update_command' -begin - gem "rdoc" -rescue Gem::LoadError - # ignore -end - class TestGemCommandsUpdateCommand < Gem::TestCase def setup @@ -25,8 +19,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase util_setup_fake_fetcher - @a1_path = Gem.cache_gem(@a1.file_name, @gemhome) - @a2_path = Gem.cache_gem(@a2.file_name, @gemhome) + @a1_path = File.join @gemhome, 'cache', @a1.file_name + @a2_path = File.join @gemhome, 'cache', @a2.file_name util_setup_spec_fetcher @a1, @a2 @@ -42,8 +36,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase Gem::Installer.new(@a1_path).install @cmd.options[:args] = [] - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false + @cmd.options[:generate_rdoc] = true + @cmd.options[:generate_ri] = true use_ui @ui do @cmd.execute @@ -54,153 +48,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_equal "Updating #{@a2.name}", out.shift assert_equal "Successfully installed #{@a2.full_name}", out.shift assert_equal "Gems updated: #{@a2.name}", out.shift - assert_empty out - end - - def util_setup_rubygem version - gem = quick_spec('rubygems-update', version.to_s) do |s| - s.files = %w[setup.rb] - end - write_file File.join(*%W[gems #{gem.original_name} setup.rb]) - util_build_gem gem - util_setup_spec_fetcher gem - gem - end - - def util_setup_rubygem8 - @rubygem8 = util_setup_rubygem 8 - end - - def util_setup_rubygem9 - @rubygem9 = util_setup_rubygem 9 - end - - def util_setup_rubygem_current - @rubygem_current = util_setup_rubygem Gem::VERSION - end - - def util_add_to_fetcher *specs - specs.each do |spec| - gem_file = Gem.cache_gem(spec.file_name, @gemhome) - - @fetcher.data["http://gems.example.com/gems/#{spec.file_name}"] = - Gem.read_binary gem_file - end - end - - def test_execute_system - util_setup_rubygem9 - util_setup_spec_fetcher @rubygem9 - util_add_to_fetcher @rubygem9 - util_clear_gems - - @cmd.options[:args] = [] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - use_ui @ui do - @cmd.execute - end - - out = @ui.output.split "\n" - assert_equal "Updating rubygems-update", out.shift - assert_equal "Successfully installed rubygems-update-9", out.shift - assert_equal "Installing RubyGems 9", out.shift - assert_equal "RubyGems system software updated", out.shift - - assert_empty out - end - - def test_execute_system_at_latest - util_setup_rubygem_current - util_setup_spec_fetcher @rubygem_current - util_add_to_fetcher @rubygem_current - util_clear_gems - - @cmd.options[:args] = [] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - assert_raises Gem::SystemExitException do - use_ui @ui do - @cmd.execute - end - end - - out = @ui.output.split "\n" - assert_equal "Latest version currently installed. Aborting.", out.shift - assert_empty out - end - - def test_execute_system_multiple - util_setup_rubygem9 - util_setup_rubygem8 - util_setup_spec_fetcher @rubygem8, @rubygem9 - util_add_to_fetcher @rubygem8, @rubygem9 - util_clear_gems - - @cmd.options[:args] = [] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - use_ui @ui do - @cmd.execute - end - - out = @ui.output.split "\n" - assert_equal "Updating rubygems-update", out.shift - assert_equal "Successfully installed rubygems-update-9", out.shift - assert_equal "Installing RubyGems 9", out.shift - assert_equal "RubyGems system software updated", out.shift - - assert_empty out - end - - def test_execute_system_specific - util_clear_gems - util_setup_rubygem9 - util_setup_rubygem8 - util_setup_spec_fetcher @rubygem8, @rubygem9 - util_add_to_fetcher @rubygem8, @rubygem9 - - @cmd.options[:args] = [] - @cmd.options[:system] = "8" - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - use_ui @ui do - @cmd.execute - end - - out = @ui.output.split "\n" - assert_equal "Updating rubygems-update", out.shift - assert_equal "Successfully installed rubygems-update-8", out.shift - assert_equal "Installing RubyGems 8", out.shift - assert_equal "RubyGems system software updated", out.shift + assert_equal "Installing ri documentation for a-2...", out.shift + assert_equal "Installing RDoc documentation for a-2...", out.shift assert_empty out end - def test_execute_system_with_gems - @cmd.options[:args] = %w[gem] - @cmd.options[:system] = true - @cmd.options[:generate_rdoc] = false - @cmd.options[:generate_ri] = false - - assert_raises Gem::MockGemUi::TermError do - use_ui @ui do - @cmd.execute - end - end - - assert_empty @ui.output - assert_equal "ERROR: Gem names are not allowed with the --system option\n", - @ui.error - end - # before: # a1 -> c1.2 # after: @@ -210,7 +63,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_dependencies @a1.add_dependency 'c', '1.2' - @c2 = quick_spec 'c', '2' do |s| + @c2 = quick_gem 'c', '2' do |s| s.files = %w[lib/code.rb] s.require_paths = %w[lib] end @@ -218,9 +71,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase @a2.add_dependency 'c', '2' @a2.add_dependency 'b', '2' - @b2_path = Gem.cache_gem(@b2.file_name, @gemhome) - @c1_2_path = Gem.cache_gem(@c1_2.file_name, @gemhome) - @c2_path = Gem.cache_gem(@c2.file_name, @gemhome) + @b2_path = File.join @gemhome, 'cache', @b2.file_name + @c1_2_path = File.join @gemhome, 'cache', @c1_2.file_name + @c2_path = File.join @gemhome, 'cache', @c2.file_name @source_index = Gem::SourceIndex.new @source_index.add_spec @a1 @@ -319,39 +172,4 @@ class TestGemCommandsUpdateCommand < Gem::TestCase assert_empty out end - - def test_handle_options_system - @cmd.handle_options %w[--system] - - expected = { - :generate_ri => true, - :system => true, - :force => false, - :args => [], - :generate_rdoc => true, - } - - assert_equal expected, @cmd.options - end - - def test_handle_options_system_non_version - assert_raises ArgumentError do - @cmd.handle_options %w[--system non-version] - end - end - - def test_handle_options_system_specific - @cmd.handle_options %w[--system 1.3.7] - - expected = { - :generate_ri => true, - :system => "1.3.7", - :force => false, - :args => [], - :generate_rdoc => true, - } - - assert_equal expected, @cmd.options - end - end diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index 424fd92f80..dc53d21933 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -283,20 +283,6 @@ class TestGemConfigFile < Gem::TestCase assert_equal "701229f217cdf23b1344c7b4b54ca97", @cfg.rubygems_api_key end - def test_load_api_keys_from_config - temp_cred = File.join Gem.user_home, '.gem', 'credentials' - FileUtils.mkdir File.dirname(temp_cred) - File.open temp_cred, 'w' do |fp| - fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97" - fp.puts ":other: a5fdbb6ba150cbb83aad2bb2fede64c" - end - - util_config_file - - assert_equal({:rubygems => '701229f217cdf23b1344c7b4b54ca97', - :other => 'a5fdbb6ba150cbb83aad2bb2fede64c'}, @cfg.api_keys) - end - def util_config_file(args = @cfg_args) @cfg = Gem::ConfigFile.new args end diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb index b4a21b896c..51b746f555 100644 --- a/test/rubygems/test_gem_dependency.rb +++ b/test/rubygems/test_gem_dependency.rb @@ -106,45 +106,6 @@ class TestGemDependency < Gem::TestCase refute_equal dep("pkg", :development), dep("pkg", :runtime), "type" end - def test_merge - a1 = dep 'a', '~> 1.0' - a2 = dep 'a', '= 1.0' - - a3 = a1.merge a2 - - assert_equal dep('a', '~> 1.0', '= 1.0'), a3 - end - - def test_merge_default - a1 = dep 'a' - a2 = dep 'a', '1' - - a3 = a1.merge a2 - - assert_equal dep('a', '1'), a3 - end - - def test_merge_name_mismatch - a = dep 'a' - b = dep 'b' - - e = assert_raises ArgumentError do - a.merge b - end - - assert_equal 'a (>= 0) and b (>= 0) have different names', - e.message - end - - def test_merge_other_default - a1 = dep 'a', '1' - a2 = dep 'a' - - a3 = a1.merge a2 - - assert_equal dep('a', '1'), a3 - end - def test_prerelease_eh d = dep "pkg", "= 1" diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 5cf79d3c59..cdc0428e9f 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -6,28 +6,66 @@ require 'rubygems/test_case' require 'rubygems/dependency_installer' -require 'rubygems/security' class TestGemDependencyInstaller < Gem::TestCase def setup super - @gems_dir = File.join @tempdir, 'gems' - @cache_dir = Gem.cache_dir(@gemhome) - + @gems_dir = File.join @tempdir, 'gems' + @cache_dir = File.join @gemhome, 'cache' FileUtils.mkdir @gems_dir - @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end + write_file File.join('gems', 'a-1', 'bin', 'a_bin') do |fp| + fp.puts "#!/usr/bin/ruby" + end + + @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end + @aa1, @aa1_gem = util_gem 'aa', '1' @a1_pre, @a1_pre_gem = util_gem 'a', '1.a' - @b1, @b1_gem = util_gem 'b', '1' do |s| + + @b1, @b1_gem = util_gem 'b', '1' do |s| + s.add_dependency 'a' + s.add_development_dependency 'aa' + end + + @b1_pre, @b1_pre_gem = util_gem 'b', '1.a' do |s| s.add_dependency 'a' s.add_development_dependency 'aa' end - Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new + @c1_pre, @c1_pre_gem = util_gem 'c', '1.a' do |s| + s.add_dependency 'a', '1.a' + s.add_dependency 'b', '1' + end + + @d1, @d1_gem = util_gem 'd', '1' + @d2, @d2_gem = util_gem 'd', '2' + + @x1_m, @x1_m_gem = util_gem 'x', '1' do |s| + s.platform = Gem::Platform.new %w[cpu my_platform 1] + end + + @x1_o, @x1_o_gem = util_gem 'x', '1' do |s| + s.platform = Gem::Platform.new %w[cpu other_platform 1] + end + + @w1, @w1_gem = util_gem 'w', '1', 'x' => nil + + @y1, @y1_gem = util_gem 'y', '1' + @y1_1_p, @y1_1_p_gem = util_gem 'y', '1.1' do |s| + s.platform = Gem::Platform.new %w[cpu my_platform 1] + end + + @z1, @z1_gem = util_gem 'z', '1', 'y' => nil + + @fetcher = Gem::FakeFetcher.new + Gem::RemoteFetcher.fetcher = @fetcher + + util_setup_spec_fetcher(@a1, @a1_pre, @b1, @b1_pre, @c1_pre, @d1, @d2, + @x1_m, @x1_o, @w1, @y1, @y1_1_p, @z1) - util_reset_gems + util_clear_gems end def test_install @@ -82,8 +120,8 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name } - assert Gem.cache_gem(@a1.file_name, @gemhome) - assert Gem.cache_gem(@b1.file_name, @gemhome) + assert File.exist?(File.join(@tempdir, 'cache', @a1.file_name)) + assert File.exist?(File.join(@tempdir, 'cache', @b1.file_name)) end def test_install_dependencies_satisfied @@ -130,10 +168,6 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_dependency_development - @aa1, @aa1_gem = util_gem 'aa', '1' - - util_reset_gems - FileUtils.mv @a1_gem, @tempdir FileUtils.mv @aa1_gem, @tempdir FileUtils.mv @b1_gem, @tempdir @@ -287,7 +321,7 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } assert File.exist?(File.join(gemhome2, 'specifications', @a1.spec_name)) - assert File.exist?(Gem.cache_gem(@a1.file_name, gemhome2)) + assert File.exist?(File.join(gemhome2, 'cache', @a1.file_name)) end def test_install_domain_both @@ -342,13 +376,12 @@ class TestGemDependencyInstaller < Gem::TestCase Gem.source_index.remove_spec @a1_pre.full_name Dir.chdir @tempdir do - e = assert_raises Gem::DependencyError do + e = assert_raises Gem::InstallError do inst = Gem::DependencyInstaller.new :domain => :local inst.install 'b' end - expected = "Unable to resolve dependencies: b requires a (>= 0)" - assert_equal expected, e.message + assert_equal 'b requires a (>= 0, runtime)', e.message end assert_equal [], inst.installed_gems.map { |s| s.full_name } @@ -392,22 +425,6 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name } end - def test_install_reinstall - Gem::Installer.new(@a1_gem).install - FileUtils.mv @a1_gem, @tempdir - inst = nil - - Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new - inst.install 'a' - end - - assert_equal Gem::SourceIndex.new(@a1.full_name => @a1), - Gem::SourceIndex.from_installed_gems - - assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } - end - def test_install_remote a1_data = nil File.open @a1_gem, 'rb' do |fp| @@ -443,7 +460,7 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end - def test_install_remote_platform_newer + def test_install_domain_remote_platform_newer a2_o, a2_o_gem = util_gem 'a', '2' do |s| s.platform = Gem::Platform.new %w[cpu other_platform 1] end @@ -471,6 +488,22 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end + def test_install_reinstall + Gem::Installer.new(@a1_gem).install + FileUtils.mv @a1_gem, @tempdir + inst = nil + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new + inst.install 'a' + end + + assert_equal Gem::SourceIndex.new(@a1.full_name => @a1), + Gem::SourceIndex.from_installed_gems + + assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } + end + if defined? OpenSSL then def test_install_security_policy data = File.open(@a1_gem, 'rb') { |f| f.read } @@ -506,8 +539,6 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_version - util_setup_d - data = File.open(@d2_gem, 'rb') { |f| f.read } @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data @@ -522,8 +553,6 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_version_default - util_setup_d - data = File.open(@d2_gem, 'rb') { |f| f.read } @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data @@ -590,22 +619,7 @@ class TestGemDependencyInstaller < Gem::TestCase util_setup_spec_fetcher(*specs) inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version specs.first.name - inst.gather_dependencies - - actual = inst.gems_to_install.map { |s| s.full_name } - assert_equal expected, actual - end - - def assert_resolve_pre expected, *specs - util_clear_gems - - util_setup_spec_fetcher(*specs) - - spec = specs.first - - inst = Gem::DependencyInstaller.new :prerelease => true - inst.find_spec_by_name_and_version spec.name, spec.version + inst.find_spec_by_name_and_version 'a' inst.gather_dependencies actual = inst.gems_to_install.map { |s| s.full_name } @@ -620,182 +634,47 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name } end - ## - # [A1] depends on - # [B] > 0 (satisfied by 2.0) - # [B1] depends on - # [C] > 0 (satisfied by 1.0) - # [B2] depends on nothing! - # [C1] depends on nothing - - def test_gather_dependencies_dropped - a1, = util_spec 'a', '1', 'b' => nil - b1, = util_spec 'b', '1', 'c' => nil - b2, = util_spec 'b', '2' - c1, = util_spec 'c', '1' - - assert_resolve %w[b-2 a-1], a1, b1, b2, c1 - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 1.1) depends on - # [Z] - # [C] >= 1.0 depends on - # [B] = 1.0 - # - # and should backtrack to resolve using b-1.0, pruning Z from the - # resolve. - - def test_gather_dependencies_raggi_the_edgecase_generator - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0' - b1, _ = util_spec 'b', '1.0' - b2, _ = util_spec 'b', '1.1', 'z' => '>= 1.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_resolve %w[b-1.0 c-1.0 a-1.0], a, b1, b2, c - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] = 1.0 depends on - # [B] ~> 1.0 - # - # and should resolve using b-1.0 - - def test_gather_dependencies_over - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0' - b1, _ = util_spec 'b', '1.0' - b2, _ = util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '~> 1.0' - - assert_resolve %w[b-1.0 c-1.0 a-1.0], a, b1, b2, c - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.1) - # [C] = 1.0 depends on - # [B] = 1.0 - # - # and should resolve using b-1.0 - # - # TODO: this is not under, but over... under would require depth - # first resolve through a dependency that is later pruned. - - def test_gather_dependencies_under - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - b10, _ = util_spec 'b', '1.0' - b11, _ = util_spec 'b', '1.1' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_resolve %w[b-1.0 c-1.0 a-1.0], a, b10, b11, c - end - - # under - # - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.0) - # [C] = 1.0 depends on - # [B] = 2.0 - - def test_gather_dependencies_divergent - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - b1, _ = util_spec 'b', '1.0' - b2, _ = util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 2.0' - - assert_raises Gem::DependencyError do - assert_resolve :ignored, a, b1, b2, c - end - end - def test_gather_dependencies_platform_alternate - util_setup_wxyz util_set_arch 'cpu-my_platform1' - assert_resolve %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'w' + inst.gather_dependencies + + assert_equal %w[x-1-cpu-my_platform-1 w-1], + inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_platform_bump - util_setup_wxyz + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'z' + inst.gather_dependencies - assert_resolve %w[y-1 z-1], @z1, @y1 + assert_equal %w[y-1 z-1], inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_prerelease - util_setup_c1_pre + inst = Gem::DependencyInstaller.new :prerelease => true + inst.find_spec_by_name_and_version 'c', '1.a' + inst.gather_dependencies - assert_resolve_pre %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1 + assert_equal %w[a-1.a b-1 c-1.a], + inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_old_required - util_setup_d - e1, = util_spec 'e', '1', 'd' => '= 1' - util_clear_gems - - assert_resolve %w[d-1 e-1], e1, @d1, @d2 - end - - def util_write_a1_bin - write_file File.join('gems', 'a-1', 'bin', 'a_bin') do |fp| - fp.puts "#!/usr/bin/ruby" - end - end - - def util_setup_c1_pre - @c1_pre, @c1_pre_gem = util_spec 'c', '1.a' do |s| - s.add_dependency 'a', '1.a' - s.add_dependency 'b', '1' - end - - util_reset_gems - end + e1, = util_gem 'e', '1', 'd' => '= 1' - def util_setup_d - @d1, @d1_gem = util_gem 'd', '1' - @d2, @d2_gem = util_gem 'd', '2' - - util_reset_gems - end - - def util_setup_wxyz - @x1_m, @x1_m_gem = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @x1_o, @x1_o_gem = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu other_platform 1] - end + util_clear_gems - @w1, @w1_gem = util_spec 'w', '1', 'x' => nil + util_setup_spec_fetcher @d1, @d2, e1 - @y1, @y1_gem = util_spec 'y', '1' - @y1_1_p, @y1_1_p_gem = util_spec 'y', '1.1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @z1, @z1_gem = util_spec 'z', '1', 'y' => nil + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'e' + inst.gather_dependencies - util_reset_gems + assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name } end - def util_reset_gems - @c1_pre ||= nil - @d1 ||= nil - @d2 ||= nil - @w1 ||= nil - @x1_m ||= nil - @x1_o ||= nil - @y1 ||= nil - @y1_1_p ||= nil - @z1 ||= nil - - 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 + diff --git a/test/rubygems/test_gem_dependency_list.rb b/test/rubygems/test_gem_dependency_list.rb index 688455475b..92966ace08 100644 --- a/test/rubygems/test_gem_dependency_list.rb +++ b/test/rubygems/test_gem_dependency_list.rb @@ -14,17 +14,17 @@ class TestGemDependencyList < Gem::TestCase @deplist = Gem::DependencyList.new - @a1 = quick_spec 'a', '1' - @a2 = quick_spec 'a', '2' - @a3 = quick_spec 'a', '3' + @a1 = quick_gem 'a', '1' + @a2 = quick_gem 'a', '2' + @a3 = quick_gem 'a', '3' - @b1 = quick_spec 'b', '1' do |s| s.add_dependency 'a', '>= 1' end - @b2 = quick_spec 'b', '2' do |s| s.add_dependency 'a', '>= 1' end + @b1 = quick_gem 'b', '1' do |s| s.add_dependency 'a', '>= 1' end + @b2 = quick_gem 'b', '2' do |s| s.add_dependency 'a', '>= 1' end - @c1 = quick_spec 'c', '1' do |s| s.add_dependency 'b', '>= 1' end - @c2 = quick_spec 'c', '2' + @c1 = quick_gem 'c', '1' do |s| s.add_dependency 'b', '>= 1' end + @c2 = quick_gem 'c', '2' - @d1 = quick_spec 'd', '1' do |s| s.add_dependency 'c', '>= 1' end + @d1 = quick_gem 'd', '1' do |s| s.add_dependency 'c', '>= 1' end end def test_self_from_source_index @@ -72,9 +72,9 @@ class TestGemDependencyList < Gem::TestCase end def test_dependency_order_development - e1 = quick_spec 'e', '1' - f1 = quick_spec 'f', '1' - g1 = quick_spec 'g', '1' + e1 = quick_gem 'e', '1' + f1 = quick_gem 'f', '1' + g1 = quick_gem 'g', '1' @a1.add_dependency 'e' @a1.add_dependency 'f' @@ -100,7 +100,7 @@ class TestGemDependencyList < Gem::TestCase def test_dependency_order_diamond util_diamond - e1 = quick_spec 'e', '1' + e1 = quick_gem 'e', '1' @deplist.add e1 @a1.add_dependency 'e', '>= 1' @@ -128,8 +128,6 @@ class TestGemDependencyList < Gem::TestCase end def test_ok_eh - util_clear_gems - assert @deplist.ok?, 'no dependencies' @deplist.add @b2 @@ -141,30 +139,14 @@ class TestGemDependencyList < Gem::TestCase assert @deplist.ok?, 'satisfied dependency' end - def test_why_not_ok_eh - util_clear_gems - - assert_equal({}, @deplist.why_not_ok?) - - @deplist.add @b2 - - exp = { - "b" => [ - Gem::Dependency.new("a", ">= 1") - ] - } - - assert_equal exp, @deplist.why_not_ok? - end - def test_ok_eh_mismatch - a1 = quick_spec 'a', '1' - a2 = quick_spec 'a', '2' + a1 = quick_gem 'a', '1' + a2 = quick_gem 'a', '2' - b = quick_spec 'b', '1' do |s| s.add_dependency 'a', '= 1' end - c = quick_spec 'c', '1' do |s| s.add_dependency 'a', '= 2' end + b = quick_gem 'b', '1' do |s| s.add_dependency 'a', '= 1' end + c = quick_gem 'c', '1' do |s| s.add_dependency 'a', '= 2' end - d = quick_spec 'd', '1' do |s| + d = quick_gem 'd', '1' do |s| s.add_dependency 'b' s.add_dependency 'c' end @@ -210,8 +192,6 @@ class TestGemDependencyList < Gem::TestCase end def test_remove_by_name - util_clear_gems - @deplist.add @a1, @b2 @deplist.remove_by_name "a-1" diff --git a/test/rubygems/test_gem_doc_manager.rb b/test/rubygems/test_gem_doc_manager.rb index f52f1f87f1..be4c12bd5b 100644 --- a/test/rubygems/test_gem_doc_manager.rb +++ b/test/rubygems/test_gem_doc_manager.rb @@ -12,26 +12,25 @@ class TestGemDocManager < Gem::TestCase def setup super - @spec = quick_gem 'a', 2 + @spec = quick_gem 'a' @manager = Gem::DocManager.new(@spec) end def test_uninstall_doc_unwritable - path = @spec.installation_path - orig_mode = File.stat(path).mode + orig_mode = File.stat(@spec.installation_path).mode # File.chmod has no effect on MS Windows directories (it needs ACL). if win_platform? skip("test_uninstall_doc_unwritable skipped on MS Windows") else - File.chmod 0000, path + File.chmod(0, @spec.installation_path) end assert_raises Gem::FilePermissionError do @manager.uninstall_doc end ensure - File.chmod orig_mode, path + File.chmod orig_mode, @spec.installation_path end end diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb index 6f169588eb..f964cab143 100644 --- a/test/rubygems/test_gem_format.rb +++ b/test/rubygems/test_gem_format.rb @@ -5,7 +5,7 @@ ###################################################################### require 'rubygems/package/tar_test_case' -require 'rubygems/simple_gem' +require 'test/rubygems/simple_gem' require 'rubygems/format' class TestGemFormat < Gem::Package::TarTestCase @@ -20,7 +20,7 @@ class TestGemFormat < Gem::Package::TarTestCase def test_class_from_file_by_path util_make_gems - gems = Dir[Gem.cache_gem('*.gem', @gemhome)] + gems = Dir[File.join(@gemhome, 'cache', '*.gem')] names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec| spec.original_name diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index 71fb965460..a7f49506a6 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -18,20 +18,21 @@ class TestGemIndexer < Gem::TestCase util_make_gems - @d2_0 = quick_spec 'd', '2.0' do |s| + @d2_0 = quick_gem 'd', '2.0' do |s| s.date = Gem::Specification::TODAY - 86400 * 3 end util_build_gem @d2_0 - @d2_0_a = quick_spec 'd', '2.0.a' + @d2_0_a = quick_gem 'd', '2.0.a' util_build_gem @d2_0_a - @d2_0_b = quick_spec 'd', '2.0.b' + @d2_0_b = quick_gem 'd', '2.0.b' util_build_gem @d2_0_b gems = File.join(@tempdir, 'gems') FileUtils.mkdir_p gems - FileUtils.mv Dir[Gem.cache_gem('*.gem', @gemhome)], gems + cache_gems = File.join @gemhome, 'cache', '*.gem' + FileUtils.mv Dir[cache_gems], gems @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems', :rss_host => 'example.com', @@ -59,7 +60,7 @@ class TestGemIndexer < Gem::TestCase end def test_build_indicies - spec = quick_spec 'd', '2.0' + spec = quick_gem 'd', '2.0' spec.instance_variable_set :@original_platform, '' @indexer.make_temp_directories @@ -509,17 +510,17 @@ eighty characters.</pre> assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - @d2_1 = quick_spec 'd', '2.1' + @d2_1 = quick_gem 'd', '2.1' util_build_gem @d2_1 @d2_1_tuple = [@d2_1.name, @d2_1.version, @d2_1.original_platform] - @d2_1_a = quick_spec 'd', '2.2.a' + @d2_1_a = quick_gem 'd', '2.2.a' 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 Gem.cache_gem(@d2_1.file_name, @gemhome), gems - FileUtils.mv Gem.cache_gem(@d2_1_a.file_name, @gemhome), gems + FileUtils.mv File.join(@gemhome, 'cache', @d2_1.file_name), gems + FileUtils.mv File.join(@gemhome, 'cache', @d2_1_a.file_name), gems use_ui @ui do @indexer.update_index diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index fe10fd4949..937774617f 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -69,4 +69,6 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase ensure FileUtils.chmod 0755, @gemhome end + end + diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 0b73af996d..94fa4423bc 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -9,8 +9,7 @@ require 'rubygems/installer_test_case' class TestGemInstaller < Gem::InstallerTestCase def test_app_script_text - @spec.version = 2 - util_make_exec @spec, '' + util_make_exec '2', '' expected = <<-EOF #!#{Gem.ruby} @@ -31,10 +30,10 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then end gem 'a', version -load Gem.bin_path('a', 'executable', version) +load Gem.bin_path('a', 'my_exec', version) EOF - wrapper = @installer.app_script_text 'executable' + wrapper = @installer.app_script_text 'my_exec' assert_equal expected, wrapper end @@ -102,7 +101,7 @@ load Gem.bin_path('a', 'executable', version) @installer.ensure_dependency @spec, dep end - assert_equal 'a requires b (> 2)', e.message + assert_equal 'a requires b (> 2, runtime)', e.message end def test_extract_files @@ -171,11 +170,11 @@ load Gem.bin_path('a', 'executable', version) def test_generate_bin_bindir @installer.wrappers = true - @spec.executables = %w[executable] + @spec.executables = ["my_exec"] @spec.bindir = '.' - exec_file = @installer.formatted_program_filename 'executable' - exec_path = File.join util_gem_dir(@spec), exec_file + exec_file = @installer.formatted_program_filename "my_exec" + exec_path = File.join util_gem_dir(@spec.version), exec_file File.open exec_path, 'w' do |f| f.puts '#!/usr/bin/ruby' end @@ -185,7 +184,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -200,7 +199,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -217,7 +216,7 @@ load Gem.bin_path('a', 'executable', version) Gem::Installer.exec_format = 'foo-%s-bar' @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join util_inst_bindir, 'foo-executable-bar' + installed_exec = File.join util_inst_bindir, 'foo-my_exec-bar' assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil @@ -231,7 +230,7 @@ load Gem.bin_path('a', 'executable', version) Gem::Installer.exec_format = 'foo-%s-bar' @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join util_inst_bindir, 'executable' + installed_exec = File.join util_inst_bindir, 'my_exec' assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil @@ -239,12 +238,12 @@ load Gem.bin_path('a', 'executable', version) def test_generate_bin_script_install_dir @installer.wrappers = true - @spec.executables = %w[executable] + @spec.executables = ["my_exec"] gem_dir = File.join "#{@gemhome}2", 'gems', @spec.full_name gem_bindir = File.join gem_dir, 'bin' FileUtils.mkdir_p gem_bindir - File.open File.join(gem_bindir, 'executable'), 'w' do |f| + File.open File.join(gem_bindir, "my_exec"), 'w' do |f| f.puts "#!/bin/ruby" end @@ -253,7 +252,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin - installed_exec = File.join("#{@gemhome}2", 'bin', 'executable') + installed_exec = File.join("#{@gemhome}2", 'bin', 'my_exec') assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -262,12 +261,9 @@ load Gem.bin_path('a', 'executable', version) end def test_generate_bin_script_no_execs - util_execless - @installer.wrappers = true @installer.generate_bin - - refute File.exist?(util_inst_bindir), 'bin dir was created when not needed' + assert_equal false, File.exist?(util_inst_bindir) end def test_generate_bin_script_no_perms @@ -291,18 +287,18 @@ load Gem.bin_path('a', 'executable', version) def test_generate_bin_script_no_shebang @installer.wrappers = true - @spec.executables = %w[executable] + @spec.executables = ["my_exec"] gem_dir = File.join @gemhome, 'gems', @spec.full_name gem_bindir = File.join gem_dir, 'bin' FileUtils.mkdir_p gem_bindir - File.open File.join(gem_bindir, 'executable'), 'w' do |f| + File.open File.join(gem_bindir, "my_exec"), 'w' do |f| f.puts "blah blah blah" end @installer.generate_bin - installed_exec = File.join @gemhome, 'bin', 'executable' + installed_exec = File.join @gemhome, 'bin', 'my_exec' assert_equal true, File.exist?(installed_exec) assert_equal 0100755, File.stat(installed_exec).mode unless win_platform? @@ -316,9 +312,9 @@ load Gem.bin_path('a', 'executable', version) @installer.wrappers = true util_make_exec @installer.gem_dir = util_gem_dir - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") - real_exec = File.join util_gem_dir, 'bin', 'executable' + real_exec = File.join util_gem_dir, 'bin', 'my_exec' # fake --no-wrappers for previous install unless Gem.win_platform? then @@ -346,19 +342,16 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.symlink?(installed_exec) - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + assert_equal(File.join(util_gem_dir, "bin", "my_exec"), File.readlink(installed_exec)) end def test_generate_bin_symlink_no_execs - util_execless - @installer.wrappers = false @installer.generate_bin - - refute File.exist?(util_inst_bindir) + assert_equal false, File.exist?(util_inst_bindir) end def test_generate_bin_symlink_no_perms @@ -389,8 +382,8 @@ load Gem.bin_path('a', 'executable', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir, "bin", "my_exec"), File.readlink(installed_exec)) @spec = Gem::Specification.new do |s| @@ -402,12 +395,11 @@ load Gem.bin_path('a', 'executable', version) s.require_path = 'lib' end - @spec.version = 3 - util_make_exec - @installer.gem_dir = File.join util_gem_dir @spec + util_make_exec '3' + @installer.gem_dir = File.join util_gem_dir('3') @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_bindir(@spec), 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_bindir('3'), "my_exec"), File.readlink(installed_exec), "Ensure symlink moved to latest version") end @@ -420,8 +412,8 @@ load Gem.bin_path('a', 'executable', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir, "bin", "my_exec"), File.readlink(installed_exec)) spec = Gem::Specification.new do |s| @@ -433,16 +425,14 @@ load Gem.bin_path('a', 'executable', version) s.require_path = 'lib' end - util_make_exec - one = @spec.dup - one.version = 1 - @installer.gem_dir = util_gem_dir one + util_make_exec '1' + @installer.gem_dir = util_gem_dir('1') @installer.spec = spec @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir('2'), "bin", "my_exec"), File.readlink(installed_exec), "Ensure symlink not moved") end @@ -455,7 +445,7 @@ load Gem.bin_path('a', 'executable', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) @spec = Gem::Specification.new do |s| @@ -468,12 +458,11 @@ load Gem.bin_path('a', 'executable', version) end @installer.wrappers = false - @spec.version = 3 - util_make_exec - @installer.gem_dir = util_gem_dir + util_make_exec '3' + @installer.gem_dir = util_gem_dir '3' @installer.generate_bin - installed_exec = File.join(util_inst_bindir, 'executable') - assert_equal(File.join(util_gem_dir, 'bin', 'executable'), + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal(File.join(util_gem_dir('3'), "bin", "my_exec"), File.readlink(installed_exec), "Ensure symlink moved to latest version") end @@ -490,7 +479,7 @@ load Gem.bin_path('a', 'executable', version) end assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, 'executable') + installed_exec = File.join(util_inst_bindir, "my_exec") assert_equal true, File.exist?(installed_exec) assert_match(/Unable to use symlinks on Windows, installing wrapper/i, @@ -511,18 +500,19 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin default_shebang = Gem.ruby - shebang_line = open("#{@gemhome}/bin/executable") { |f| f.readlines.first } + shebang_line = open("#{@gemhome}/bin/my_exec") { |f| f.readlines.first } assert_match(/\A#!/, shebang_line) assert_match(/#{default_shebang}/, shebang_line) end def test_initialize - spec = quick_spec 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end + spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end gem = File.join @tempdir, spec.file_name Dir.mkdir util_inst_bindir util_build_gem spec - FileUtils.mv Gem.cache_gem(spec.file_name, @gemhome), @tempdir + FileUtils.mv File.join(@gemhome, 'cache', spec.file_name), + @tempdir installer = Gem::Installer.new gem @@ -535,7 +525,7 @@ load Gem.bin_path('a', 'executable', version) util_clear_gems gemdir = File.join @gemhome, 'gems', @spec.full_name - cache_file = Gem.cache_gem(@spec.file_name, @gemhome) + cache_file = File.join @gemhome, 'cache', @spec.file_name stub_exe = File.join @gemhome, 'bin', 'executable' rakefile = File.join gemdir, 'ext', 'a', 'Rakefile' @@ -584,42 +574,6 @@ load Gem.bin_path('a', 'executable', version) assert_same @installer, @pre_install_hook_arg 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 File.exist?(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 - File.open File.join('lib', 'other.rb'), 'w' do |f| f.puts '1' end - use_ui ui do - FileUtils.rm @gem - Gem::Builder.new(@spec).build - end - end - @installer = Gem::Installer.new @gem - build_rake_in do - use_ui @ui do - assert_equal @spec, @installer.install - end - end - - assert File.exist?(File.join(gemdir, 'lib', 'other.rb')) - refute(File.exist?(File.join(gemdir, 'lib', 'code.rb')), - "code.rb from prior install of same gem shouldn't remain here") - end - def test_install_bad_gem gem = nil @@ -656,7 +610,7 @@ load Gem.bin_path('a', 'executable', version) gemhome2 = "#{@gemhome}2" @spec.add_dependency 'b' - b2 = quick_spec 'b', 2 + b2 = quick_gem 'b', 2 FileUtils.mv @gemhome, gemhome2 Gem.source_index.gems.delete b2.full_name @@ -712,7 +666,7 @@ load Gem.bin_path('a', 'executable', version) end def test_install_missing_dirs - FileUtils.rm_f Gem.cache_dir + FileUtils.rm_f File.join(Gem.dir, 'cache') FileUtils.rm_f File.join(Gem.dir, 'docs') FileUtils.rm_f File.join(Gem.dir, 'specifications') @@ -722,11 +676,11 @@ load Gem.bin_path('a', 'executable', version) @installer.install end - File.directory? Gem.cache_dir + File.directory? File.join(Gem.dir, 'cache') File.directory? File.join(Gem.dir, 'docs') File.directory? File.join(Gem.dir, 'specifications') - assert File.exist?(Gem.cache_gem(@spec.file_name, @gemhome)) + assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name)) assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name)) end @@ -832,13 +786,13 @@ load Gem.bin_path('a', 'executable', version) end def test_install_wrong_rubygems_version - spec = quick_spec 'old_rubygems_required', '1' do |s| + spec = quick_gem 'old_rubygems_required', '1' do |s| s.required_rubygems_version = '< 0' end util_build_gem spec - gem = Gem.cache_gem(spec.file_name, @gemhome) + gem = File.join @gemhome, 'cache', spec.file_name use_ui @ui do @installer = Gem::Installer.new gem @@ -859,49 +813,49 @@ load Gem.bin_path('a', 'executable', version) end def test_shebang - util_make_exec @spec, "#!/usr/bin/ruby" + util_make_exec '2', "#!/usr/bin/ruby" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_arguments - util_make_exec @spec, "#!/usr/bin/ruby -ws" + util_make_exec '2', "#!/usr/bin/ruby -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_empty - util_make_exec @spec, '' + util_make_exec '2', '' - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env - util_make_exec @spec, "#!/usr/bin/env ruby" + util_make_exec '2', "#!/usr/bin/env ruby" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env_arguments - util_make_exec @spec, "#!/usr/bin/env ruby -ws" + util_make_exec '2', "#!/usr/bin/env ruby -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_env_shebang - util_make_exec @spec, '' + util_make_exec '2', '' @installer.env_shebang = true - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' env_shebang = "/usr/bin/env" unless Gem.win_platform? @@ -910,49 +864,49 @@ load Gem.bin_path('a', 'executable', version) end def test_shebang_nested - util_make_exec @spec, "#!/opt/local/ruby/bin/ruby" + util_make_exec '2', "#!/opt/local/ruby/bin/ruby" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_nested_arguments - util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws" + util_make_exec '2', "#!/opt/local/ruby/bin/ruby -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version - util_make_exec @spec, "#!/usr/bin/ruby18" + util_make_exec '2', "#!/usr/bin/ruby18" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_arguments - util_make_exec @spec, "#!/usr/bin/ruby18 -ws" + util_make_exec '2', "#!/usr/bin/ruby18 -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version_env - util_make_exec @spec, "#!/usr/bin/env ruby18" + util_make_exec '2', "#!/usr/bin/env ruby18" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_env_arguments - util_make_exec @spec, "#!/usr/bin/env ruby18 -ws" + util_make_exec '2', "#!/usr/bin/env ruby18 -ws" - shebang = @installer.shebang 'executable' + shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby} -ws", shebang end @@ -983,41 +937,14 @@ load Gem.bin_path('a', 'executable', version) assert_equal @spec, eval(File.read(spec_file)) end - def test_write_spec_writes_cached_spec - spec_dir = File.join @gemhome, 'specifications' - spec_file = File.join spec_dir, @spec.spec_name - FileUtils.rm spec_file - refute File.exist?(spec_file) - - @spec.files = %w[a.rb b.rb c.rb] - - @installer.spec = @spec - @installer.gem_home = @gemhome - - @installer.write_spec - - # cached specs have no file manifest: - @spec.files = [] - - assert_equal @spec, eval(File.read(spec_file)) - end - def old_ruby_required - spec = quick_spec 'old_ruby_required', '1' do |s| + spec = quick_gem 'old_ruby_required', '1' do |s| s.required_ruby_version = '= 1.4.6' end util_build_gem spec - Gem.cache_gem(spec.file_name, @gemhome) - end - - def util_execless - @spec = quick_spec 'z' - - gem = File.join @tempdir, @spec.file_name - - @installer = util_installer @spec, gem, @gemhome + File.join @gemhome, 'cache', spec.file_name end end diff --git a/test/rubygems/test_gem_package_tar_output.rb b/test/rubygems/test_gem_package_tar_output.rb index 77f31852f9..7458a749dd 100644 --- a/test/rubygems/test_gem_package_tar_output.rb +++ b/test/rubygems/test_gem_package_tar_output.rb @@ -55,9 +55,6 @@ class TestGemPackageTarOutput < Gem::Package::TarTestCase if defined? OpenSSL then def test_self_open_signed - @private_key = File.expand_path('test/rubygems/private_key.pem', @@project_dir) - @public_cert = File.expand_path('test/rubygems/public_cert.pem', @@project_dir) - signer = Gem::Security::Signer.new @private_key, [@public_cert] open @file, 'wb' do |tar_io| diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 66fb682c6c..135b2c7e53 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -99,10 +99,9 @@ gems: # REFACTOR: copied from test_gem_dependency_installer.rb @gems_dir = File.join @tempdir, 'gems' - @cache_dir = Gem.cache_dir(@gemhome) + @cache_dir = File.join @gemhome, 'cache' FileUtils.mkdir @gems_dir - # TODO: why does the remote fetcher need it written to disk? @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end Gem::RemoteFetcher.fetcher = nil @@ -209,7 +208,7 @@ gems: fetcher = util_fuck_with_fetcher a1_data - a1_cache_gem = Gem.cache_gem(@a1.file_name, @gemhome) + a1_cache_gem = File.join(@gemhome, 'cache', @a1.file_name) assert_equal a1_cache_gem, fetcher.download(@a1, 'http://gems.example.com') assert_equal("http://gems.example.com/gems/a-1.gem", fetcher.instance_variable_get(:@test_arg).to_s) @@ -221,7 +220,7 @@ gems: inst = Gem::RemoteFetcher.fetcher - assert_equal Gem.cache_gem(@a1.file_name, @gemhome), + assert_equal File.join(@gemhome, 'cache', @a1.file_name), inst.download(@a1, 'http://gems.example.com') end @@ -234,7 +233,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - assert_equal Gem.cache_gem(@a1.file_name, @gemhome), + assert_equal File.join(@gemhome, 'cache', @a1.file_name), inst.download(@a1, local_path) end @@ -249,7 +248,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - assert_equal Gem.cache_gem(@a1.file_name, @gemhome), + assert_equal File.join(@gemhome, 'cache', @a1.file_name), inst.download(@a1, local_path) end @@ -263,7 +262,7 @@ gems: install_dir = File.join @tempdir, 'more_gems' - a1_cache_gem = Gem.cache_gem(@a1.file_name, install_dir) + a1_cache_gem = File.join install_dir, 'cache', @a1.file_name FileUtils.mkdir_p(File.dirname(a1_cache_gem)) actual = fetcher.download(@a1, 'http://gems.example.com', install_dir) @@ -279,7 +278,7 @@ gems: FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, @a1.file_name inst = nil - File.chmod 0555, Gem.cache_dir(@gemhome) + File.chmod 0555, File.join(@gemhome, 'cache') Dir.chdir @tempdir do inst = Gem::RemoteFetcher.fetcher @@ -288,19 +287,19 @@ gems: assert_equal File.join(@tempdir, @a1.file_name), inst.download(@a1, local_path) ensure - File.chmod 0755, Gem.cache_dir(@gemhome) + File.chmod 0755, File.join(@gemhome, 'cache') end def test_download_read_only - File.chmod 0555, Gem.cache_dir(@gemhome) + File.chmod 0555, File.join(@gemhome, 'cache') File.chmod 0555, File.join(@gemhome) fetcher = util_fuck_with_fetcher File.read(@a1_gem) fetcher.download(@a1, 'http://gems.example.com') - assert File.exist?(Gem.cache_gem(@a1.file_name, Gem.user_dir)) + assert File.exist?(File.join(Gem.user_dir, 'cache', @a1.file_name)) ensure - File.chmod 0755, @gemhome - File.chmod 0755, Gem.cache_dir(@gemhome) + File.chmod 0755, File.join(@gemhome) + File.chmod 0755, File.join(@gemhome, 'cache') end end @@ -319,7 +318,7 @@ gems: fetcher = util_fuck_with_fetcher e1_data, :blow_chunks - e1_cache_gem = Gem.cache_gem(e1.file_name, @gemhome) + e1_cache_gem = File.join(@gemhome, 'cache', e1.file_name) assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com') @@ -337,7 +336,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - cache_path = Gem.cache_gem(@a1.file_name, @gemhome) + cache_path = File.join @gemhome, 'cache', @a1.file_name FileUtils.mv local_path, cache_path gem = Gem::Format.from_file_by_path cache_path @@ -745,13 +744,5 @@ gems: end 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 diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb index 89e2ea3894..9846c9cc89 100644 --- a/test/rubygems/test_gem_source_index.rb +++ b/test/rubygems/test_gem_source_index.rb @@ -23,7 +23,7 @@ class TestGemSourceIndex < Gem::TestCase FileUtils.mkdir_p spec_dir - a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end + a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end spec_file = File.join spec_dir, a1.spec_name @@ -44,7 +44,7 @@ class TestGemSourceIndex < Gem::TestCase FileUtils.mkdir_p spec_dir - a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end + a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end spec_file = File.join spec_dir, a1.spec_name @@ -214,24 +214,24 @@ end end def test_latest_specs - p1_ruby = quick_spec 'p', '1' - p1_platform = quick_spec 'p', '1' do |spec| + p1_ruby = quick_gem 'p', '1' + p1_platform = quick_gem 'p', '1' do |spec| spec.platform = Gem::Platform::CURRENT end - a1_platform = quick_spec @a1.name, (@a1.version) do |s| + a1_platform = quick_gem @a1.name, (@a1.version) do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a2_platform = quick_spec @a2.name, (@a2.version) do |s| + a2_platform = quick_gem @a2.name, (@a2.version) do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a2_platform_other = quick_spec @a2.name, (@a2.version) do |s| + a2_platform_other = quick_gem @a2.name, (@a2.version) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end - a3_platform_other = quick_spec @a2.name, (@a2.version.bump) do |s| + a3_platform_other = quick_gem @a2.name, (@a2.version.bump) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end @@ -266,8 +266,8 @@ end FileUtils.mkdir_p spec_dir1 FileUtils.mkdir_p spec_dir2 - a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end - a2 = quick_spec 'a', '1' do |spec| spec.author = 'author 2' end + a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end + a2 = quick_gem 'a', '1' do |spec| spec.author = 'author 2' end File.open File.join(spec_dir1, a1.spec_name), 'w' do |fp| fp.write a1.to_ruby @@ -287,12 +287,12 @@ end assert_equal [], @source_index.outdated - updated = quick_spec @a2.name, (@a2.version.bump) + updated = quick_gem @a2.name, (@a2.version.bump) util_setup_spec_fetcher updated assert_equal [updated.name], @source_index.outdated - updated_platform = quick_spec @a2.name, (updated.version.bump) do |s| + updated_platform = quick_gem @a2.name, (updated.version.bump) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end @@ -302,11 +302,10 @@ end end def test_prerelease_specs_kept_in_right_place - gem_a1_alpha = quick_spec 'abba', '1.a' + gem_a1_alpha = quick_gem 'abba', '1.a' @source_index.add_spec gem_a1_alpha refute @source_index.latest_specs.include?(gem_a1_alpha) - assert @source_index.latest_specs(true).include?(gem_a1_alpha) assert @source_index.find_name(gem_a1_alpha.full_name).empty? assert @source_index.prerelease_specs.include?(gem_a1_alpha) end @@ -364,11 +363,11 @@ end def test_search_platform util_set_arch 'x86-my_platform1' - a1 = quick_spec 'a', '1' - a1_mine = quick_spec 'a', '1' do |s| + a1 = quick_gem 'a', '1' + a1_mine = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a1_other = quick_spec 'a', '1' do |s| + a1_other = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 57983a2752..6e3891b866 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -16,7 +16,7 @@ class TestGemSpecFetcher < Gem::TestCase util_setup_fake_fetcher - @a_pre = quick_spec 'a', '1.a' + @a_pre = quick_gem 'a', '1.a' @source_index.add_spec @pl1 @source_index.add_spec @a_pre @@ -412,10 +412,5 @@ class TestGemSpecFetcher < Gem::TestCase assert_equal @latest_specs, latest_specs end - def test_cache_dir_escapes_windows_paths - uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo") - cache_dir = @sf.cache_dir(uri) - assert cache_dir !~ /:/, "#{cache_dir} should not contain a :" - end end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index f820d7c1c3..49862fe4bb 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -46,7 +46,6 @@ end def setup super - # TODO: there is no reason why the spec tests need to write to disk @a1 = quick_gem 'a', '1' do |s| s.executable = 'exec' s.extensions << 'ext/a/extconf.rb' @@ -168,13 +167,6 @@ end Gem::Specification.normalize_yaml_input(StringIO.new(input)) end - def test_self_normalize_yaml_input_with_192_yaml - input = "--- !ruby/object:Gem::Specification \nblah: !!null \n" - expected = "--- !ruby/object:Gem::Specification \nblah: \n" - - assert_equal expected, Gem::Specification.normalize_yaml_input(input) - end - def test_initialize spec = Gem::Specification.new do |s| s.name = "blah" @@ -302,7 +294,7 @@ end end def test_add_dependency_with_explicit_type - gem = quick_spec "awesome", "1.0" do |awesome| + gem = quick_gem "awesome", "1.0" do |awesome| awesome.add_development_dependency "monkey" end @@ -379,19 +371,18 @@ end assert_equal [rake, jabber, pqa], @a1.dependencies end - def test_dependencies - util_setup_deps - assert_equal [@bonobo, @monkey], @gem.dependencies - end + def test_dependencies_scoped_by_type + gem = quick_gem "awesome", "1.0" do |awesome| + awesome.add_runtime_dependency "bonobo", [] + awesome.add_development_dependency "monkey", [] + end - def test_runtime_dependencies - util_setup_deps - assert_equal [@bonobo], @gem.runtime_dependencies - end + bonobo = Gem::Dependency.new("bonobo", []) + monkey = Gem::Dependency.new("monkey", [], :development) - def test_development_dependencies - util_setup_deps - assert_equal [@monkey], @gem.development_dependencies + assert_equal([bonobo, monkey], gem.dependencies) + assert_equal([bonobo], gem.runtime_dependencies) + assert_equal([monkey], gem.development_dependencies) end def test_description @@ -399,8 +390,8 @@ end end def test_eql_eh - g1 = quick_spec 'gem' - g2 = quick_spec 'gem' + g1 = quick_gem 'gem' + g2 = quick_gem 'gem' assert_equal g1, g2 assert_equal g1.hash, g2.hash @@ -699,7 +690,7 @@ end end def test_prerelease_spec_adds_required_rubygems_version - @prerelease = quick_spec('tardis', '2.2.0.a') + @prerelease = quick_gem('tardis', '2.2.0.a') refute @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.3.1')) assert @prerelease.required_rubygems_version.satisfied_by?(Gem::Version.new('1.4.0')) end @@ -725,8 +716,8 @@ end end def test_spaceship_name - s1 = quick_spec 'a', '1' - s2 = quick_spec 'b', '1' + s1 = quick_gem 'a', '1' + s2 = quick_gem 'b', '1' assert_equal(-1, (s1 <=> s2)) assert_equal( 0, (s1 <=> s1)) @@ -734,8 +725,8 @@ end end def test_spaceship_platform - s1 = quick_spec 'a', '1' - s2 = quick_spec 'a', '1' do |s| + s1 = quick_gem 'a', '1' + s2 = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end @@ -745,8 +736,8 @@ end end def test_spaceship_version - s1 = quick_spec 'a', '1' - s2 = quick_spec 'a', '2' + s1 = quick_gem 'a', '1' + s2 = quick_gem 'a', '2' assert_equal( -1, (s1 <=> s2)) assert_equal( 0, (s1 <=> s1)) @@ -812,54 +803,6 @@ end assert_equal @a2, same_spec end - def test_to_ruby_for_cache - @a2.add_runtime_dependency 'b', '1' - @a2.dependencies.first.instance_variable_set :@type, nil - @a2.required_rubygems_version = Gem::Requirement.new '> 0' - - # cached specs do not have spec.files populated: - ruby_code = @a2.to_ruby_for_cache - - expected = <<-SPEC -# -*- encoding: utf-8 -*- - -Gem::Specification.new do |s| - s.name = %q{a} - s.version = \"2\" - - s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version= - s.authors = [\"A User\"] - s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}} - s.description = %q{This is a test description} - s.email = %q{example@example.com} - s.homepage = %q{http://example.com} - s.require_paths = [\"lib\"] - s.rubygems_version = %q{#{Gem::VERSION}} - s.summary = %q{this is a summary} - - if s.respond_to? :specification_version then - s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [\"= 1\"]) - else - s.add_dependency(%q, [\"= 1\"]) - end - else - s.add_dependency(%q, [\"= 1\"]) - end -end - SPEC - - assert_equal expected, ruby_code - - same_spec = eval ruby_code - - # cached specs do not have spec.files populated: - @a2.files = [] - assert_equal @a2, same_spec - end - def test_to_ruby_fancy @a1.platform = Gem::Platform.local ruby_code = @a1.to_ruby @@ -899,16 +842,16 @@ Gem::Specification.new do |s| if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [\"> 0.4\"]) s.add_runtime_dependency(%q, [\"> 0.0.0\"]) - s.add_runtime_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) + s.add_runtime_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) else s.add_dependency(%q, [\"> 0.4\"]) s.add_dependency(%q, [\"> 0.0.0\"]) - s.add_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) + s.add_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) end else s.add_dependency(%q, [\"> 0.4\"]) s.add_dependency(%q, [\"> 0.0.0\"]) - s.add_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) + s.add_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) end end SPEC @@ -941,9 +884,6 @@ end def test_to_yaml yaml_str = @a1.to_yaml - - refute_match '!!null', yaml_str - same_spec = YAML.load(yaml_str) assert_equal @a1, same_spec @@ -1318,16 +1258,6 @@ end specfile.delete end - def util_setup_deps - @gem = quick_spec "awesome", "1.0" do |awesome| - awesome.add_runtime_dependency "bonobo", [] - awesome.add_development_dependency "monkey", [] - end - - @bonobo = Gem::Dependency.new("bonobo", []) - @monkey = Gem::Dependency.new("monkey", [], :development) - end - def util_setup_validate Dir.chdir @tempdir do FileUtils.mkdir_p File.join('ext', 'a') @@ -1339,4 +1269,6 @@ end FileUtils.touch File.join('test', 'suite.rb') end end + end + diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index 0c08f42d01..3925ab1a63 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -12,19 +12,19 @@ class TestGemUninstaller < Gem::InstallerTestCase def setup super - @user_spec.executables = ["executable"] + @user_spec.executables = ["my_exec"] # HACK util_make_exec user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin' FileUtils.mkdir_p user_bin_dir - exec_path = File.join user_bin_dir, "executable" + exec_path = File.join user_bin_dir, "my_exec" open exec_path, 'w' do |f| f.puts "#!/usr/bin/ruby" end user_bin_dir = File.join Gem.user_dir, 'bin' FileUtils.mkdir_p user_bin_dir - exec_path = File.join user_bin_dir, "executable" + exec_path = File.join user_bin_dir, "my_exec" open exec_path, 'w' do |f| f.puts "#!/usr/bin/ruby" end @@ -47,8 +47,8 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_remove_executables_force_keep uninstaller = Gem::Uninstaller.new nil, :executables => false - executable = File.join Gem.user_dir, 'bin', 'executable' - assert File.exist?(executable), 'executable not written' + executable = File.join Gem.user_dir, 'bin', 'my_exec' + assert File.exist? executable use_ui @ui do uninstaller.remove_executables @user_spec @@ -62,14 +62,14 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_remove_executables_force_remove uninstaller = Gem::Uninstaller.new nil, :executables => true - executable = File.join Gem.user_dir, 'bin', 'executable' - assert File.exist?(executable), 'executable not written' + executable = File.join Gem.user_dir, 'bin', 'my_exec' + assert File.exist? executable use_ui @ui do uninstaller.remove_executables @user_spec end - assert_equal "Removing executable\n", @ui.output + assert_equal "Removing my_exec\n", @ui.output refute File.exist? executable end @@ -81,47 +81,12 @@ class TestGemUninstaller < Gem::InstallerTestCase uninstaller.remove_executables @user_spec end - exec_path = File.join Gem.user_dir, 'bin', 'executable' + exec_path = File.join Gem.user_dir, 'bin', 'my_exec' assert_equal false, File.exist?(exec_path), 'removed exec from bin dir' - assert_equal "Removing executable\n", @ui.output + assert_equal "Removing my_exec\n", @ui.output end - def test_remove_executables_user_format - Gem::Installer.exec_format = 'foo-%s-bar' - - uninstaller = Gem::Uninstaller.new nil, :executables => true, :format_executable => true - - use_ui @ui do - uninstaller.remove_executables @user_spec - end - - exec_path = File.join Gem.user_dir, 'bin', 'foo-executable-bar' - assert_equal false, File.exist?(exec_path), 'removed exec from bin dir' - - assert_equal "Removing executable\n", @ui.output - ensure - Gem::Installer.exec_format = nil - end - - def test_remove_executables_user_format_disabled - Gem::Installer.exec_format = 'foo-%s-bar' - - uninstaller = Gem::Uninstaller.new nil, :executables => true - - use_ui @ui do - uninstaller.remove_executables @user_spec - end - - exec_path = File.join Gem.user_dir, 'bin', 'executable' - assert_equal false, File.exist?(exec_path), 'removed exec from bin dir' - - assert_equal "Removing executable\n", @ui.output - ensure - Gem::Installer.exec_format = nil - end - - def test_path_ok_eh uninstaller = Gem::Uninstaller.new nil @@ -164,31 +129,6 @@ class TestGemUninstaller < Gem::InstallerTestCase assert_same uninstaller, @post_uninstall_hook_arg end - def test_uninstall_not_ok - quick_gem 'z' do |s| - s.add_runtime_dependency @spec.name - end - - uninstaller = Gem::Uninstaller.new @spec.name - - gem_dir = File.join @gemhome, 'gems', @spec.full_name - executable = File.join @gemhome, 'bin', 'executable' - - assert File.exist?(gem_dir), 'gem_dir must exist' - assert File.exist?(executable), 'executable must exist' - - ui = Gem::MockGemUi.new "n\n" - - assert_raises Gem::DependencyRemovalException do - use_ui ui do - uninstaller.uninstall - end - end - - assert File.exist?(gem_dir), 'gem_dir must still exist' - assert File.exist?(executable), 'executable must still exist' - end - def test_uninstall_user uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true, :user_install => true diff --git a/test/rubygems/test_gem_validator.rb b/test/rubygems/test_gem_validator.rb index 304c141483..aa4bd38eb6 100644 --- a/test/rubygems/test_gem_validator.rb +++ b/test/rubygems/test_gem_validator.rb @@ -5,7 +5,7 @@ ###################################################################### require 'rubygems/test_case' -require "rubygems/simple_gem" +require "test/rubygems/simple_gem" require 'rubygems/validator' class TestGemValidator < Gem::TestCase diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb index d3714a2c59..98d27a6123 100644 --- a/test/rubygems/test_kernel.rb +++ b/test/rubygems/test_kernel.rb @@ -46,7 +46,7 @@ class TestKernel < Gem::TestCase gem 'a', '= 2' end - assert_match(/activate a \(= 2\)/, ex.message) + assert_match(/activate a \(= 2, runtime\)/, ex.message) assert_match(/activated a-1/, ex.message) assert_equal 'a', ex.name assert_equal Gem::Requirement.new('= 2'), ex.requirement -- cgit v1.2.3