From 1df42597d15416357a20bd68700ce1a2d245e8bb Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 7 Mar 2011 08:44:45 +0000 Subject: cancel subversion backfire. sorry git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 33 ++ test/ruby/test_m17n.rb | 1 + test/ruby/test_process.rb | 18 +- test/ruby/test_string.rb | 32 ++ test/ruby/test_system.rb | 30 +- 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 +- 38 files changed, 1463 insertions(+), 413 deletions(-) (limited to 'test') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 6cc2897f5f..6b8e6b58ce 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1776,4 +1776,37 @@ End end end end + + def test_fcntl_lock + return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform + + pad=0 + Tempfile.open(self.class.name) do |f| + r, w = IO.pipe + pid = fork do + r.close + lock = [Fcntl::F_WRLCK, IO::SEEK_SET, pad, 12, 34, 0].pack("s!s!i!L!L!i!") + f.fcntl Fcntl::F_SETLKW, lock + w.syswrite "." + sleep + end + w.close + assert_equal ".", r.read(1) + r.close + pad = 0 + getlock = [Fcntl::F_WRLCK, 0, pad, 0, 0, 0].pack("s!s!i!L!L!i!") + f.fcntl Fcntl::F_GETLK, getlock + + ptype, whence, pad, start, len, lockpid = getlock.unpack("s!s!i!L!L!i!") + + assert_equal(ptype, Fcntl::F_WRLCK) + assert_equal(whence, IO::SEEK_SET) + assert_equal(start, 12) + assert_equal(len, 34) + assert_equal(pid, lockpid) + + Process.kill :TERM, pid + Process.waitpid2(pid) + end + end end diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index a29d509fc4..c4bc9e6637 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -962,6 +962,7 @@ class TestM17N < Test::Unit::TestCase assert_equal("X\u3042\u3044X", "A\u3042\u3044\u3046".tr("^\u3042\u3044", "X")) assert_equal("\u3042\u3046" * 100, ("\u3042\u3044" * 100).tr("\u3044", "\u3046")) + assert_equal("Y", "\u3042".tr("^X", "Y")) end def test_tr_s diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index b45bfb9bb0..f3f3f9eb80 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -384,16 +384,20 @@ class TestProcess < Test::Unit::TestCase Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]) assert_equal("c", File.read("out").chomp) File.open("out", "w") {|f| - Process.wait Process.spawn(*ECHO["d"], f=>STDOUT, STDOUT=>f) + Process.wait Process.spawn(*ECHO["d"], STDOUT=>f) assert_equal("d", File.read("out").chomp) } - Process.wait Process.spawn(*ECHO["e"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], - 3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT) + opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} + if /mswin|mingw/ !~ RUBY_PLATFORM + opts.merge(3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT) + end + Process.wait Process.spawn(*ECHO["e"], opts) assert_equal("e", File.read("out").chomp) - Process.wait Process.spawn(*ECHO["ee"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644], - 3=>0, 4=>:in, 5=>STDIN, - 6=>1, 7=>:out, 8=>STDOUT, - 9=>2, 10=>:err, 11=>STDERR) + opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]} + if /mswin|mingw/ !~ RUBY_PLATFORM + opts.merge(3=>0, 4=>:in, 5=>STDIN, 6=>1, 7=>:out, 8=>STDOUT, 9=>2, 10=>:err, 11=>STDERR) + end + Process.wait Process.spawn(*ECHO["ee"], opts) assert_equal("ee", File.read("out").chomp) if /mswin|mingw/ !~ RUBY_PLATFORM # passing non-stdio fds is not supported on Windows diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index c5d3a53850..faa7bd670d 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1944,4 +1944,36 @@ class TestString < Test::Unit::TestCase assert_equal(S("hello world"), a) assert_equal(S("hello "), b) end + + def u(str) + str.force_encoding(Encoding::UTF_8) + end + + def test_byteslice + assert_equal("h", "hello".byteslice(0)) + assert_equal(nil, "hello".byteslice(5)) + assert_equal("o", "hello".byteslice(-1)) + assert_equal(nil, "hello".byteslice(-6)) + + assert_equal("", "hello".byteslice(0, 0)) + assert_equal("hello", "hello".byteslice(0, 6)) + assert_equal("hello", "hello".byteslice(0, 6)) + assert_equal("", "hello".byteslice(5, 1)) + assert_equal("o", "hello".byteslice(-1, 6)) + assert_equal(nil, "hello".byteslice(-6, 1)) + assert_equal(nil, "hello".byteslice(0, -1)) + + assert_equal("h", "hello".byteslice(0..0)) + assert_equal("", "hello".byteslice(5..0)) + assert_equal("o", "hello".byteslice(4..5)) + assert_equal(nil, "hello".byteslice(6..0)) + assert_equal("", "hello".byteslice(-1..0)) + assert_equal("llo", "hello".byteslice(-3..5)) + + assert_equal(u("\x81"), "\u3042".byteslice(1)) + assert_equal(u("\x81\x82"), "\u3042".byteslice(1, 2)) + assert_equal(u("\x81\x82"), "\u3042".byteslice(1..2)) + + assert_equal(u("\x82")+("\u3042"*9), ("\u3042"*10).byteslice(2, 28)) + end end diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb index bb77ad445e..f1372781cf 100644 --- a/test/ruby/test_system.rb +++ b/test/ruby/test_system.rb @@ -91,24 +91,13 @@ class TestSystem < Test::Unit::TestCase def test_system_at if /mswin|mingw/ =~ RUBY_PLATFORM bug4393 = '[ruby-core:35218]' - bug4396 = '[ruby-core:35227]' # @ + builtin command assert_equal("foo\n", `@echo foo`, bug4393); assert_equal("foo\n", `@@echo foo`, bug4393); assert_equal("@@foo\n", `@@echo @@foo`, bug4393); - # "" + @ + built-in - assert_equal("@@foo\n", `"echo" @@foo`, bug4396); - assert_equal("@@foo\n", `"@@echo" @@foo`, bug4396); - assert_equal("@@foo\n", `"@@echo @@foo"`, bug4396); - assert_equal('"@foo"\n', `"echo" "@foo"`, bug4396); - - # ^ + @ + built-in - assert_equal(nil, system('^@echo foo'), bug4396); - assert_equal(nil, system('"^@echo foo"'), bug4396); - assert_equal("@foo\n", `echo ^@foo`); - + # @ + non builtin command Dir.mktmpdir("ruby_script_tmp") {|tmpdir| tmpfilename = "#{tmpdir}/ruby_script_tmp.#{$$}" @@ -116,16 +105,23 @@ class TestSystem < Test::Unit::TestCase tmp.print "foo\nbar\nbaz\n@foo"; tmp.close - # @ + non builtin command assert_match(/\Abar\nbaz\n?\z/, `@@findstr "ba" #{tmpfilename.gsub("/", "\\")}`, bug4393); - - # "" + @ + non built-in - assert_match(/\Abar\nbaz\n?\z/, `"@@findstr" "ba" #{tmpfilename.gsub("/", "\\")}`, bug4396); - assert_match(/\A@foo\n?\z/, `"@@findstr" "@foo" #{tmpfilename.gsub("/", "\\")}`, bug4396); } end end + def test_system_redirect_win + if /mswin|mingw/ !~ RUBY_PLATFORM + return + end + + cmd = "%WINDIR%/system32/ping.exe \"BFI3CHL671\" > out.txt 2>NUL" + assert_equal(false, system(cmd), '[ruby-talk:258939]'); + + cmd = "\"%WINDIR%/system32/ping.exe BFI3CHL671\" > out.txt 2>NUL" + assert_equal(false, system(cmd), '[ruby-talk:258939]'); + end + def test_empty_evstr assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]") end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 06f25d4775..98d37a807e 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -26,6 +26,352 @@ 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 @@ -71,7 +417,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_nonexistent_binfile - quick_gem 'a', '2' do |s| + quick_spec 'a', '2' do |s| s.executables = ['exec'] end assert_raises(Gem::GemNotFoundException) do @@ -80,7 +426,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_no_bin_file - quick_gem 'a', '1' + quick_spec 'a', '1' assert_raises(Gem::Exception) do Gem.bin_path('a', nil, '1') end @@ -94,7 +440,7 @@ class TestGem < Gem::TestCase def test_self_bin_path_bin_file_gone_in_latest util_exec_gem - quick_gem 'a', '10' do |s| + quick_spec 'a', '10' do |s| s.executables = [] s.default_executable = nil end @@ -150,7 +496,7 @@ class TestGem < Gem::TestCase fp.puts 'blah' end - foo = quick_gem 'foo' do |s| s.files = %w[data/foo.txt] end + foo = quick_spec 'foo' do |s| s.files = %w[data/foo.txt] end install_gem foo end @@ -212,7 +558,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories @gemhome - assert File.directory?(File.join(@gemhome, "cache")) + assert File.directory?(Gem.cache_dir(@gemhome)) end def test_self_ensure_gem_directories_missing_parents @@ -224,7 +570,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - assert File.directory?("#{gemdir}/cache") + assert File.directory?(Gem.cache_dir(gemdir)) end unless win_platform? then # only for FS that support write protection @@ -238,7 +584,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?("#{gemdir}/cache") + refute File.exist?(Gem.cache_dir(gemdir)) ensure FileUtils.chmod 0600, gemdir end @@ -255,7 +601,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?("#{gemdir}/cache") + refute File.exist?(Gem.cache_dir(gemdir)) ensure FileUtils.chmod 0600, parent end @@ -276,8 +622,8 @@ class TestGem < Gem::TestCase def test_self_find_files discover_path = File.join 'lib', 'sff', 'discover.rb' - cwd = File.expand_path '..', __FILE__ - $LOAD_PATH.unshift cwd.dup + cwd = File.expand_path("test/rubygems", @@project_dir) + $LOAD_PATH.unshift cwd foo1 = quick_gem 'sff', '1' do |s| s.files << discover_path @@ -301,7 +647,7 @@ class TestGem < Gem::TestCase Gem.searcher = nil expected = [ - File.expand_path('../sff/discover.rb', __FILE__), + File.expand_path('test/rubygems/sff/discover.rb', @@project_dir), File.join(foo2.full_gem_path, discover_path), File.join(foo1.full_gem_path, discover_path), ] @@ -327,7 +673,7 @@ class TestGem < Gem::TestCase end def test_self_loaded_specs - foo = quick_gem 'foo' + foo = quick_spec 'foo' install_gem foo Gem.source_index = nil @@ -430,22 +776,12 @@ class TestGem < Gem::TestCase end def test_self_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 + assert_equal @@project_dir, Gem.prefix end def test_self_prefix_libdir orig_libdir = Gem::ConfigMap[:libdir] - - 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 + Gem::ConfigMap[:libdir] = @@project_dir assert_nil Gem.prefix ensure @@ -454,12 +790,7 @@ class TestGem < Gem::TestCase def test_self_prefix_sitelibdir orig_sitelibdir = Gem::ConfigMap[:sitelibdir] - - 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 + Gem::ConfigMap[:sitelibdir] = @@project_dir assert_nil Gem.prefix ensure @@ -623,6 +954,20 @@ 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 @@ -674,10 +1019,10 @@ class TestGem < Gem::TestCase Dir.chdir @tempdir do FileUtils.mkdir_p 'lib' File.open plugin_path, "w" do |fp| - fp.puts "TestGem::TEST_SPEC_PLUGIN_LOAD = :loaded" + fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end" end - foo = quick_gem 'foo', '1' do |s| + foo = quick_spec 'foo', '1' do |s| s.files << plugin_path end @@ -685,6 +1030,7 @@ class TestGem < Gem::TestCase end Gem.source_index = nil + Gem.searcher = nil gem 'foo' @@ -695,23 +1041,24 @@ class TestGem < Gem::TestCase def test_load_env_plugins with_plugin('load') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_LOAD + assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil util_remove_interrupt_command # Should attempt to cause a StandardError with_plugin('standarderror') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_STANDARDERROR + assert_equal :loaded, TEST_PLUGIN_STANDARDERROR rescue nil util_remove_interrupt_command # Should attempt to cause an Exception with_plugin('exception') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_EXCEPTION + assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil end def with_plugin(path) - test_plugin_path = File.expand_path "../plugin/#{path}", __FILE__ + test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}", + @@project_dir) # A single test plugin should get loaded once only, in order to preserve # sane test semantics. @@ -733,7 +1080,7 @@ class TestGem < Gem::TestCase end def util_exec_gem - spec, _ = quick_gem 'a', '4' do |s| + spec, _ = quick_spec 'a', '4' do |s| s.default_executable = 'exec' s.executables = ['exec', 'abin'] end @@ -777,6 +1124,5 @@ 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 d146c843bb..f95472f626 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_gem('a') + builder = Gem::Builder.new quick_spec('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 daadf2520e..3769c250d5 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 - $: << "test/rubygems" + $: << File.expand_path("test/rubygems", @@project_dir) 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 - $: << "test/rubygems" + $: << File.expand_path("test/rubygems", @@project_dir) @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 5c9c5eeb6e..5c38a1a5e8 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_gem 'some_gem' do |s| + @gem = quick_spec '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 9d5fc1eada..a514ea41f2 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -6,6 +6,7 @@ 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" @@ -21,7 +22,7 @@ class TestGemCommandsCertCommand < Gem::TestCase @cmd = Gem::Commands::CertCommand.new - root = File.expand_path(File.dirname(__FILE__)) + root = File.expand_path(File.dirname(__FILE__), @@project_dir) 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 40d96f729a..665cd98c4d 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, runtime)\n baz (> 1, runtime)\n\n", + assert_equal "Gem foo-2\n bar (> 1)\n baz (> 1)\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_gem 'foo' do |gem| + quick_spec 'foo' do |gem| gem.add_dependency 'bar', '> 1' end @@ -127,6 +127,7 @@ 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 @@ -146,9 +147,9 @@ Gem b-2 expected = <<-EOF Gem foo-2 - bar (> 1, runtime) + bar (> 1) Used by - baz-2 (foo (>= 0, runtime)) + baz-2 (foo (>= 0)) EOF @@ -194,7 +195,7 @@ ERROR: Only reverse dependencies for local gems are supported. @cmd.execute end - assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output + assert_equal "Gem foo-2\n bar (> 1)\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 657e8e9f80..173a33572f 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(File.join(@gemhome, 'cache', @a2.file_name)) + File.read(Gem.cache_gem(@a2.file_name, @gemhome)) @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(File.join(@gemhome, 'cache', @a2.file_name)) + File.read(Gem.cache_gem(@a2.file_name, @gemhome)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - File.read(File.join(@gemhome, 'cache', @a2_pre.file_name)) + File.read(Gem.cache_gem(@a2_pre.file_name, @gemhome)) @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(File.join(@gemhome, 'cache', @a1.file_name)) + File.read(Gem.cache_gem(@a1.file_name, @gemhome)) @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 a3ceb81ab7..adc66aa911 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -7,6 +7,12 @@ require 'rubygems/test_case' require 'rubygems/commands/install_command' +begin + gem "rdoc" +rescue Gem::LoadError + # ignore +end + class TestGemCommandsInstallCommand < Gem::TestCase def setup @@ -22,9 +28,9 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(File.join(@gemhome, 'cache', @a2.file_name)) + read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) + read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) @cmd.options[:args] = [@a2.name] @@ -44,11 +50,12 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_spec_fetcher @a2, @a2_pre @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(File.join(@gemhome, 'cache', @a2.file_name)) + read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) + read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) - @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s] + @cmd.handle_options [@a2_pre.name, '--version', @a2_pre.version.to_s, + "--no-ri", "--no-rdoc"] assert @cmd.options[:prerelease] assert @cmd.options[:version].satisfied_by?(@a2_pre.version) @@ -85,8 +92,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_fake_fetcher @cmd.options[:domain] = :local - FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), - File.join(@tempdir) + FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir @cmd.options[:args] = [@a2.name] @@ -115,8 +121,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase util_setup_fake_fetcher @cmd.options[:user_install] = false - FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), - File.join(@tempdir) + FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir @cmd.options[:args] = [@a2.name] @@ -183,7 +188,7 @@ class TestGemCommandsInstallCommand < Gem::TestCase correctly_spelled = "non_existent_with_hint" util_setup_fake_fetcher - util_setup_spec_fetcher quick_gem(correctly_spelled, '2') + util_setup_spec_fetcher quick_spec(correctly_spelled, '2') @cmd.options[:args] = [misspelled] @@ -207,9 +212,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(File.join(@gemhome, 'cache', @a2.file_name)) + read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] = - read_binary(File.join(@gemhome, 'cache', @a2_pre.file_name)) + read_binary(Gem.cache_gem(@a2_pre.file_name, @gemhome)) @cmd.options[:prerelease] = true @cmd.options[:args] = [@a2_pre.name] @@ -233,7 +238,7 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @a2 @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - read_binary(File.join(@gemhome, 'cache', @a2.file_name)) + read_binary(Gem.cache_gem(@a2.file_name, @gemhome)) @cmd.options[:args] = [@a2.name] @@ -260,11 +265,9 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_fake_fetcher @cmd.options[:domain] = :local - FileUtils.mv File.join(@gemhome, 'cache', @a2.file_name), - File.join(@tempdir) + FileUtils.mv Gem.cache_gem(@a2.file_name, @gemhome), @tempdir - FileUtils.mv File.join(@gemhome, 'cache', @b2.file_name), - File.join(@tempdir) + FileUtils.mv Gem.cache_gem(@b2.file_name, @gemhome), @tempdir @cmd.options[:args] = [@a2.name, @b2.name] @@ -293,7 +296,7 @@ ERROR: Possible alternatives: non_existent_with_hint util_setup_spec_fetcher @b2 @fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = - read_binary(File.join(@gemhome, 'cache', @b2.file_name)) + read_binary(Gem.cache_gem(@b2.file_name, @gemhome)) uninstall_gem(@b2) diff --git a/test/rubygems/test_gem_commands_lock_command.rb b/test/rubygems/test_gem_commands_lock_command.rb index 25b033af5d..bb3134661d 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, runtime)' from currently installed gems +# Unable to satisfy 'z (>= 0)' 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 6f99f33e99..632e9a5548 100644 --- a/test/rubygems/test_gem_commands_outdated_command.rb +++ b/test/rubygems/test_gem_commands_outdated_command.rb @@ -22,14 +22,11 @@ class TestGemCommandsOutdatedCommand < Gem::TestCase def test_execute quick_gem 'foo', '0.1' quick_gem 'foo', '0.2' - remote_10 = quick_gem 'foo', '1.0' - remote_20 = quick_gem 'foo', '2.0' + remote_10 = quick_spec 'foo', '1.0' + remote_20 = quick_spec '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 9cab574a1f..4decdf81b9 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_gem 'a' do |s| s.executables = %w[foo] end + a = quick_spec '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_gem 'a' do |s| s.executables = %w[foo] end + a = quick_spec '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,15 +73,29 @@ class TestGemCommandsPristineCommand < Gem::TestCase end def test_execute_missing_cache_gem - a = quick_gem 'a' do |s| s.executables = %w[foo] end + a = quick_spec '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 - FileUtils.rm File.join(@gemhome, 'cache', a.file_name) + 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) @cmd.options[:args] = %w[a] @@ -91,11 +105,17 @@ class TestGemCommandsPristineCommand < Gem::TestCase out = @ui.output.split "\n" - assert_equal "Restoring gem\(s\) to pristine condition...", out.shift - assert_empty out, out.inspect + [ + "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 "ERROR: Cached gem for #{a.full_name} not found, use `gem install` to restore\n", - @ui.error + assert_empty out, out.inspect 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 ca210059fd..767992f240 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_gem 'foo' + foo = quick_spec '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_gem 'foo', '0.0.1' - quick_gem 'foo', '0.0.2' + quick_spec 'foo', '0.0.1' + quick_spec '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_gem 'foo' - quick_gem 'foo_bar' + quick_spec 'foo' + quick_spec 'foo_bar' @cmd.options[:args] = %w[foo] @@ -77,7 +77,7 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase end def test_execute_field - foo = quick_gem 'foo' + foo = quick_spec '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_gem 'foo' + foo = quick_spec '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_gem 'foo' + foo = quick_spec '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 f3876d90db..d5aad6ce0c 100644 --- a/test/rubygems/test_gem_commands_stale_command.rb +++ b/test/rubygems/test_gem_commands_stale_command.rb @@ -16,10 +16,11 @@ class TestGemCommandsStaleCommand < Gem::TestCase def test_execute_sorts files = %w[lib/foo_bar.rb Rakefile] - foo_bar = quick_gem 'foo_bar' do |gem| + foo_bar = quick_spec 'foo_bar' do |gem| gem.files = files end - bar_baz = quick_gem 'bar_baz' do |gem| + + bar_baz = quick_spec 'bar_baz' do |gem| gem.files = files end @@ -36,6 +37,7 @@ 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 c5be3beb90..47f4960145 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? + if win_platform? then 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+") {|f| f.puts "binary"} + open @executable, "wb+" do |f| f.puts "binary" end - @cmd.options[:args] = Array(@spec.name) + @cmd.options[:args] = [@spec.name] use_ui @ui do @cmd.execute end @@ -56,6 +56,25 @@ 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 @@ -70,7 +89,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase end def test_execute_prerelease - @spec = quick_gem "pre", "2.b" + @spec = quick_spec "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 0fb4ef3843..8291a6b949 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), - File.join(@gemhome, 'cache', @a1.file_name), + Gem.cache_gem(@a1.file_name, @gemhome), 'found a-1.gem in the cache' ) end @@ -34,7 +34,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase a1_data = nil - open File.join(@gemhome, 'cache', @a1.file_name), 'rb' do |fp| + open Gem.cache_gem(@a1.file_name, @gemhome), '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), - File.join(@gemhome, 'cache', @a1.file_name), + Gem.cache_gem(@a1.file_name, @gemhome), 'fetches a-1 and returns the cache path' ) - FileUtils.rm File.join(@gemhome, 'cache', @a1.file_name) + FileUtils.rm Gem.cache_gem(@a1.file_name, @gemhome) assert_equal( @cmd.get_path(dep), - File.join(@gemhome, 'cache', @a1.file_name), + Gem.cache_gem(@a1.file_name, @gemhome), 'when removed from cache, refetches a-1' ) end @@ -74,6 +74,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase def test_execute_gem_path util_make_gems + util_setup_spec_fetcher + util_setup_fake_fetcher Gem.clear_paths @@ -121,7 +123,7 @@ class TestGemCommandsUnpackCommand < Gem::TestCase util_clear_gems a2_data = nil - open File.join(@gemhome, 'cache', @a2.file_name), 'rb' do |fp| + open Gem.cache_gem(@a2.file_name, @gemhome), 'rb' do |fp| a2_data = fp.read end @@ -175,8 +177,8 @@ class TestGemCommandsUnpackCommand < Gem::TestCase end def test_execute_exact_match - foo_spec = quick_gem 'foo' - foo_bar_spec = quick_gem 'foo_bar' + foo_spec = quick_spec 'foo' + foo_bar_spec = quick_spec '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 6c16713130..24966a3a84 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -7,6 +7,12 @@ require 'rubygems/test_case' require 'rubygems/commands/update_command' +begin + gem "rdoc" +rescue Gem::LoadError + # ignore +end + class TestGemCommandsUpdateCommand < Gem::TestCase def setup @@ -19,8 +25,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase util_setup_fake_fetcher - @a1_path = File.join @gemhome, 'cache', @a1.file_name - @a2_path = File.join @gemhome, 'cache', @a2.file_name + @a1_path = Gem.cache_gem(@a1.file_name, @gemhome) + @a2_path = Gem.cache_gem(@a2.file_name, @gemhome) util_setup_spec_fetcher @a1, @a2 @@ -36,8 +42,8 @@ class TestGemCommandsUpdateCommand < Gem::TestCase Gem::Installer.new(@a1_path).install @cmd.options[:args] = [] - @cmd.options[:generate_rdoc] = true - @cmd.options[:generate_ri] = true + @cmd.options[:generate_rdoc] = false + @cmd.options[:generate_ri] = false use_ui @ui do @cmd.execute @@ -48,12 +54,153 @@ 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_equal "Installing ri documentation for a-2...", out.shift - assert_equal "Installing RDoc documentation for a-2...", 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_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: @@ -63,7 +210,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def test_execute_dependencies @a1.add_dependency 'c', '1.2' - @c2 = quick_gem 'c', '2' do |s| + @c2 = quick_spec 'c', '2' do |s| s.files = %w[lib/code.rb] s.require_paths = %w[lib] end @@ -71,9 +218,9 @@ class TestGemCommandsUpdateCommand < Gem::TestCase @a2.add_dependency 'c', '2' @a2.add_dependency 'b', '2' - @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 + @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) @source_index = Gem::SourceIndex.new @source_index.add_spec @a1 @@ -172,4 +319,39 @@ 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 dc53d21933..424fd92f80 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -283,6 +283,20 @@ 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 51b746f555..b4a21b896c 100644 --- a/test/rubygems/test_gem_dependency.rb +++ b/test/rubygems/test_gem_dependency.rb @@ -106,6 +106,45 @@ 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 cdc0428e9f..5cf79d3c59 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -6,66 +6,28 @@ 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 = File.join @gemhome, 'cache' - FileUtils.mkdir @gems_dir + @gems_dir = File.join @tempdir, 'gems' + @cache_dir = Gem.cache_dir(@gemhome) - write_file File.join('gems', 'a-1', 'bin', 'a_bin') do |fp| - fp.puts "#!/usr/bin/ruby" - end + FileUtils.mkdir @gems_dir - @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end - @aa1, @aa1_gem = util_gem 'aa', '1' + @a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end @a1_pre, @a1_pre_gem = util_gem 'a', '1.a' - - @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| + @b1, @b1_gem = util_gem 'b', '1' do |s| s.add_dependency 'a' s.add_development_dependency 'aa' end - @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) + Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new - util_clear_gems + util_reset_gems end def test_install @@ -120,8 +82,8 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name } - assert File.exist?(File.join(@tempdir, 'cache', @a1.file_name)) - assert File.exist?(File.join(@tempdir, 'cache', @b1.file_name)) + assert Gem.cache_gem(@a1.file_name, @gemhome) + assert Gem.cache_gem(@b1.file_name, @gemhome) end def test_install_dependencies_satisfied @@ -168,6 +130,10 @@ 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 @@ -321,7 +287,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?(File.join(gemhome2, 'cache', @a1.file_name)) + assert File.exist?(Gem.cache_gem(@a1.file_name, gemhome2)) end def test_install_domain_both @@ -376,12 +342,13 @@ class TestGemDependencyInstaller < Gem::TestCase Gem.source_index.remove_spec @a1_pre.full_name Dir.chdir @tempdir do - e = assert_raises Gem::InstallError do + e = assert_raises Gem::DependencyError do inst = Gem::DependencyInstaller.new :domain => :local inst.install 'b' end - assert_equal 'b requires a (>= 0, runtime)', e.message + expected = "Unable to resolve dependencies: b requires a (>= 0)" + assert_equal expected, e.message end assert_equal [], inst.installed_gems.map { |s| s.full_name } @@ -425,6 +392,22 @@ 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| @@ -460,7 +443,7 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end - def test_install_domain_remote_platform_newer + def test_install_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 @@ -488,22 +471,6 @@ 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 } @@ -539,6 +506,8 @@ 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 @@ -553,6 +522,8 @@ 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 @@ -619,7 +590,22 @@ class TestGemDependencyInstaller < Gem::TestCase util_setup_spec_fetcher(*specs) inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version 'a' + 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.gather_dependencies actual = inst.gems_to_install.map { |s| s.full_name } @@ -634,47 +620,182 @@ 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' - 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 } + assert_resolve %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m end def test_gather_dependencies_platform_bump - inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version 'z' - inst.gather_dependencies + util_setup_wxyz - assert_equal %w[y-1 z-1], inst.gems_to_install.map { |s| s.full_name } + assert_resolve %w[y-1 z-1], @z1, @y1 end def test_gather_dependencies_prerelease - inst = Gem::DependencyInstaller.new :prerelease => true - inst.find_spec_by_name_and_version 'c', '1.a' - inst.gather_dependencies + util_setup_c1_pre - assert_equal %w[a-1.a b-1 c-1.a], - inst.gems_to_install.map { |s| s.full_name } + assert_resolve_pre %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1 end def test_gather_dependencies_old_required - e1, = util_gem 'e', '1', 'd' => '= 1' - + util_setup_d + e1, = util_spec 'e', '1', 'd' => '= 1' util_clear_gems - util_setup_spec_fetcher @d1, @d2, e1 + assert_resolve %w[d-1 e-1], e1, @d1, @d2 + end - inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version 'e' - inst.gather_dependencies + 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 - assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name } + util_reset_gems end -end + 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 + + @w1, @w1_gem = util_spec 'w', '1', 'x' => nil + + @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 + + util_reset_gems + 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 92966ace08..688455475b 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_gem 'a', '1' - @a2 = quick_gem 'a', '2' - @a3 = quick_gem 'a', '3' + @a1 = quick_spec 'a', '1' + @a2 = quick_spec 'a', '2' + @a3 = quick_spec 'a', '3' - @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 + @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 - @c1 = quick_gem 'c', '1' do |s| s.add_dependency 'b', '>= 1' end - @c2 = quick_gem 'c', '2' + @c1 = quick_spec 'c', '1' do |s| s.add_dependency 'b', '>= 1' end + @c2 = quick_spec 'c', '2' - @d1 = quick_gem 'd', '1' do |s| s.add_dependency 'c', '>= 1' end + @d1 = quick_spec '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_gem 'e', '1' - f1 = quick_gem 'f', '1' - g1 = quick_gem 'g', '1' + e1 = quick_spec 'e', '1' + f1 = quick_spec 'f', '1' + g1 = quick_spec '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_gem 'e', '1' + e1 = quick_spec 'e', '1' @deplist.add e1 @a1.add_dependency 'e', '>= 1' @@ -128,6 +128,8 @@ class TestGemDependencyList < Gem::TestCase end def test_ok_eh + util_clear_gems + assert @deplist.ok?, 'no dependencies' @deplist.add @b2 @@ -139,14 +141,30 @@ 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_gem 'a', '1' - a2 = quick_gem 'a', '2' + a1 = quick_spec 'a', '1' + a2 = quick_spec 'a', '2' - 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 + 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 - d = quick_gem 'd', '1' do |s| + d = quick_spec 'd', '1' do |s| s.add_dependency 'b' s.add_dependency 'c' end @@ -192,6 +210,8 @@ 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 be4c12bd5b..f52f1f87f1 100644 --- a/test/rubygems/test_gem_doc_manager.rb +++ b/test/rubygems/test_gem_doc_manager.rb @@ -12,25 +12,26 @@ class TestGemDocManager < Gem::TestCase def setup super - @spec = quick_gem 'a' + @spec = quick_gem 'a', 2 @manager = Gem::DocManager.new(@spec) end def test_uninstall_doc_unwritable - orig_mode = File.stat(@spec.installation_path).mode + path = @spec.installation_path + orig_mode = File.stat(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(0, @spec.installation_path) + File.chmod 0000, path end assert_raises Gem::FilePermissionError do @manager.uninstall_doc end ensure - File.chmod orig_mode, @spec.installation_path + File.chmod orig_mode, path end end diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb index f964cab143..6f169588eb 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 'test/rubygems/simple_gem' +require '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[File.join(@gemhome, 'cache', '*.gem')] + gems = Dir[Gem.cache_gem('*.gem', @gemhome)] 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 a7f49506a6..71fb965460 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -18,21 +18,20 @@ class TestGemIndexer < Gem::TestCase util_make_gems - @d2_0 = quick_gem 'd', '2.0' do |s| + @d2_0 = quick_spec 'd', '2.0' do |s| s.date = Gem::Specification::TODAY - 86400 * 3 end util_build_gem @d2_0 - @d2_0_a = quick_gem 'd', '2.0.a' + @d2_0_a = quick_spec 'd', '2.0.a' util_build_gem @d2_0_a - @d2_0_b = quick_gem 'd', '2.0.b' + @d2_0_b = quick_spec 'd', '2.0.b' util_build_gem @d2_0_b gems = File.join(@tempdir, 'gems') FileUtils.mkdir_p gems - cache_gems = File.join @gemhome, 'cache', '*.gem' - FileUtils.mv Dir[cache_gems], gems + FileUtils.mv Dir[Gem.cache_gem('*.gem', @gemhome)], gems @indexer = Gem::Indexer.new @tempdir, :rss_title => 'ExampleForge gems', :rss_host => 'example.com', @@ -60,7 +59,7 @@ class TestGemIndexer < Gem::TestCase end def test_build_indicies - spec = quick_gem 'd', '2.0' + spec = quick_spec 'd', '2.0' spec.instance_variable_set :@original_platform, '' @indexer.make_temp_directories @@ -510,17 +509,17 @@ eighty characters.</pre> assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - @d2_1 = quick_gem 'd', '2.1' + @d2_1 = quick_spec '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_gem 'd', '2.2.a' + @d2_1_a = quick_spec '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 File.join(@gemhome, 'cache', @d2_1.file_name), gems - FileUtils.mv File.join(@gemhome, 'cache', @d2_1_a.file_name), gems + FileUtils.mv Gem.cache_gem(@d2_1.file_name, @gemhome), gems + FileUtils.mv Gem.cache_gem(@d2_1_a.file_name, @gemhome), 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 937774617f..fe10fd4949 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -69,6 +69,4 @@ 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 94fa4423bc..0b73af996d 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -9,7 +9,8 @@ require 'rubygems/installer_test_case' class TestGemInstaller < Gem::InstallerTestCase def test_app_script_text - util_make_exec '2', '' + @spec.version = 2 + util_make_exec @spec, '' expected = <<-EOF #!#{Gem.ruby} @@ -30,10 +31,10 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then end gem 'a', version -load Gem.bin_path('a', 'my_exec', version) +load Gem.bin_path('a', 'executable', version) EOF - wrapper = @installer.app_script_text 'my_exec' + wrapper = @installer.app_script_text 'executable' assert_equal expected, wrapper end @@ -101,7 +102,7 @@ load Gem.bin_path('a', 'my_exec', version) @installer.ensure_dependency @spec, dep end - assert_equal 'a requires b (> 2, runtime)', e.message + assert_equal 'a requires b (> 2)', e.message end def test_extract_files @@ -170,11 +171,11 @@ load Gem.bin_path('a', 'my_exec', version) def test_generate_bin_bindir @installer.wrappers = true - @spec.executables = ["my_exec"] + @spec.executables = %w[executable] @spec.bindir = '.' - exec_file = @installer.formatted_program_filename "my_exec" - exec_path = File.join util_gem_dir(@spec.version), exec_file + exec_file = @installer.formatted_program_filename 'executable' + exec_path = File.join util_gem_dir(@spec), exec_file File.open exec_path, 'w' do |f| f.puts '#!/usr/bin/ruby' end @@ -184,7 +185,7 @@ load Gem.bin_path('a', 'my_exec', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, "my_exec") + installed_exec = File.join(util_inst_bindir, 'executable') assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -199,7 +200,7 @@ load Gem.bin_path('a', 'my_exec', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, "my_exec") + installed_exec = File.join(util_inst_bindir, 'executable') assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -216,7 +217,7 @@ load Gem.bin_path('a', 'my_exec', 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-my_exec-bar' + installed_exec = File.join util_inst_bindir, 'foo-executable-bar' assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil @@ -230,7 +231,7 @@ load Gem.bin_path('a', 'my_exec', 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, 'my_exec' + installed_exec = File.join util_inst_bindir, 'executable' assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil @@ -238,12 +239,12 @@ load Gem.bin_path('a', 'my_exec', version) def test_generate_bin_script_install_dir @installer.wrappers = true - @spec.executables = ["my_exec"] + @spec.executables = %w[executable] 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, "my_exec"), 'w' do |f| + File.open File.join(gem_bindir, 'executable'), 'w' do |f| f.puts "#!/bin/ruby" end @@ -252,7 +253,7 @@ load Gem.bin_path('a', 'my_exec', version) @installer.generate_bin - installed_exec = File.join("#{@gemhome}2", 'bin', 'my_exec') + installed_exec = File.join("#{@gemhome}2", 'bin', 'executable') assert_equal true, File.exist?(installed_exec) assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? @@ -261,9 +262,12 @@ load Gem.bin_path('a', 'my_exec', version) end def test_generate_bin_script_no_execs + util_execless + @installer.wrappers = true @installer.generate_bin - assert_equal false, File.exist?(util_inst_bindir) + + refute File.exist?(util_inst_bindir), 'bin dir was created when not needed' end def test_generate_bin_script_no_perms @@ -287,18 +291,18 @@ load Gem.bin_path('a', 'my_exec', version) def test_generate_bin_script_no_shebang @installer.wrappers = true - @spec.executables = ["my_exec"] + @spec.executables = %w[executable] 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, "my_exec"), 'w' do |f| + File.open File.join(gem_bindir, 'executable'), 'w' do |f| f.puts "blah blah blah" end @installer.generate_bin - installed_exec = File.join @gemhome, 'bin', 'my_exec' + installed_exec = File.join @gemhome, 'bin', 'executable' assert_equal true, File.exist?(installed_exec) assert_equal 0100755, File.stat(installed_exec).mode unless win_platform? @@ -312,9 +316,9 @@ load Gem.bin_path('a', 'my_exec', version) @installer.wrappers = true util_make_exec @installer.gem_dir = util_gem_dir - installed_exec = File.join(util_inst_bindir, "my_exec") + installed_exec = File.join(util_inst_bindir, 'executable') - real_exec = File.join util_gem_dir, 'bin', 'my_exec' + real_exec = File.join util_gem_dir, 'bin', 'executable' # fake --no-wrappers for previous install unless Gem.win_platform? then @@ -342,16 +346,19 @@ load Gem.bin_path('a', 'my_exec', version) @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, "my_exec") + installed_exec = File.join(util_inst_bindir, 'executable') assert_equal true, File.symlink?(installed_exec) - assert_equal(File.join(util_gem_dir, "bin", "my_exec"), + assert_equal(File.join(util_gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) end def test_generate_bin_symlink_no_execs + util_execless + @installer.wrappers = false @installer.generate_bin - assert_equal false, File.exist?(util_inst_bindir) + + refute File.exist?(util_inst_bindir) end def test_generate_bin_symlink_no_perms @@ -382,8 +389,8 @@ load Gem.bin_path('a', 'my_exec', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_dir, "bin", "my_exec"), + installed_exec = File.join(util_inst_bindir, 'executable') + assert_equal(File.join(util_gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) @spec = Gem::Specification.new do |s| @@ -395,11 +402,12 @@ load Gem.bin_path('a', 'my_exec', version) s.require_path = 'lib' end - util_make_exec '3' - @installer.gem_dir = File.join util_gem_dir('3') + @spec.version = 3 + util_make_exec + @installer.gem_dir = File.join util_gem_dir @spec @installer.generate_bin - installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_bindir('3'), "my_exec"), + installed_exec = File.join(util_inst_bindir, 'executable') + assert_equal(File.join(util_gem_bindir(@spec), 'executable'), File.readlink(installed_exec), "Ensure symlink moved to latest version") end @@ -412,8 +420,8 @@ load Gem.bin_path('a', 'my_exec', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_dir, "bin", "my_exec"), + installed_exec = File.join(util_inst_bindir, 'executable') + assert_equal(File.join(util_gem_dir, 'bin', 'executable'), File.readlink(installed_exec)) spec = Gem::Specification.new do |s| @@ -425,14 +433,16 @@ load Gem.bin_path('a', 'my_exec', version) s.require_path = 'lib' end - util_make_exec '1' - @installer.gem_dir = util_gem_dir('1') + util_make_exec + one = @spec.dup + one.version = 1 + @installer.gem_dir = util_gem_dir one @installer.spec = spec @installer.generate_bin - installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_dir('2'), "bin", "my_exec"), + installed_exec = File.join(util_inst_bindir, 'executable') + assert_equal(File.join(util_gem_dir, 'bin', 'executable'), File.readlink(installed_exec), "Ensure symlink not moved") end @@ -445,7 +455,7 @@ load Gem.bin_path('a', 'my_exec', version) @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, "my_exec") + installed_exec = File.join(util_inst_bindir, 'executable') assert_equal true, File.exist?(installed_exec) @spec = Gem::Specification.new do |s| @@ -458,11 +468,12 @@ load Gem.bin_path('a', 'my_exec', version) end @installer.wrappers = false - util_make_exec '3' - @installer.gem_dir = util_gem_dir '3' + @spec.version = 3 + util_make_exec + @installer.gem_dir = util_gem_dir @installer.generate_bin - installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_dir('3'), "bin", "my_exec"), + installed_exec = File.join(util_inst_bindir, 'executable') + assert_equal(File.join(util_gem_dir, 'bin', 'executable'), File.readlink(installed_exec), "Ensure symlink moved to latest version") end @@ -479,7 +490,7 @@ load Gem.bin_path('a', 'my_exec', version) end assert_equal true, File.directory?(util_inst_bindir) - installed_exec = File.join(util_inst_bindir, "my_exec") + installed_exec = File.join(util_inst_bindir, 'executable') assert_equal true, File.exist?(installed_exec) assert_match(/Unable to use symlinks on Windows, installing wrapper/i, @@ -500,19 +511,18 @@ load Gem.bin_path('a', 'my_exec', version) @installer.generate_bin default_shebang = Gem.ruby - shebang_line = open("#{@gemhome}/bin/my_exec") { |f| f.readlines.first } + shebang_line = open("#{@gemhome}/bin/executable") { |f| f.readlines.first } assert_match(/\A#!/, shebang_line) assert_match(/#{default_shebang}/, shebang_line) end def test_initialize - spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end + spec = quick_spec '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 File.join(@gemhome, 'cache', spec.file_name), - @tempdir + FileUtils.mv Gem.cache_gem(spec.file_name, @gemhome), @tempdir installer = Gem::Installer.new gem @@ -525,7 +535,7 @@ load Gem.bin_path('a', 'my_exec', version) util_clear_gems gemdir = File.join @gemhome, 'gems', @spec.full_name - cache_file = File.join @gemhome, 'cache', @spec.file_name + cache_file = Gem.cache_gem(@spec.file_name, @gemhome) stub_exe = File.join @gemhome, 'bin', 'executable' rakefile = File.join gemdir, 'ext', 'a', 'Rakefile' @@ -574,6 +584,42 @@ load Gem.bin_path('a', 'my_exec', 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 @@ -610,7 +656,7 @@ load Gem.bin_path('a', 'my_exec', version) gemhome2 = "#{@gemhome}2" @spec.add_dependency 'b' - b2 = quick_gem 'b', 2 + b2 = quick_spec 'b', 2 FileUtils.mv @gemhome, gemhome2 Gem.source_index.gems.delete b2.full_name @@ -666,7 +712,7 @@ load Gem.bin_path('a', 'my_exec', version) end def test_install_missing_dirs - FileUtils.rm_f File.join(Gem.dir, 'cache') + FileUtils.rm_f Gem.cache_dir FileUtils.rm_f File.join(Gem.dir, 'docs') FileUtils.rm_f File.join(Gem.dir, 'specifications') @@ -676,11 +722,11 @@ load Gem.bin_path('a', 'my_exec', version) @installer.install end - File.directory? File.join(Gem.dir, 'cache') + File.directory? Gem.cache_dir File.directory? File.join(Gem.dir, 'docs') File.directory? File.join(Gem.dir, 'specifications') - assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name)) + assert File.exist?(Gem.cache_gem(@spec.file_name, @gemhome)) assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name)) end @@ -786,13 +832,13 @@ load Gem.bin_path('a', 'my_exec', version) end def test_install_wrong_rubygems_version - spec = quick_gem 'old_rubygems_required', '1' do |s| + spec = quick_spec 'old_rubygems_required', '1' do |s| s.required_rubygems_version = '< 0' end util_build_gem spec - gem = File.join @gemhome, 'cache', spec.file_name + gem = Gem.cache_gem(spec.file_name, @gemhome) use_ui @ui do @installer = Gem::Installer.new gem @@ -813,49 +859,49 @@ load Gem.bin_path('a', 'my_exec', version) end def test_shebang - util_make_exec '2', "#!/usr/bin/ruby" + util_make_exec @spec, "#!/usr/bin/ruby" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_arguments - util_make_exec '2', "#!/usr/bin/ruby -ws" + util_make_exec @spec, "#!/usr/bin/ruby -ws" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_empty - util_make_exec '2', '' + util_make_exec @spec, '' - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env - util_make_exec '2', "#!/usr/bin/env ruby" + util_make_exec @spec, "#!/usr/bin/env ruby" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env_arguments - util_make_exec '2', "#!/usr/bin/env ruby -ws" + util_make_exec @spec, "#!/usr/bin/env ruby -ws" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_env_shebang - util_make_exec '2', '' + util_make_exec @spec, '' @installer.env_shebang = true - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' env_shebang = "/usr/bin/env" unless Gem.win_platform? @@ -864,49 +910,49 @@ load Gem.bin_path('a', 'my_exec', version) end def test_shebang_nested - util_make_exec '2', "#!/opt/local/ruby/bin/ruby" + util_make_exec @spec, "#!/opt/local/ruby/bin/ruby" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_nested_arguments - util_make_exec '2', "#!/opt/local/ruby/bin/ruby -ws" + util_make_exec @spec, "#!/opt/local/ruby/bin/ruby -ws" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version - util_make_exec '2', "#!/usr/bin/ruby18" + util_make_exec @spec, "#!/usr/bin/ruby18" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_arguments - util_make_exec '2', "#!/usr/bin/ruby18 -ws" + util_make_exec @spec, "#!/usr/bin/ruby18 -ws" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end def test_shebang_version_env - util_make_exec '2', "#!/usr/bin/env ruby18" + util_make_exec @spec, "#!/usr/bin/env ruby18" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_version_env_arguments - util_make_exec '2', "#!/usr/bin/env ruby18 -ws" + util_make_exec @spec, "#!/usr/bin/env ruby18 -ws" - shebang = @installer.shebang 'my_exec' + shebang = @installer.shebang 'executable' assert_equal "#!#{Gem.ruby} -ws", shebang end @@ -937,14 +983,41 @@ load Gem.bin_path('a', 'my_exec', 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_gem 'old_ruby_required', '1' do |s| + spec = quick_spec 'old_ruby_required', '1' do |s| s.required_ruby_version = '= 1.4.6' end util_build_gem spec - File.join @gemhome, 'cache', spec.file_name + 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 end end diff --git a/test/rubygems/test_gem_package_tar_output.rb b/test/rubygems/test_gem_package_tar_output.rb index 7458a749dd..77f31852f9 100644 --- a/test/rubygems/test_gem_package_tar_output.rb +++ b/test/rubygems/test_gem_package_tar_output.rb @@ -55,6 +55,9 @@ 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 135b2c7e53..66fb682c6c 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -99,9 +99,10 @@ gems: # REFACTOR: copied from test_gem_dependency_installer.rb @gems_dir = File.join @tempdir, 'gems' - @cache_dir = File.join @gemhome, 'cache' + @cache_dir = Gem.cache_dir(@gemhome) 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 @@ -208,7 +209,7 @@ gems: fetcher = util_fuck_with_fetcher a1_data - a1_cache_gem = File.join(@gemhome, 'cache', @a1.file_name) + a1_cache_gem = Gem.cache_gem(@a1.file_name, @gemhome) 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) @@ -220,7 +221,7 @@ gems: inst = Gem::RemoteFetcher.fetcher - assert_equal File.join(@gemhome, 'cache', @a1.file_name), + assert_equal Gem.cache_gem(@a1.file_name, @gemhome), inst.download(@a1, 'http://gems.example.com') end @@ -233,7 +234,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - assert_equal File.join(@gemhome, 'cache', @a1.file_name), + assert_equal Gem.cache_gem(@a1.file_name, @gemhome), inst.download(@a1, local_path) end @@ -248,7 +249,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - assert_equal File.join(@gemhome, 'cache', @a1.file_name), + assert_equal Gem.cache_gem(@a1.file_name, @gemhome), inst.download(@a1, local_path) end @@ -262,7 +263,7 @@ gems: install_dir = File.join @tempdir, 'more_gems' - a1_cache_gem = File.join install_dir, 'cache', @a1.file_name + a1_cache_gem = Gem.cache_gem(@a1.file_name, install_dir) FileUtils.mkdir_p(File.dirname(a1_cache_gem)) actual = fetcher.download(@a1, 'http://gems.example.com', install_dir) @@ -278,7 +279,7 @@ gems: FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, @a1.file_name inst = nil - File.chmod 0555, File.join(@gemhome, 'cache') + File.chmod 0555, Gem.cache_dir(@gemhome) Dir.chdir @tempdir do inst = Gem::RemoteFetcher.fetcher @@ -287,19 +288,19 @@ gems: assert_equal File.join(@tempdir, @a1.file_name), inst.download(@a1, local_path) ensure - File.chmod 0755, File.join(@gemhome, 'cache') + File.chmod 0755, Gem.cache_dir(@gemhome) end def test_download_read_only - File.chmod 0555, File.join(@gemhome, 'cache') + File.chmod 0555, Gem.cache_dir(@gemhome) 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?(File.join(Gem.user_dir, 'cache', @a1.file_name)) + assert File.exist?(Gem.cache_gem(@a1.file_name, Gem.user_dir)) ensure - File.chmod 0755, File.join(@gemhome) - File.chmod 0755, File.join(@gemhome, 'cache') + File.chmod 0755, @gemhome + File.chmod 0755, Gem.cache_dir(@gemhome) end end @@ -318,7 +319,7 @@ gems: fetcher = util_fuck_with_fetcher e1_data, :blow_chunks - e1_cache_gem = File.join(@gemhome, 'cache', e1.file_name) + e1_cache_gem = Gem.cache_gem(e1.file_name, @gemhome) assert_equal e1_cache_gem, fetcher.download(e1, 'http://gems.example.com') @@ -336,7 +337,7 @@ gems: inst = Gem::RemoteFetcher.fetcher end - cache_path = File.join @gemhome, 'cache', @a1.file_name + cache_path = Gem.cache_gem(@a1.file_name, @gemhome) FileUtils.mv local_path, cache_path gem = Gem::Format.from_file_by_path cache_path @@ -744,5 +745,13 @@ 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 9846c9cc89..89e2ea3894 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_gem 'a', '1' do |spec| spec.author = 'author 1' end + a1 = quick_spec '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_gem 'a', '1' do |spec| spec.author = 'author 1' end + a1 = quick_spec '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_gem 'p', '1' - p1_platform = quick_gem 'p', '1' do |spec| + p1_ruby = quick_spec 'p', '1' + p1_platform = quick_spec 'p', '1' do |spec| spec.platform = Gem::Platform::CURRENT end - a1_platform = quick_gem @a1.name, (@a1.version) do |s| + a1_platform = quick_spec @a1.name, (@a1.version) do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a2_platform = quick_gem @a2.name, (@a2.version) do |s| + a2_platform = quick_spec @a2.name, (@a2.version) do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a2_platform_other = quick_gem @a2.name, (@a2.version) do |s| + a2_platform_other = quick_spec @a2.name, (@a2.version) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end - a3_platform_other = quick_gem @a2.name, (@a2.version.bump) do |s| + a3_platform_other = quick_spec @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_gem 'a', '1' do |spec| spec.author = 'author 1' end - a2 = quick_gem 'a', '1' do |spec| spec.author = 'author 2' end + a1 = quick_spec 'a', '1' do |spec| spec.author = 'author 1' end + a2 = quick_spec '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_gem @a2.name, (@a2.version.bump) + updated = quick_spec @a2.name, (@a2.version.bump) util_setup_spec_fetcher updated assert_equal [updated.name], @source_index.outdated - updated_platform = quick_gem @a2.name, (updated.version.bump) do |s| + updated_platform = quick_spec @a2.name, (updated.version.bump) do |s| s.platform = Gem::Platform.new 'x86-other_platform1' end @@ -302,10 +302,11 @@ end end def test_prerelease_specs_kept_in_right_place - gem_a1_alpha = quick_gem 'abba', '1.a' + gem_a1_alpha = quick_spec '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 @@ -363,11 +364,11 @@ end def test_search_platform util_set_arch 'x86-my_platform1' - a1 = quick_gem 'a', '1' - a1_mine = quick_gem 'a', '1' do |s| + a1 = quick_spec 'a', '1' + a1_mine = quick_spec 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end - a1_other = quick_gem 'a', '1' do |s| + a1_other = quick_spec '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 6e3891b866..57983a2752 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_gem 'a', '1.a' + @a_pre = quick_spec 'a', '1.a' @source_index.add_spec @pl1 @source_index.add_spec @a_pre @@ -412,5 +412,10 @@ 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 49862fe4bb..f820d7c1c3 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -46,6 +46,7 @@ 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' @@ -167,6 +168,13 @@ 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" @@ -294,7 +302,7 @@ end end def test_add_dependency_with_explicit_type - gem = quick_gem "awesome", "1.0" do |awesome| + gem = quick_spec "awesome", "1.0" do |awesome| awesome.add_development_dependency "monkey" end @@ -371,18 +379,19 @@ end assert_equal [rake, jabber, pqa], @a1.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_dependencies + util_setup_deps + assert_equal [@bonobo, @monkey], @gem.dependencies + end - bonobo = Gem::Dependency.new("bonobo", []) - monkey = Gem::Dependency.new("monkey", [], :development) + def test_runtime_dependencies + util_setup_deps + assert_equal [@bonobo], @gem.runtime_dependencies + end - assert_equal([bonobo, monkey], gem.dependencies) - assert_equal([bonobo], gem.runtime_dependencies) - assert_equal([monkey], gem.development_dependencies) + def test_development_dependencies + util_setup_deps + assert_equal [@monkey], @gem.development_dependencies end def test_description @@ -390,8 +399,8 @@ end end def test_eql_eh - g1 = quick_gem 'gem' - g2 = quick_gem 'gem' + g1 = quick_spec 'gem' + g2 = quick_spec 'gem' assert_equal g1, g2 assert_equal g1.hash, g2.hash @@ -690,7 +699,7 @@ end end def test_prerelease_spec_adds_required_rubygems_version - @prerelease = quick_gem('tardis', '2.2.0.a') + @prerelease = quick_spec('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 @@ -716,8 +725,8 @@ end end def test_spaceship_name - s1 = quick_gem 'a', '1' - s2 = quick_gem 'b', '1' + s1 = quick_spec 'a', '1' + s2 = quick_spec 'b', '1' assert_equal(-1, (s1 <=> s2)) assert_equal( 0, (s1 <=> s1)) @@ -725,8 +734,8 @@ end end def test_spaceship_platform - s1 = quick_gem 'a', '1' - s2 = quick_gem 'a', '1' do |s| + s1 = quick_spec 'a', '1' + s2 = quick_spec 'a', '1' do |s| s.platform = Gem::Platform.new 'x86-my_platform1' end @@ -736,8 +745,8 @@ end end def test_spaceship_version - s1 = quick_gem 'a', '1' - s2 = quick_gem 'a', '2' + s1 = quick_spec 'a', '1' + s2 = quick_spec 'a', '2' assert_equal( -1, (s1 <=> s2)) assert_equal( 0, (s1 <=> s1)) @@ -803,6 +812,54 @@ 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 @@ -842,16 +899,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.4\", \"<= 0.6\"]) + s.add_runtime_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) else s.add_dependency(%q, [\"> 0.4\"]) s.add_dependency(%q, [\"> 0.0.0\"]) - s.add_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) + s.add_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) end else s.add_dependency(%q, [\"> 0.4\"]) s.add_dependency(%q, [\"> 0.0.0\"]) - s.add_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) + s.add_dependency(%q, [\"<= 0.6\", \"> 0.4\"]) end end SPEC @@ -884,6 +941,9 @@ 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 @@ -1258,6 +1318,16 @@ 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') @@ -1269,6 +1339,4 @@ 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 3925ab1a63..0c08f42d01 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 = ["my_exec"] + @user_spec.executables = ["executable"] # 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, "my_exec" + exec_path = File.join user_bin_dir, "executable" 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, "my_exec" + exec_path = File.join user_bin_dir, "executable" 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', 'my_exec' - assert File.exist? executable + executable = File.join Gem.user_dir, 'bin', 'executable' + assert File.exist?(executable), 'executable not written' 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', 'my_exec' - assert File.exist? executable + executable = File.join Gem.user_dir, 'bin', 'executable' + assert File.exist?(executable), 'executable not written' use_ui @ui do uninstaller.remove_executables @user_spec end - assert_equal "Removing my_exec\n", @ui.output + assert_equal "Removing executable\n", @ui.output refute File.exist? executable end @@ -81,12 +81,47 @@ class TestGemUninstaller < Gem::InstallerTestCase uninstaller.remove_executables @user_spec end - exec_path = File.join Gem.user_dir, 'bin', 'my_exec' + exec_path = File.join Gem.user_dir, 'bin', 'executable' assert_equal false, File.exist?(exec_path), 'removed exec from bin dir' - assert_equal "Removing my_exec\n", @ui.output + assert_equal "Removing executable\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 @@ -129,6 +164,31 @@ 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 aa4bd38eb6..304c141483 100644 --- a/test/rubygems/test_gem_validator.rb +++ b/test/rubygems/test_gem_validator.rb @@ -5,7 +5,7 @@ ###################################################################### require 'rubygems/test_case' -require "test/rubygems/simple_gem" +require "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 98d27a6123..d3714a2c59 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, runtime\)/, ex.message) + assert_match(/activate a \(= 2\)/, 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