diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-13 19:58:57 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-13 19:58:57 +0000 |
commit | 1daa0b113d853bfa57b776cc569939b61ca14292 (patch) | |
tree | f8c4acb08a551820299dff2b13966d6ac38d31e4 /test | |
parent | 85995e88d49c442b5b113c2676456133e79f5c02 (diff) |
* lib/rubygems: Update to RubyGems 2.1.3
Fixed installing platform gems
Restored concurrent requires
Fixed installing gems with extensions with --install-dir
Fixed `gem fetch -v` to install the latest version
Fixed installing gems with "./" in their files entries
* test/rubygems/test_gem_package.rb: Tests for the above.
* NEWS: Updated for RubyGems 2.1.3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
45 files changed, 1154 insertions, 2015 deletions
diff --git a/test/rubygems/ca_cert.pem b/test/rubygems/ca_cert.pem index 5207531bc2..5acdcf8f32 100644 --- a/test/rubygems/ca_cert.pem +++ b/test/rubygems/ca_cert.pem @@ -43,26 +43,3 @@ ySjIblqVQkPuzebv3Ror6ZnVDukn96Mg7kP4u6zgxOeqlJGRe1M949SS9Vudjl8X SF4aZUUB9pQGhsqQJVqaz2OlhGOp9D0q54xko/rekjAIcuDjl1mdX4F2WRrzpUmZ uY/bPeOBYiVsOYVe -----END CERTIFICATE----- - ------BEGIN CERTIFICATE----- -MIIDtTCCAp2gAwIBAgIJANz6ehBcVuuiMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV -BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX -aWRnaXRzIFB0eSBMdGQwHhcNMTMwNTAxMTQ0NTQxWhcNMjMwMzEwMTQ0NTQxWjBF -MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50 -ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEAzlpZwhEYoALOEKU4lmMw5l3YI/gadzDOoELtdcidvVvovKK8IIOTDwbA -3XcjwV0UPGEPOK4Uk1aD0EKkOQVg8ivSre2a3FFGffs2kXck+doJMzAA+pf8tvFk -QsETVOurOp74GN+er2xbbRSDVxQKq6d+QTe1E60btyXQS5M1Nt5SvLn8dazZJgvv -3yzJQ1IOQl+xeEO0WVVhPIx5Mx3VtjjcDyl8aewPkYkzia6UOrAyQZnl5sIzWGOb -kYKCNeKjTPepzlbMx0dN6jBupPYGNB+4FYY9GezInjGbRP5np5382wd3EWwsVzic -Nau8kXHTL2r7GzNvoy0p//iPCqx9FQIDAQABo4GnMIGkMB0GA1UdDgQWBBS7B027 -H/ZIkW3ngm1SrR0X/aTCwDB1BgNVHSMEbjBsgBS7B027H/ZIkW3ngm1SrR0X/aTC -wKFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNV -BAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJANz6ehBcVuuiMAwGA1UdEwQF -MAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAC0glUrUiylTfuOWlwkQvi74oiYC5CzW -Jfusg6o/Gg1XEuJhaHiYMsK/do16gSc6Za3934rHQbYu3mesyFkCWF9kD4J6/hEO -OQL8xmmgN7wS6GXy6oIODpny0MgnFrV4gd1aEx69NIfL/wXaM8Gw2sj1TnuGLs8+ -HFmWLRRH3WSR7ZLnqYzPVJwhHu8vtZBL9HZk1J6xyq00Nwi2Cz5WdiHamgaza3TS -OgBdWwDeSClwhrTJni4d30dbq+eNMByIZ7QNGBQivpFzDxeNV/2UBrTU0CilKG5Q -j7ZwknfKeA4xUTd8TMK3vKab5JJCfjbXOTHZQsYUcEEGSjOMS8/YVQs= ------END CERTIFICATE----- diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 45db153c22..fda83767f2 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -13,21 +13,128 @@ end class TestGem < Gem::TestCase - PLUGINS_LOADED = [] - def setup super - PLUGINS_LOADED.clear - - common_installer_setup - ENV.delete 'RUBYGEMS_GEMDEPS' @additional = %w[a b].map { |d| File.join @tempdir, d } util_remove_interrupt_command end + def assert_activate expected, *specs + specs.each do |spec| + case spec + when String then + Gem::Specification.find_by_name(spec).activate + when Gem::Specification then + spec.activate + else + flunk spec.inspect + 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::Specification.unresolved_deps.values.map(&:to_s).sort + end + + # TODO: move these to specification + 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" + + install_specs a1, b1, b2 + + a1.activate + save_loaded_features do + require "b/c" + end + + assert_equal %w(a-1 b-1), loaded_spec_names + end + + # TODO: move these to specification + 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 + + a1.activate + 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 + + # TODO: move these to specification + 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" + + Gem::Specification.reset + install_specs a1, b1, b2, c1, c2 + + a1.activate + 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 + + # TODO: move these to specification + 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 + + a1.activate + 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_finish_resolve save_loaded_features do a1 = new_spec "a", "1", "b" => "> 0" @@ -50,6 +157,36 @@ class TestGem < Gem::TestCase end end + def test_self_activate_via_require_wtf + save_loaded_features do + a1 = new_spec "a", "1", "b" => "> 0", "d" => "> 0" # this + b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/b.rb" + b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/b.rb" # this + c1 = new_spec "c", "1" + c2 = new_spec "c", "2" # this + d1 = new_spec "d", "1", { "c" => "< 2" }, "lib/d.rb" + d2 = new_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this + + install_specs a1, b1, b2, c1, c2, d1, d2 + + a1.activate + + assert_equal %w(a-1), loaded_spec_names + assert_equal ["b (> 0)", "d (> 0)"], unresolved_names + + require "b" + + e = assert_raises Gem::LoadError do + require "d" + end + + assert_equal "unable to find a version of 'd' to activate", e.message + + assert_equal %w(a-1 b-2 c-2), loaded_spec_names + assert_equal ["d (> 0)"], unresolved_names + end + end + def test_self_finish_resolve_wtf save_loaded_features do a1 = new_spec "a", "1", "b" => "> 0", "d" => "> 0" # this @@ -74,6 +211,94 @@ class TestGem < Gem::TestCase end end + # TODO: move these to specification + 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, d1 + + a1.activate + 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 + + # TODO: move these to specification + 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, a2, b1, b2, c1, c2 + + a2.activate + 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 + + # TODO: move these to specification + def test_require_already_activated + save_loaded_features do + a1 = new_spec "a", "1", nil, "lib/d.rb" + + install_specs a1 # , a2, b1, b2, c1, c2 + + a1.activate + assert_equal %w(a-1), loaded_spec_names + assert_equal [], unresolved_names + + assert require "d" + + assert_equal %w(a-1), loaded_spec_names + assert_equal [], unresolved_names + end + end + + # TODO: move these to specification + def test_require_already_activated_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, a2, b1, b2, c1, c2 + + a1.activate + c1.activate + assert_equal %w(a-1 c-1), loaded_spec_names + assert_equal ["b (> 0)"], unresolved_names + + assert require "d" + + assert_equal %w(a-1 c-1), loaded_spec_names + assert_equal ["b (> 0)"], unresolved_names + end + end + def test_require_missing save_loaded_features do assert_raises ::LoadError do @@ -96,6 +321,221 @@ class TestGem < Gem::TestCase end end + # TODO: move these to specification + def test_self_activate_loaded + foo = util_spec 'foo', '1' + + assert foo.activate + refute foo.activate + 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 + # TODO: move these to specification + + 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' + util_spec 'c', '1.0', 'b' => '~> 1.0' + + a.activate + + 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 + # [C] = 1.0 depends on + # [B] = 2.0 + # [B] ~> 1.0 (satisfied by 1.0) + + def test_self_activate_checks_dependencies + a, _ = util_spec 'a', '1.0' + a.add_dependency 'c', '= 1.0' + a.add_dependency 'b', '~> 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 + + expected = "can't satisfy 'b (~> 1.0)', already activated 'b-2.0'" + assert_equal expected, e.message + 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_bin_path_no_exec_name e = assert_raises ArgumentError do Gem.bin_path 'a' @@ -350,7 +790,9 @@ class TestGem < Gem::TestCase spec } - Gem.refresh + # HACK should be Gem.refresh + Gem.searcher = nil + Gem::Specification.reset expected = [ File.expand_path('test/rubygems/sff/discover.rb', @@project_dir), @@ -364,37 +806,6 @@ class TestGem < Gem::TestCase assert_equal cwd, $LOAD_PATH.shift end - def test_self_find_latest_files - cwd = File.expand_path("test/rubygems", @@project_dir) - $LOAD_PATH.unshift cwd - - discover_path = File.join 'lib', 'sff', 'discover.rb' - - _, foo2 = %w(1 2).map { |version| - spec = quick_gem 'sff', version do |s| - s.files << discover_path - end - - write_file(File.join 'gems', spec.full_name, discover_path) do |fp| - fp.puts "# #{spec.full_name}" - end - - spec - } - - Gem.refresh - - expected = [ - File.expand_path('test/rubygems/sff/discover.rb', @@project_dir), - File.join(foo2.full_gem_path, discover_path), - ] - - assert_equal expected, Gem.find_latest_files('sff/discover') - assert_equal expected, Gem.find_latest_files('sff/**.rb'), '[ruby-core:31730]' - ensure - assert_equal cwd, $LOAD_PATH.shift - end - def test_self_latest_spec_for a1 = quick_spec 'a', 1 a2 = quick_spec 'a', 2 @@ -917,20 +1328,14 @@ class TestGem < Gem::TestCase Dir.chdir @tempdir do FileUtils.mkdir_p 'lib' File.open plugin_path, "w" do |fp| - fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end" - end - - foo1 = quick_spec 'foo', '1' do |s| - s.files << plugin_path + fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end" end - install_gem foo1 - - foo2 = quick_spec 'foo', '2' do |s| + foo = quick_spec 'foo', '1' do |s| s.files << plugin_path end - install_gem foo2 + install_gem foo end Gem.searcher = nil @@ -940,7 +1345,7 @@ class TestGem < Gem::TestCase Gem.load_plugins - assert_equal %w[plugin], PLUGINS_LOADED + assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD end def test_load_env_plugins @@ -1153,61 +1558,6 @@ class TestGem < Gem::TestCase assert_equal '["a-1", "b-1", "c-1"]', out.strip end - def test_register_default_spec - Gem.clear_default_specs - - old_style = Gem::Specification.new do |spec| - spec.files = ["foo.rb", "bar.rb"] - end - - Gem.register_default_spec old_style - - assert_equal old_style, Gem.find_unresolved_default_spec("foo.rb") - assert_equal old_style, Gem.find_unresolved_default_spec("bar.rb") - assert_equal nil, Gem.find_unresolved_default_spec("baz.rb") - - Gem.clear_default_specs - - new_style = Gem::Specification.new do |spec| - spec.files = ["lib/foo.rb", "ext/bar.rb", "bin/exec", "README"] - spec.require_paths = ["lib", "ext"] - end - - Gem.register_default_spec new_style - - assert_equal new_style, Gem.find_unresolved_default_spec("foo.rb") - assert_equal new_style, Gem.find_unresolved_default_spec("bar.rb") - assert_equal nil, Gem.find_unresolved_default_spec("exec") - assert_equal nil, Gem.find_unresolved_default_spec("README") - end - - def test_default_gems_use_full_paths - begin - if defined?(RUBY_ENGINE) then - engine = RUBY_ENGINE - Object.send :remove_const, :RUBY_ENGINE - end - Object.const_set :RUBY_ENGINE, 'ruby' - - refute Gem.default_gems_use_full_paths? - ensure - Object.send :remove_const, :RUBY_ENGINE - Object.const_set :RUBY_ENGINE, engine if engine - end - - begin - if defined?(RUBY_ENGINE) then - engine = RUBY_ENGINE - Object.send :remove_const, :RUBY_ENGINE - end - Object.const_set :RUBY_ENGINE, 'jruby' - assert Gem.default_gems_use_full_paths? - ensure - Object.send :remove_const, :RUBY_ENGINE - Object.const_set :RUBY_ENGINE, engine if engine - end - end - def with_plugin(path) test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}", @@project_dir) @@ -1284,3 +1634,4 @@ class TestGem < Gem::TestCase File.join Gem.dir, "cache" end end + diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index f6433c5cc3..e201d73275 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -58,7 +58,7 @@ class TestGemCommandManager < Gem::TestCase use_ui @ui do assert_raises Gem::MockGemUi::TermError do - @command_manager.run %w[interrupt] + @command_manager.run 'interrupt' end assert_equal '', ui.output assert_equal "ERROR: Interrupted\n", ui.error @@ -75,7 +75,7 @@ class TestGemCommandManager < Gem::TestCase @command_manager.register_command :crash use_ui @ui do assert_raises Gem::MockGemUi::TermError do - @command_manager.run %w[crash] + @command_manager.run 'crash' end assert_equal '', ui.output err = ui.error.split("\n").first @@ -89,7 +89,7 @@ class TestGemCommandManager < Gem::TestCase def test_process_args_bad_arg use_ui @ui do assert_raises Gem::MockGemUi::TermError do - @command_manager.process_args %w[--bad-arg] + @command_manager.process_args("--bad-arg") end end @@ -107,7 +107,7 @@ class TestGemCommandManager < Gem::TestCase end #check defaults - @command_manager.process_args %w[install] + @command_manager.process_args("install") assert_equal %w[ri], check_options[:document].sort assert_equal false, check_options[:force] assert_equal :both, check_options[:domain] @@ -118,10 +118,8 @@ class TestGemCommandManager < Gem::TestCase #check settings check_options = nil - @command_manager.process_args %w[ - install --force --local --rdoc --install-dir . - --version 3.0 --no-wrapper --bindir . - ] + @command_manager.process_args( + "install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ") assert_equal %w[rdoc ri], check_options[:document].sort assert_equal true, check_options[:force] assert_equal :local, check_options[:domain] @@ -132,17 +130,17 @@ class TestGemCommandManager < Gem::TestCase #check remote domain check_options = nil - @command_manager.process_args %w[install --remote] + @command_manager.process_args("install --remote") assert_equal :remote, check_options[:domain] #check both domain check_options = nil - @command_manager.process_args %w[install --both] + @command_manager.process_args("install --both") assert_equal :both, check_options[:domain] #check both domain check_options = nil - @command_manager.process_args %w[install --both] + @command_manager.process_args("install --both") assert_equal :both, check_options[:domain] end end @@ -157,12 +155,12 @@ class TestGemCommandManager < Gem::TestCase end #check defaults - @command_manager.process_args %w[uninstall] + @command_manager.process_args("uninstall") assert_equal Gem::Requirement.default, check_options[:version] #check settings check_options = nil - @command_manager.process_args %w[uninstall foobar --version 3.0] + @command_manager.process_args("uninstall foobar --version 3.0") assert_equal "foobar", check_options[:args].first assert_equal Gem::Requirement.new('3.0'), check_options[:version] end @@ -177,12 +175,12 @@ class TestGemCommandManager < Gem::TestCase end #check defaults - @command_manager.process_args %w[check] + @command_manager.process_args("check") assert_equal true, check_options[:alien] #check settings check_options = nil - @command_manager.process_args %w[check foobar --alien] + @command_manager.process_args("check foobar --alien") assert_equal true, check_options[:alien] end @@ -196,12 +194,12 @@ class TestGemCommandManager < Gem::TestCase end #check defaults - @command_manager.process_args %w[build] + @command_manager.process_args("build") #NOTE: Currently no defaults #check settings check_options = nil - @command_manager.process_args %w[build foobar.rb] + @command_manager.process_args("build foobar.rb") assert_equal 'foobar.rb', check_options[:args].first end @@ -215,26 +213,26 @@ class TestGemCommandManager < Gem::TestCase end #check defaults - @command_manager.process_args %w[query] + @command_manager.process_args("query") assert_equal(//, check_options[:name]) assert_equal :local, check_options[:domain] assert_equal false, check_options[:details] #check settings check_options = nil - @command_manager.process_args %w[query --name foobar --local --details] + @command_manager.process_args("query --name foobar --local --details") assert_equal(/foobar/i, check_options[:name]) assert_equal :local, check_options[:domain] assert_equal true, check_options[:details] #remote domain check_options = nil - @command_manager.process_args %w[query --remote] + @command_manager.process_args("query --remote") assert_equal :remote, check_options[:domain] #both (local/remote) domains check_options = nil - @command_manager.process_args %w[query --both] + @command_manager.process_args("query --both") assert_equal :both, check_options[:domain] end @@ -248,12 +246,12 @@ class TestGemCommandManager < Gem::TestCase end #check defaults - @command_manager.process_args %w[update] + @command_manager.process_args("update") assert_includes check_options[:document], 'rdoc' #check settings check_options = nil - @command_manager.process_args %w[update --force --rdoc --install-dir .] + @command_manager.process_args("update --force --rdoc --install-dir .") assert_includes check_options[:document], 'ri' assert_equal true, check_options[:force] assert_equal Dir.pwd, check_options[:install_dir] diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index a158a4442b..75db6c4e15 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -2,8 +2,8 @@ require 'rubygems/test_case' require 'rubygems/commands/cert_command' require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9" -unless defined?(OpenSSL::SSL) then - warn 'Skipping `gem cert` tests. openssl not found.' +unless defined? OpenSSL then + warn "`gem cert` tests are being skipped, module OpenSSL not found" end class TestGemCommandsCertCommand < Gem::TestCase @@ -98,22 +98,14 @@ Added '/CN=alternate/DC=example' end def test_execute_build - passphrase = 'Foo bar' - @cmd.handle_options %W[--build [email protected]] - @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}" - - use_ui @build_ui do + use_ui @ui do @cmd.execute end - output = @build_ui.output.split "\n" + output = @ui.output.split "\n" - assert_equal "Passphrase for your Private Key: ", - output.shift - assert_equal "Please repeat the passphrase for your Private Key: ", - output.shift assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", output.shift assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}", @@ -123,43 +115,12 @@ Added '/CN=alternate/DC=example' output.shift assert_empty output - assert_empty @build_ui.error + assert_empty @ui.error assert_path_exists File.join(@tempdir, 'gem-private_key.pem') assert_path_exists File.join(@tempdir, 'gem-public_cert.pem') end - def test_execute_build_bad_passphrase_confirmation - passphrase = 'Foo bar' - passphrase_confirmation = 'Fu bar' - - @cmd.handle_options %W[--build [email protected]] - - @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase_confirmation}" - - use_ui @build_ui do - e = assert_raises Gem::CommandLineError do - @cmd.execute - end - - output = @build_ui.output.split "\n" - - assert_equal "Passphrase for your Private Key: ", - output.shift - assert_equal "Please repeat the passphrase for your Private Key: ", - output.shift - - assert_empty output - - assert_equal "Passphrase and passphrase confirmation don't match", - e.message - - end - - refute_path_exists File.join(@tempdir, 'gem-private_key.pem') - refute_path_exists File.join(@tempdir, 'gem-public_cert.pem') - end - def test_execute_build_key @cmd.handle_options %W[ --build [email protected] @@ -174,32 +135,21 @@ Added '/CN=alternate/DC=example' assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", output.shift + assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}", + output.shift - assert_empty output - assert_empty @ui.error - - assert_path_exists File.join(@tempdir, 'gem-public_cert.pem') - end - - def test_execute_build_encrypted_key - @cmd.handle_options %W[ - --build [email protected] - --private-key #{ENCRYPTED_PRIVATE_KEY_PATH} - ] - - use_ui @ui do - @cmd.execute - end - - output = @ui.output.split "\n" - - assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", + assert_equal "Don't forget to move the key file to somewhere private!", output.shift assert_empty output assert_empty @ui.error assert_path_exists File.join(@tempdir, 'gem-public_cert.pem') + + private_key_file = File.join @tempdir, 'gem-private_key.pem' + assert_path_exists private_key_file + + assert_equal PRIVATE_KEY.to_pem, File.read(private_key_file) end def test_execute_certificate @@ -253,17 +203,6 @@ Added '/CN=alternate/DC=example' assert_equal PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem end - def test_execute_encrypted_private_key - use_ui @ui do - @cmd.send :handle_options, %W[--private-key #{ENCRYPTED_PRIVATE_KEY_PATH}] - end - - assert_equal '', @ui.output - assert_equal '', @ui.error - - assert_equal ENCRYPTED_PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem - end - def test_execute_remove @trust_dir.trust_cert PUBLIC_CERT @@ -368,35 +307,6 @@ Removed '/CN=alternate/DC=example' assert_equal mask, File.stat(path).mode unless win_platform? end - def test_execute_sign_encrypted_key - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 - - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s - - @cmd.handle_options %W[ - --private-key #{ENCRYPTED_PRIVATE_KEY_PATH} - --certificate #{PUBLIC_CERT_FILE} - - --sign #{path} - ] - - use_ui @ui do - @cmd.execute - end - - assert_equal '', @ui.output - assert_equal '', @ui.error - - cert = OpenSSL::X509::Certificate.new File.read path - - assert_equal '/CN=nobody/DC=example', cert.issuer.to_s - - mask = 0100600 & (~File.umask) - - assert_equal mask, File.stat(path).mode unless win_platform? - end - def test_execute_sign_default FileUtils.mkdir_p File.join Gem.user_home, '.gem' @@ -429,38 +339,6 @@ Removed '/CN=alternate/DC=example' assert_equal mask, File.stat(path).mode unless win_platform? end - def test_execute_sign_default_encrypted_key - FileUtils.mkdir_p File.join(Gem.user_home, '.gem') - - private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem' - Gem::Security.write ENCRYPTED_PRIVATE_KEY, private_key_path, 0600, PRIVATE_KEY_PASSPHRASE - - public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' - Gem::Security.write PUBLIC_CERT, public_cert_path - - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 - - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s - - @cmd.handle_options %W[--sign #{path}] - - use_ui @ui do - @cmd.execute - end - - assert_equal '', @ui.output - assert_equal '', @ui.error - - cert = OpenSSL::X509::Certificate.new File.read path - - assert_equal '/CN=nobody/DC=example', cert.issuer.to_s - - mask = 0100600 & (~File.umask) - - assert_equal mask, File.stat(path).mode unless win_platform? - end - def test_execute_sign_no_cert FileUtils.mkdir_p File.join Gem.user_home, '.gem' @@ -631,24 +509,6 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis assert_equal [ALTERNATE_CERT_FILE, CHILD_CERT_FILE], @cmd.options[:sign] end - def test_handle_options_sign_encrypted_key - @cmd.handle_options %W[ - --private-key #{ALTERNATE_KEY_FILE} - --private-key #{ENCRYPTED_PRIVATE_KEY_PATH} - - --certificate #{ALTERNATE_CERT_FILE} - --certificate #{PUBLIC_CERT_FILE} - - --sign #{ALTERNATE_CERT_FILE} - --sign #{CHILD_CERT_FILE} - ] - - assert_equal ENCRYPTED_PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem - assert_equal PUBLIC_CERT.to_pem, @cmd.options[:issuer_cert].to_pem - - assert_equal [ALTERNATE_CERT_FILE, CHILD_CERT_FILE], @cmd.options[:sign] - end - def test_handle_options_sign_nonexistent nonexistent = File.join @tempdir, 'nonexistent' e = assert_raises OptionParser::InvalidArgument do @@ -665,5 +525,5 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis e.message end -end if defined?(OpenSSL::SSL) +end if defined? OpenSSL diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb index 6fd06d26e0..26b1fe7b0c 100644 --- a/test/rubygems/test_gem_commands_cleanup_command.rb +++ b/test/rubygems/test_gem_commands_cleanup_command.rb @@ -15,21 +15,6 @@ class TestGemCommandsCleanupCommand < Gem::TestCase install_gem @a_2 end - def test_handle_options_d - @cmd.handle_options %w[-d] - assert @cmd.options[:dryrun] - end - - def test_handle_options_dry_run - @cmd.handle_options %w[--dryrun] - assert @cmd.options[:dryrun] - end - - def test_handle_options_n - @cmd.handle_options %w[-n] - assert @cmd.options[:dryrun] - end - def test_execute @cmd.options[:args] = %w[a] diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb index d87e84fc82..60df53f53b 100644 --- a/test/rubygems/test_gem_commands_contents_command.rb +++ b/test/rubygems/test_gem_commands_contents_command.rb @@ -91,34 +91,6 @@ class TestGemCommandsContentsCommand < Gem::TestCase assert_equal "", @ui.error end - def test_execute_missing_single - @cmd.options[:args] = %w[foo] - - assert_raises Gem::MockGemUi::TermError do - use_ui @ui do - @cmd.execute - end - end - - assert_match "Unable to find gem 'foo'", @ui.output - assert_empty @ui.error - end - - def test_execute_missing_multiple - @cmd.options[:args] = %w[foo bar] - - gem 'foo' - - use_ui @ui do - @cmd.execute - end - - assert_match "lib/foo.rb", @ui.output - assert_match "Unable to find gem 'bar'", @ui.output - - assert_empty @ui.error - end - def test_execute_multiple @cmd.options[:args] = %w[foo bar] @@ -168,10 +140,10 @@ lib/foo.rb @cmd.execute end - expected = [ - File.join(Gem::ConfigMap[:bindir], 'default_command'), - File.join(Gem::ConfigMap[:rubylibdir], 'default/gem.rb'), - File.join(Gem::ConfigMap[:archdir], 'default_gem.so') + expected = %W[ + #{Gem::ConfigMap[:bindir]}/default_command + #{Gem::ConfigMap[:rubylibdir]}/default/gem.rb + #{Gem::ConfigMap[:archdir]}/default_gem.so ].sort.join "\n" assert_equal expected, @ui.output.chomp diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb index 253c459d94..439057df9d 100644 --- a/test/rubygems/test_gem_commands_environment_command.rb +++ b/test/rubygems/test_gem_commands_environment_command.rb @@ -11,7 +11,6 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase def test_execute orig_sources = Gem.sources.dup - orig_path, ENV['PATH'] = ENV['PATH'], %w[/usr/local/bin /usr/bin /bin].join(File::PATH_SEPARATOR) Gem.sources.replace %w[http://gems.example.com] Gem.configuration['gemcutter_key'] = 'blah' @@ -37,17 +36,10 @@ class TestGemCommandsEnvironmentCommand < Gem::TestCase assert_match %r|"gemcutter_key" => "\*\*\*\*"|, @ui.output assert_match %r|:verbose => |, @ui.output assert_match %r|REMOTE SOURCES:|, @ui.output - - assert_match %r|- SHELL PATH:|, @ui.output - assert_match %r|- /usr/local/bin$|, @ui.output - assert_match %r|- /usr/bin$|, @ui.output - assert_match %r|- /bin$|, @ui.output - - assert_empty @ui.error + assert_equal '', @ui.error ensure Gem.sources.replace orig_sources - ENV['PATH'] = orig_path end def test_execute_gemdir diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb index 364881a132..924f4c44e7 100644 --- a/test/rubygems/test_gem_commands_fetch_command.rb +++ b/test/rubygems/test_gem_commands_fetch_command.rb @@ -34,32 +34,6 @@ class TestGemCommandsFetchCommand < Gem::TestCase 'gem repository directories must not be created' end - def test_execute_latest - util_setup_fake_fetcher - util_setup_spec_fetcher @a1, @a2 - - @fetcher.data["#{@gem_repo}gems/#{@a1.file_name}"] = - File.read(@a1.cache_file) - @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] = - File.read(@a2.cache_file) - - refute_path_exists File.join(@tempdir, 'cache'), 'sanity check' - - @cmd.options[:args] = [@a2.name] - @cmd.options[:version] = req('>= 0.1') - - use_ui @ui do - Dir.chdir @tempdir do - @cmd.execute - end - end - - assert_path_exists(File.join(@tempdir, @a2.file_name), - "#{@a2.full_name} not fetched") - refute_path_exists File.join(@tempdir, 'cache'), - 'gem repository directories must not be created' - end - def test_execute_prerelease util_setup_fake_fetcher true util_clear_gems @@ -79,8 +53,8 @@ class TestGemCommandsFetchCommand < Gem::TestCase end end - assert_path_exists(File.join(@tempdir, @a2.file_name), - "#{@a2.full_name} not fetched") + assert_path_exists(File.join(@tempdir, @a2_pre.file_name), + "#{@a2_pre.full_name} not fetched") end def test_execute_specific_prerelease diff --git a/test/rubygems/test_gem_commands_help_command.rb b/test/rubygems/test_gem_commands_help_command.rb index 3a6f2fa523..a10e575a5a 100644 --- a/test/rubygems/test_gem_commands_help_command.rb +++ b/test/rubygems/test_gem_commands_help_command.rb @@ -18,7 +18,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase def test_gem_help_bad util_gem 'bad' do |out, err| assert_equal('', out) - assert_match "Unknown command bad", err + assert_match(/Unknown command bad. Try gem help commands\n/, err) end end @@ -36,12 +36,9 @@ class TestGemCommandsHelpCommand < Gem::TestCase mgr.command_names.each do |cmd| assert_match(/\s+#{cmd}\s+\S+/, out) end + assert_equal '', err - if defined?(OpenSSL::SSL) then - assert_empty err - - refute_match 'No command found for ', out - end + refute_match 'No command found for ', out end end diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index caf52f147d..f86d2837ea 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -6,7 +6,6 @@ class TestGemCommandsInstallCommand < Gem::TestCase def setup super - common_installer_setup @cmd = Gem::Commands::InstallCommand.new @cmd.options[:document] = [] @@ -169,7 +168,8 @@ class TestGemCommandsInstallCommand < Gem::TestCase # This is needed because we need to exercise the cache path # within SpecFetcher - path = File.join Gem.spec_cache_dir, "not-there.nothing%80", "latest_specs.4.8" + path = File.join Gem.user_home, '.gem', 'specs', "not-there.nothing%80", + "latest_specs.4.8" FileUtils.mkdir_p File.dirname(path) @@ -633,6 +633,67 @@ ERROR: Possible alternatives: non_existent_with_hint assert_equal x, e end + def test_execute_installs_dependencies + r, r_gem = util_gem 'r', '1', 'q' => '= 1' + q, q_gem = util_gem 'q', '1' + + util_setup_fake_fetcher + util_setup_spec_fetcher r, q + + Gem::Specification.reset + + @fetcher.data["#{@gem_repo}gems/#{q.file_name}"] = read_binary(q_gem) + @fetcher.data["#{@gem_repo}gems/#{r.file_name}"] = read_binary(r_gem) + + @cmd.options[:args] = ["r"] + + e = nil + use_ui @ui do + e = assert_raises Gem::SystemExitException do + capture_io do + @cmd.execute + end + end + end + + out = @ui.output.split "\n" + assert_equal "2 gems installed", out.shift + assert out.empty?, out.inspect + + assert_equal %w[q-1 r-1], @cmd.installed_specs.map { |spec| spec.full_name } + + assert_equal 0, e.exit_code + end + + def test_execute_satisfy_deps_of_local_from_sources + r, r_gem = util_gem 'r', '1', 'q' => '= 1' + q, q_gem = util_gem 'q', '1' + + util_setup_fake_fetcher + util_setup_spec_fetcher r, q + + Gem::Specification.reset + + @fetcher.data["#{@gem_repo}gems/#{q.file_name}"] = read_binary(q_gem) + + @cmd.options[:args] = [r_gem] + + use_ui @ui do + e = assert_raises Gem::SystemExitException do + capture_io do + @cmd.execute + end + end + assert_equal 0, e.exit_code + end + + assert_equal %w[q-1 r-1], @cmd.installed_specs.map { |spec| spec.full_name } + + out = @ui.output.split "\n" + assert_equal "2 gems installed", out.shift + assert out.empty?, out.inspect + end + def test_execute_uses_from_a_gemdeps util_setup_fake_fetcher util_setup_spec_fetcher @@ -890,3 +951,4 @@ ERROR: Possible alternatives: non_existent_with_hint end + diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb index 5d7b66137e..dfbc2572dc 100644 --- a/test/rubygems/test_gem_commands_owner_command.rb +++ b/test/rubygems/test_gem_commands_owner_command.rb @@ -6,7 +6,6 @@ class TestGemCommandsOwnerCommand < Gem::TestCase def setup super - ENV["RUBYGEMS_HOST"] = nil @fetcher = Gem::FakeFetcher.new Gem::RemoteFetcher.fetcher = @fetcher Gem.configuration.rubygems_api_key = "ed244fbf2b1a52e012da8616c512fa47f9aa5250" @@ -35,36 +34,6 @@ EOF assert_match %r{- [email protected]}, @ui.output end - def test_show_owners_setting_up_host_through_env_var - response = "- email: [email protected]\n" - host = "http://rubygems.example" - ENV["RUBYGEMS_HOST"] = host - - @fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK'] - - use_ui @ui do - @cmd.show_owners("freewill") - end - - assert_match %r{Owners for gem: freewill}, @ui.output - assert_match %r{- [email protected]}, @ui.output - end - - def test_show_owners_setting_up_host - response = "- email: [email protected]\n" - host = "http://rubygems.example" - @cmd.host = host - - @fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK'] - - use_ui @ui do - @cmd.show_owners("freewill") - end - - assert_match %r{Owners for gem: freewill}, @ui.output - assert_match %r{- [email protected]}, @ui.output - end - def test_show_owners_denied response = "You don't have permission to push to this gem" @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden'] @@ -118,24 +87,6 @@ EOF assert_match response, @ui.output end - def test_add_owner_with_host_option_through_execute - host = "http://rubygems.example" - add_owner_response = "Owner added successfully." - show_owners_response = "- email: [email protected]\n" - @fetcher.data["#{host}/api/v1/gems/freewill/owners"] = [add_owner_response, 200, 'OK'] - @fetcher.data["#{host}/api/v1/gems/freewill/owners.yaml"] = [show_owners_response, 200, 'OK'] - - @cmd.handle_options %W[--host #{host} --add [email protected] freewill] - - use_ui @ui do - @cmd.execute - end - - assert_match add_owner_response, @ui.output - assert_match %r{Owners for gem: freewill}, @ui.output - assert_match %r{- [email protected]}, @ui.output - end - def test_add_owners_key response = "Owner added successfully." @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK'] diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index 78c3f85a5b..778ce2ee1f 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -80,36 +80,6 @@ class TestGemCommandsPristineCommand < Gem::TestCase assert_empty out, out.inspect end - def test_execute_env_shebang - a = quick_spec 'a' do |s| - s.executables = %w[foo] - s.files = %w[bin/foo] - end - write_file File.join(@tempdir, 'bin', 'foo') do |fp| - fp.puts "#!/usr/bin/ruby" - end - - install_gem a - - gem_exec = File.join @gemhome, 'bin', 'foo' - - FileUtils.rm gem_exec - - @cmd.handle_options %w[--all --env-shebang] - - use_ui @ui do - @cmd.execute - end - - assert_path_exists gem_exec - - if win_platform? - assert_match %r%\A#!\s*ruby%, File.read(gem_exec) - else - assert_match %r%\A#!\s*/usr/bin/env ruby%, File.read(gem_exec) - end - end - def test_execute_no_extension a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb index 1e5afca009..8dc2f91ed4 100644 --- a/test/rubygems/test_gem_commands_sources_command.rb +++ b/test/rubygems/test_gem_commands_sources_command.rb @@ -194,7 +194,7 @@ beta-gems.example.com is not a URI assert_equal expected, @ui.output assert_equal '', @ui.error - dir = Gem.spec_cache_dir + dir = File.join Gem.user_home, '.gem', 'specs' refute File.exist?(dir), 'cache dir removed' end diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 9ba1371b79..844c7b4b97 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -16,20 +16,6 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase @executable = File.join(@gemhome, 'bin', 'executable') end - def test_execute_all_gem_names - @cmd.options[:args] = %w[a b] - @cmd.options[:all] = true - - assert_raises Gem::MockGemUi::TermError do - use_ui @ui do - @cmd.execute - end - end - - assert_match(/\A(?:WARNING: Unable to use symlinks on Windows, installing wrapper\n)?ERROR: Gem names and --all may not be used together\n\z/, - @ui.error) - end - def test_execute_dependency_order c = quick_gem 'c' do |spec| spec.add_dependency 'a' @@ -57,7 +43,6 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase def test_execute_removes_executable ui = Gem::MockGemUi.new - util_setup_gem ui build_rake_in do @@ -190,32 +175,5 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert Gem::Specification.find_all_by_name('x').length == 0 end - def test_execute_all - util_make_gems - - default = new_default_spec 'default', '1' - install_default_gems default - - gemhome2 = "#{@gemhome}2" - - a_4 = quick_spec 'a', 4 - install_gem a_4, :install_dir => gemhome2 - - Gem::Specification.dirs = [@gemhome, gemhome2] - - assert_includes Gem::Specification.all_names, 'a-1' - assert_includes Gem::Specification.all_names, 'a-4' - assert_includes Gem::Specification.all_names, 'default-1' - - @cmd.options[:all] = true - @cmd.options[:args] = [] - - use_ui @ui do - @cmd.execute - end - - assert_equal %w[a-4 default-1], Gem::Specification.all_names.sort - end - end diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index d1c1b20c6e..006d821210 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -11,7 +11,6 @@ class TestGemCommandsUpdateCommand < Gem::TestCase def setup super - common_installer_setup @cmd = Gem::Commands::UpdateCommand.new @@ -254,7 +253,7 @@ class TestGemCommandsUpdateCommand < Gem::TestCase out = @ui.output.split "\n" assert_equal "Updating installed gems", out.shift assert_equal "Updating #{@a2.name}", out.shift - assert_equal "Gems updated: #{@a2.name} #{@b2.name} #{@c2.name}", + assert_equal "Gems updated: #{@c2.name} #{@b2.name} #{@a2.name}", out.shift assert_empty out diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index e9cd33579d..13f1c34b50 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -201,10 +201,6 @@ ERROR: Your gem push credentials file located at: has file permissions of 0644 but 0600 is required. -To fix this error run: - -\tchmod 0600 #{@cfg.credentials_path} - You should reset your credentials at: \thttps://rubygems.org/profile/edit @@ -432,14 +428,6 @@ if you believe they were disclosed to a third party. assert_equal('/home/me/certs', @cfg.ssl_ca_cert) end - def test_load_ssl_client_cert_from_config - File.open @temp_conf, 'w' do |fp| - fp.puts ":ssl_client_cert: /home/me/mine.pem" - end - util_config_file - assert_equal('/home/me/mine.pem', @cfg.ssl_client_cert) - end - def util_config_file(args = @cfg_args) @cfg = Gem::ConfigFile.new args end diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index af6b922fe3..2b95597d4b 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -6,7 +6,6 @@ class TestGemDependencyInstaller < Gem::TestCase def setup super - common_installer_setup @gems_dir = File.join @tempdir, 'gems' @cache_dir = File.join @gemhome, 'cache' @@ -173,8 +172,7 @@ class TestGemDependencyInstaller < Gem::TestCase FileUtils.mv @a1_gem, @tempdir FileUtils.mv @b1_gem, @tempdir - FileUtils.mv e1_gem, @tempdir - + FileUtils.mv e1_gem, @tempdir inst = nil Dir.chdir @tempdir do @@ -182,15 +180,40 @@ class TestGemDependencyInstaller < Gem::TestCase inst.install 'b' end - assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }, - 'sanity check' - Dir.chdir @tempdir do inst = Gem::DependencyInstaller.new inst.install 'e' end - assert_equal %w[a-1 e-1], inst.installed_gems.map { |s| s.full_name } + assert_equal %w[e-1 a-1], inst.installed_gems.map { |s| s.full_name } + end + + def test_install_ignore_satified_deps + util_setup_gems + + _, e1_gem = util_gem 'e', '1' do |s| + s.add_dependency 'b' + end + + util_clear_gems + + FileUtils.mv @a1_gem, @tempdir + FileUtils.mv @b1_gem, @tempdir + FileUtils.mv e1_gem, @tempdir + + Dir.chdir @tempdir do + i = Gem::DependencyInstaller.new :ignore_dependencies => true + i.install 'b' + end + + inst = nil + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new :minimal_deps => true + inst.install 'e' + end + + assert_equal %w[e-1], inst.installed_gems.map { |s| s.full_name } end def test_install_cache_dir @@ -223,18 +246,15 @@ class TestGemDependencyInstaller < Gem::TestCase Gem::Specification.reset FileUtils.mv @a1_gem, @tempdir - FileUtils.mv a2_gem, @tempdir # not in index + FileUtils.mv a2_gem, @tempdir # not in index FileUtils.mv @b1_gem, @tempdir inst = nil Dir.chdir @tempdir do inst = Gem::DependencyInstaller.new - inst.install 'a', req("= 2") + inst.install 'a', Gem::Requirement.create("= 2") end - assert_equal %w[a-2], inst.installed_gems.map { |s| s.full_name }, - 'sanity check' - FileUtils.rm File.join(@tempdir, a2.file_name) Dir.chdir @tempdir do @@ -262,18 +282,19 @@ class TestGemDependencyInstaller < Gem::TestCase Gem::Specification.reset FileUtils.mv @a1_gem, @tempdir - FileUtils.mv a2_gem, @tempdir # not in index + FileUtils.mv a2_gem, @tempdir # not in index FileUtils.mv @b1_gem, @tempdir - FileUtils.mv a3_gem, @tempdir + FileUtils.mv a3_gem, @tempdir + + inst = nil Dir.chdir @tempdir do - Gem::DependencyInstaller.new.install 'a', req("= 2") + inst = Gem::DependencyInstaller.new + inst.install 'a', Gem::Requirement.create("= 2") end FileUtils.rm File.join(@tempdir, a2.file_name) - inst = nil - Dir.chdir @tempdir do inst = Gem::DependencyInstaller.new inst.install 'b' @@ -467,42 +488,6 @@ class TestGemDependencyInstaller < Gem::TestCase assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end - def test_install_minimal_deps - util_setup_gems - - _, e1_gem = util_gem 'e', '1' do |s| - s.add_dependency 'b' - end - - _, b2_gem = util_gem 'b', '2' do |s| - s.add_dependency 'a' - end - - util_clear_gems - - FileUtils.mv @a1_gem, @tempdir - FileUtils.mv @b1_gem, @tempdir - FileUtils.mv b2_gem, @tempdir - FileUtils.mv e1_gem, @tempdir - - inst = nil - - Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new :ignore_dependencies => true - inst.install 'b', req('= 1') - end - - assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }, - 'sanity check' - - Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new :minimal_deps => true - inst.install 'e' - end - - assert_equal %w[a-1 e-1], inst.installed_gems.map { |s| s.full_name } - end - def test_install_env_shebang util_setup_gems @@ -642,12 +627,12 @@ class TestGemDependencyInstaller < Gem::TestCase inst = nil Dir.chdir @tempdir do - e = assert_raises Gem::UnsatisfiableDependencyError do + e = assert_raises Gem::DependencyError do inst = Gem::DependencyInstaller.new :domain => :local inst.install 'b' end - expected = "Unable to resolve dependency: b (= 1) requires a (>= 0)" + expected = "Unable to resolve dependencies: b requires a (>= 0)" assert_equal expected, e.message end @@ -925,13 +910,12 @@ class TestGemDependencyInstaller < Gem::TestCase gems = set.sorted assert_equal 2, gems.length - - remote, local = gems - + local = gems.first assert_equal 'a-1', local.spec.full_name, 'local spec' assert_equal File.join(@tempdir, @a1.file_name), local.source.download(local.spec), 'local path' + remote = gems.last assert_equal 'a-1', remote.spec.full_name, 'remote spec' assert_equal Gem::Source.new(@gem_repo), remote.source, 'remote path' diff --git a/test/rubygems/test_gem_dependency_resolver.rb b/test/rubygems/test_gem_dependency_resolver.rb index 47eef8cc55..08d8e62f2b 100644 --- a/test/rubygems/test_gem_dependency_resolver.rb +++ b/test/rubygems/test_gem_dependency_resolver.rb @@ -15,9 +15,7 @@ class TestGemDependencyResolver < Gem::TestCase exp = expected.sort_by { |s| s.full_name } act = actual.map { |a| a.spec }.sort_by { |s| s.full_name } - msg = "Set of gems was not the same: #{exp.map { |x| x.full_name}.inspect} != #{act.map { |x| x.full_name}.inspect}" - - assert_equal exp, act, msg + assert_equal exp, act end def test_no_overlap_specificly @@ -66,32 +64,6 @@ class TestGemDependencyResolver < Gem::TestCase assert_set [a2], res.resolve end - def test_picks_best_platform - is = Gem::DependencyResolver::IndexSpecification - unknown = Gem::Platform.new 'unknown' - a2_p1 = quick_spec 'a', 2 do |s| s.platform = Gem::Platform.local end - a3_p2 = quick_spec 'a', 3 do |s| s.platform = unknown end - v2 = v(2) - v3 = v(3) - source = Gem::Source.new @gem_repo - - s = set - - a2 = is.new s, 'a', v2, source, Gem::Platform::RUBY - a2_p1 = is.new s, 'a', v2, source, Gem::Platform.local.to_s - a3_p2 = is.new s, 'a', v3, source, unknown - - s.add a3_p2 - s.add a2_p1 - s.add a2 - - ad = make_dep "a" - - res = Gem::DependencyResolver.new([ad], s) - - assert_set [a2_p1], res.resolve - end - def test_only_returns_spec_once a1 = util_spec "a", "1", "c" => "= 1" b1 = util_spec "b", "1", "c" => "= 1" @@ -205,8 +177,7 @@ class TestGemDependencyResolver < Gem::TestCase r.resolve end - assert_equal "Unable to resolve dependency: (unknown) requires a (>= 0)", - e.message + assert_equal "unable to find any gem matching dependency 'a (>= 0)'", e.message assert_equal "a (>= 0)", e.dependency.to_s end @@ -244,7 +215,7 @@ class TestGemDependencyResolver < Gem::TestCase r.resolve end - assert_match "a-1 requires c (>= 2) but it conflicted", e.message + assert_equal "detected 1 conflict with dependency 'c (>= 2)'", e.message assert_equal "c (>= 2)", e.dependency.to_s @@ -353,18 +324,4 @@ class TestGemDependencyResolver < Gem::TestCase assert_set [b1, c1, d2], r.resolve end - - def test_select_local_platforms - r = Gem::DependencyResolver.new nil, nil - - a1 = quick_spec 'a', 1 - a1_p1 = quick_spec 'a', 1 do |s| s.platform = Gem::Platform.local end - a1_p2 = quick_spec 'a', 1 do |s| s.platform = 'unknown' end - - selected = r.select_local_platforms [a1, a1_p1, a1_p2] - - assert_equal [a1, a1_p1], selected - end - end - diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb index 8383040f88..6e34ee7e46 100644 --- a/test/rubygems/test_gem_ext_builder.rb +++ b/test/rubygems/test_gem_ext_builder.rb @@ -1,6 +1,5 @@ require 'rubygems/test_case' require 'rubygems/ext' -require 'rubygems/installer' class TestGemExtBuilder < Gem::TestCase @@ -14,10 +13,6 @@ class TestGemExtBuilder < Gem::TestCase FileUtils.mkdir_p @dest_path @orig_DESTDIR = ENV['DESTDIR'] - - @spec = quick_spec 'a' - - @builder = Gem::Ext::Builder.new @spec, '' end def teardown @@ -61,93 +56,5 @@ install: end end - def test_build_extensions_none - use_ui @ui do - @builder.build_extensions - end - - assert_equal '', @ui.output - assert_equal '', @ui.error - - refute File.exist?('gem_make.out') - end - - def test_build_extensions_extconf_bad - @spec.extensions << 'extconf.rb' - - e = assert_raises Gem::Installer::ExtensionBuildError do - use_ui @ui do - @builder.build_extensions - end - end - - assert_match(/\AERROR: Failed to build gem native extension.$/, e.message) - - assert_equal "Building native extensions. This could take a while...\n", - @ui.output - assert_equal '', @ui.error - - gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out' - - assert_match %r%#{Regexp.escape Gem.ruby} extconf\.rb%, - File.read(gem_make_out) - assert_match %r%#{Regexp.escape Gem.ruby}: No such file%, - File.read(gem_make_out) - end - - def test_build_extensions_unsupported - FileUtils.mkdir_p @spec.gem_dir - gem_make_out = File.join @spec.gem_dir, 'gem_make.out' - @spec.extensions << nil - - e = assert_raises Gem::Installer::ExtensionBuildError do - use_ui @ui do - @builder.build_extensions - end - end - - assert_match(/^\s*No builder for extension ''$/, e.message) - - assert_equal "Building native extensions. This could take a while...\n", - @ui.output - assert_equal '', @ui.error - - assert_equal "No builder for extension ''\n", File.read(gem_make_out) - ensure - FileUtils.rm_f gem_make_out - end - - def test_build_extensions_with_build_args - args = ["--aa", "--bb"] - @builder.build_args = args - @spec.extensions << 'extconf.rb' - - FileUtils.mkdir_p @spec.gem_dir - - open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f| - f.write <<-'RUBY' - puts "IN EXTCONF" - extconf_args = File.join File.dirname(__FILE__), 'extconf_args' - File.open extconf_args, 'w' do |f| - f.puts ARGV.inspect - end - - File.open 'Makefile', 'w' do |f| - f.puts "default:\n\techo built" - f.puts "install:\n\techo installed" - end - RUBY - end - - use_ui @ui do - @builder.build_extensions - end - - path = File.join @spec.gem_dir, "extconf_args" - - assert_equal args.inspect, File.read(path).strip - assert File.directory? File.join(@spec.gem_dir, 'lib') - end - end diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb index dfbf3fe1b9..33398ac6f3 100644 --- a/test/rubygems/test_gem_ext_ext_conf_builder.rb +++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb @@ -120,13 +120,8 @@ checking for main\(\) in .*?nonexistent/m, error.message) extconf.puts <<-'EXTCONF' include RbConfig -ruby = - if ENV['RUBY'] then - ENV['RUBY'] - else - ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}" - File.join CONFIG['bindir'], ruby_exe - end +ruby_exe = "#{CONFIG['RUBY_INSTALL_NAME']}#{CONFIG['EXEEXT']}" +ruby = File.join CONFIG['bindir'], ruby_exe open 'Makefile', 'w' do |io| io.write <<-Makefile diff --git a/test/rubygems/test_gem_gem_runner.rb b/test/rubygems/test_gem_gem_runner.rb index 85ff725345..6680a784c9 100644 --- a/test/rubygems/test_gem_gem_runner.rb +++ b/test/rubygems/test_gem_gem_runner.rb @@ -7,7 +7,6 @@ class TestGemGemRunner < Gem::TestCase super @orig_args = Gem::Command.build_args - @runner = Gem::GemRunner.new end def teardown @@ -42,26 +41,23 @@ class TestGemGemRunner < Gem::TestCase assert_equal %w[--commands], Gem::Command.extra_args end - def test_extract_build_args - args = %w[] - assert_equal [], @runner.extract_build_args(args) - assert_equal %w[], args + def test_build_args_are_handled + Gem.clear_paths + + cls = Class.new(Gem::Command) do + def execute + end + end - args = %w[foo] - assert_equal [], @runner.extract_build_args(args) - assert_equal %w[foo], args + test_obj = cls.new :ba_test - args = %w[--foo] - assert_equal [], @runner.extract_build_args(args) - assert_equal %w[--foo], args + cmds = Gem::CommandManager.new + cmds.register_command :ba_test, test_obj - args = %w[--foo --] - assert_equal [], @runner.extract_build_args(args) - assert_equal %w[--foo], args + runner = Gem::GemRunner.new :command_manager => cmds + runner.run(%W[ba_test -- --build_arg1 --build_arg2]) - args = %w[--foo -- --bar] - assert_equal %w[--bar], @runner.extract_build_args(args) - assert_equal %w[--foo], args + assert_equal %w[--build_arg1 --build_arg2], test_obj.options[:build_args] end end diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb index d70ac35beb..18b4518b06 100644 --- a/test/rubygems/test_gem_gemcutter_utilities.rb +++ b/test/rubygems/test_gem_gemcutter_utilities.rb @@ -101,7 +101,7 @@ class TestGemGemcutterUtilities < Gem::TestCase def test_sign_in_with_host api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' - util_sign_in [api_key, 200, 'OK'], 'http://example.com', ['http://example.com'] + util_sign_in [api_key, 200, 'OK'], 'http://example.com', :param assert_match "Enter your http://example.com credentials.", @sign_in_ui.output @@ -112,20 +112,6 @@ class TestGemGemcutterUtilities < Gem::TestCase assert_equal api_key, credentials[:rubygems_api_key] end - def test_sign_in_with_host_nil - api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' - - util_sign_in [api_key, 200, 'OK'], nil, [nil] - - assert_match "Enter your RubyGems.org credentials.", - @sign_in_ui.output - assert @fetcher.last_request["authorization"] - assert_match %r{Signed in.}, @sign_in_ui.output - - credentials = YAML.load_file Gem.configuration.credentials_path - assert_equal api_key, credentials[:rubygems_api_key] - end - def test_sign_in_with_host_ENV api_key = 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903' util_sign_in [api_key, 200, 'OK'], 'http://example.com' @@ -177,14 +163,14 @@ class TestGemGemcutterUtilities < Gem::TestCase assert_match %r{Access Denied.}, @sign_in_ui.output end - def util_sign_in response, host = nil, args = [] + def util_sign_in response, host = nil, style = :ENV skip 'Always uses $stdin on windows' if Gem.win_platform? email = '[email protected]' password = 'secret' if host - ENV['RUBYGEMS_HOST'] = host + ENV['RUBYGEMS_HOST'] = host if style == :ENV else host = Gem.host end @@ -196,8 +182,8 @@ class TestGemGemcutterUtilities < Gem::TestCase @sign_in_ui = Gem::MockGemUi.new "#{email}\n#{password}\n" use_ui @sign_in_ui do - if args.length > 0 then - @cmd.sign_in(*args) + if style == :param then + @cmd.sign_in host else @cmd.sign_in end @@ -223,3 +209,4 @@ class TestGemGemcutterUtilities < Gem::TestCase end end + diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 3f63896999..18d3569417 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -22,13 +22,12 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase --rdoc --ri -E + -P HighSecurity -f -i /install_to -w ] - args.concat %w[-P HighSecurity] if defined?(OpenSSL::SSL) - assert @cmd.handles?(args) end @@ -101,8 +100,6 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase end def test_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @cmd.handle_options %w[-P HighSecurity] assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy] diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 01b151c089..e513fe6da3 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -4,7 +4,6 @@ class TestGemInstaller < Gem::InstallerTestCase def setup super - common_installer_setup if __name__ =~ /^test_install(_|$)/ then FileUtils.rm_r @spec.gem_dir @@ -15,8 +14,6 @@ class TestGemInstaller < Gem::InstallerTestCase end def teardown - common_installer_teardown - super Gem.configuration = @config @@ -55,6 +52,95 @@ load Gem.bin_path('a', 'executable', version) assert_equal expected, wrapper end + def test_build_extensions_none + use_ui @ui do + @installer.build_extensions + end + + assert_equal '', @ui.output + assert_equal '', @ui.error + + refute File.exist?('gem_make.out') + end + + def test_build_extensions_extconf_bad + @installer.spec = @spec + @spec.extensions << 'extconf.rb' + + e = assert_raises Gem::Installer::ExtensionBuildError do + use_ui @ui do + @installer.build_extensions + end + end + + assert_match(/\AERROR: Failed to build gem native extension.$/, e.message) + + assert_equal "Building native extensions. This could take a while...\n", + @ui.output + assert_equal '', @ui.error + + gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out' + + assert_match %r%#{Regexp.escape Gem.ruby} extconf\.rb%, + File.read(gem_make_out) + assert_match %r%#{Regexp.escape Gem.ruby}: No such file%, + File.read(gem_make_out) + end + + def test_build_extensions_unsupported + @installer.spec = @spec + FileUtils.mkdir_p @spec.gem_dir + gem_make_out = File.join @spec.gem_dir, 'gem_make.out' + @spec.extensions << nil + + e = assert_raises Gem::Installer::ExtensionBuildError do + use_ui @ui do + @installer.build_extensions + end + end + + assert_match(/^\s*No builder for extension ''$/, e.message) + + assert_equal "Building native extensions. This could take a while...\n", + @ui.output + assert_equal '', @ui.error + + assert_equal "No builder for extension ''\n", File.read(gem_make_out) + ensure + FileUtils.rm_f gem_make_out + end + + def test_build_extensions_with_build_args + args = ["--aa", "--bb"] + @installer.build_args = args + @installer.spec = @spec + @spec.extensions << 'extconf.rb' + + File.open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f| + f.write <<-'RUBY' + puts "IN EXTCONF" + extconf_args = File.join File.dirname(__FILE__), 'extconf_args' + File.open extconf_args, 'w' do |f| + f.puts ARGV.inspect + end + + File.open 'Makefile', 'w' do |f| + f.puts "default:\n\techo built" + f.puts "install:\n\techo installed" + end + RUBY + end + + use_ui @ui do + @installer.build_extensions + end + + path = File.join @spec.gem_dir, "extconf_args" + + assert_equal args.inspect, File.read(path).strip + assert File.directory? File.join(@spec.gem_dir, 'lib') + end + def test_check_executable_overwrite @installer.generate_bin @@ -73,7 +159,7 @@ load Gem.bin_path('a', 'executable', version) @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -136,7 +222,7 @@ gem 'other', version @installer.generate_bin # should not raise installed_exec = File.join util_inst_bindir, 'foo-executable-bar' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -165,7 +251,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -178,7 +264,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec wrapper = File.read installed_exec assert_match %r|generated by RubyGems|, wrapper @@ -214,8 +300,6 @@ gem 'other', version end def test_ensure_loadable_spec_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - _, a_gem = util_gem 'a', 2 do |s| s.add_dependency 'garbage ~> 5' end @@ -252,7 +336,7 @@ gem 'other', version assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join(util_inst_bindir, 'executable') - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -287,7 +371,7 @@ gem 'other', version @installer.generate_bin assert File.directory? util_inst_bindir installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -304,7 +388,7 @@ gem 'other', version @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join util_inst_bindir, 'foo-executable-bar' - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil end @@ -318,7 +402,7 @@ gem 'other', version @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) ensure Gem::Installer.exec_format = nil end @@ -340,7 +424,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join("#{@gemhome}2", "bin", 'executable') - assert_path_exists installed_exec + assert File.exist? installed_exec assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -353,7 +437,7 @@ gem 'other', version @installer.wrappers = true @installer.generate_bin - refute_path_exists util_inst_bindir, 'bin dir was created when not needed' + refute File.exist?(util_inst_bindir), 'bin dir was created when not needed' end def test_generate_bin_script_no_perms @@ -389,7 +473,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join @gemhome, 'bin', 'executable' - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_equal mask, File.stat(installed_exec).mode unless win_platform? wrapper = File.read installed_exec @@ -414,7 +498,7 @@ gem 'other', version @installer.generate_bin assert_equal true, File.directory?(util_inst_bindir) - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_equal mask, File.stat(installed_exec).mode unless win_platform? assert_match %r|generated by RubyGems|, File.read(installed_exec) @@ -444,7 +528,7 @@ gem 'other', version @installer.wrappers = false @installer.generate_bin - refute_path_exists util_inst_bindir + refute File.exist?(util_inst_bindir) end def test_generate_bin_symlink_no_perms @@ -543,7 +627,7 @@ gem 'other', version @installer.generate_bin installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec + assert File.exist? installed_exec @spec = Gem::Specification.new do |s| s.files = ['lib/code.rb'] @@ -580,7 +664,7 @@ gem 'other', version assert_equal true, File.directory?(util_inst_bindir) installed_exec = File.join(util_inst_bindir, 'executable') - assert_path_exists installed_exec + assert_equal true, File.exist?(installed_exec) assert_match(/Unable to use symlinks on Windows, installing wrapper/i, @ui.error) @@ -647,19 +731,19 @@ gem 'other', version rakefile = File.join gemdir, 'ext', 'a', 'Rakefile' Gem.pre_install do |installer| - refute_path_exists cache_file, 'cache file must not exist yet' + refute File.exist?(cache_file), 'cache file must not exist yet' true end Gem.post_build do |installer| - assert_path_exists gemdir, 'gem install dir must exist' - assert_path_exists rakefile, 'gem executable must exist' - refute_path_exists stub_exe, 'gem executable must not exist' + assert File.exist?(gemdir), 'gem install dir must exist' + assert File.exist?(rakefile), 'gem executable must exist' + refute File.exist?(stub_exe), 'gem executable must not exist' true end Gem.post_install do |installer| - assert_path_exists cache_file, 'cache file must exist' + assert File.exist?(cache_file), 'cache file must exist' end @newspec = nil @@ -670,23 +754,23 @@ gem 'other', version end assert_equal @spec, @newspec - assert_path_exists gemdir - assert_path_exists stub_exe, 'gem executable must exist' + assert File.exist? gemdir + assert File.exist?(stub_exe), 'gem executable must exist' exe = File.join gemdir, 'bin', 'executable' - assert_path_exists exe + assert File.exist? exe exe_mode = File.stat(exe).mode & 0111 assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform? - assert_path_exists File.join gemdir, 'lib', 'code.rb' + assert File.exist?(File.join(gemdir, 'lib', 'code.rb')) - assert_path_exists rakefile + assert File.exist? rakefile spec_file = File.join(@gemhome, 'specifications', @spec.spec_name) assert_equal spec_file, @newspec.loaded_from - assert_path_exists spec_file + assert File.exist?(spec_file) assert_same @installer, @post_build_hook_arg assert_same @installer, @post_install_hook_arg @@ -795,7 +879,7 @@ gem 'other', version end gemdir = File.join(@gemhome, 'gems', @spec.full_name) - assert_path_exists File.join gemdir, 'lib', 'code.rb' + 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 @@ -814,9 +898,9 @@ gem 'other', version end end - assert_path_exists File.join gemdir, 'lib', 'other.rb' - refute_path_exists File.join gemdir, 'lib', 'code.rb', - "code.rb from prior install of same gem shouldn't remain here" + 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_force @@ -826,7 +910,7 @@ gem 'other', version end gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-1') - assert_path_exists gem_dir + assert File.exist?(gem_dir) end def test_install_missing_dirs @@ -842,8 +926,8 @@ gem 'other', version File.directory? File.join(Gem.dir, 'docs') File.directory? File.join(Gem.dir, 'specifications') - assert_path_exists File.join @gemhome, 'cache', @spec.file_name - assert_path_exists File.join @gemhome, 'specifications', @spec.spec_name + assert File.exist?(File.join(@gemhome, 'cache', @spec.file_name)) + assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name)) end def test_install_post_build_false @@ -864,10 +948,10 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - refute_path_exists spec_file + refute File.exist? spec_file gem_dir = File.join @gemhome, 'gems', @spec.full_name - refute_path_exists gem_dir + refute File.exist? gem_dir end def test_install_post_build_nil @@ -882,10 +966,10 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - assert_path_exists spec_file + assert File.exist? spec_file gem_dir = File.join @gemhome, 'gems', @spec.full_name - assert_path_exists gem_dir + assert File.exist? gem_dir end def test_install_pre_install_false @@ -906,7 +990,7 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - refute_path_exists spec_file + refute File.exist? spec_file end def test_install_pre_install_nil @@ -921,7 +1005,7 @@ gem 'other', version end spec_file = File.join @gemhome, 'specifications', @spec.spec_name - assert_path_exists spec_file + assert File.exist? spec_file end def test_install_with_message @@ -937,31 +1021,6 @@ gem 'other', version assert_match %r|I am a shiny gem!|, @ui.output end - def test_install_extension_install_dir - gemhome2 = "#{@gemhome}2" - - @spec.extensions << "extconf.rb" - write_file File.join(@tempdir, "extconf.rb") do |io| - io.write <<-RUBY - require "mkmf" - create_makefile("#{@spec.name}") - RUBY - end - - @spec.files += %w[extconf.rb] - - use_ui @ui do - path = Gem::Package.build @spec - - installer = Gem::Installer.new path, :install_dir => gemhome2 - installer.install - end - - expected_makefile = File.join gemhome2, 'gems', @spec.full_name, 'Makefile' - - assert_path_exists expected_makefile - end - def test_install_extension_and_script @spec.extensions << "extconf.rb" write_file File.join(@tempdir, "extconf.rb") do |io| @@ -988,16 +1047,16 @@ gem 'other', version RUBY end - refute_path_exists File.join @spec.gem_dir, rb - refute_path_exists File.join @spec.gem_dir, rb2 + assert !File.exist?(File.join(@spec.gem_dir, rb)) + assert !File.exist?(File.join(@spec.gem_dir, rb2)) use_ui @ui do path = Gem::Package.build @spec @installer = Gem::Installer.new path @installer.install end - assert_path_exists File.join @spec.gem_dir, rb - assert_path_exists File.join @spec.gem_dir, rb2 + assert File.exist?(File.join(@spec.gem_dir, rb)) + assert File.exist?(File.join(@spec.gem_dir, rb2)) end def test_install_extension_flat @@ -1026,14 +1085,14 @@ gem 'other', version } so = File.join(@spec.gem_dir, "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}") - refute_path_exists so + assert !File.exist?(so) use_ui @ui do path = Gem::Package.build @spec @installer = Gem::Installer.new path @installer.install end - assert_path_exists so + assert File.exist?(so) rescue puts '-' * 78 puts File.read File.join(@gemhome, 'gems', 'a-2', 'Makefile') @@ -1278,11 +1337,11 @@ gem 'other', version @installer.unpack dest - assert_path_exists File.join dest, 'lib', 'code.rb' - assert_path_exists File.join dest, 'bin', 'executable' + assert File.exist?(File.join(dest, 'lib', 'code.rb')) + assert File.exist?(File.join(dest, 'bin', 'executable')) end - def test_write_build_info_file + def test_write_build_args refute_path_exists @spec.build_info_file @installer.build_args = %w[ @@ -1298,7 +1357,7 @@ gem 'other', version assert_equal expected, File.read(@spec.build_info_file) end - def test_write_build_info_file_empty + def test_write_build_args_empty refute_path_exists @spec.build_info_file @installer.write_build_info_file @@ -1338,20 +1397,20 @@ gem 'other', version def test_write_spec FileUtils.rm @spec.spec_file - refute_path_exists @spec.spec_file + refute File.exist?(@spec.spec_file) @installer.spec = @spec @installer.gem_home = @gemhome @installer.write_spec - assert_path_exists @spec.spec_file + assert File.exist?(@spec.spec_file) assert_equal @spec, eval(File.read(@spec.spec_file)) end def test_write_spec_writes_cached_spec FileUtils.rm @spec.spec_file - refute_path_exists @spec.spec_file + refute File.exist?(@spec.spec_file) @spec.files = %w[a.rb b.rb c.rb] @@ -1370,30 +1429,6 @@ gem 'other', version assert_match %r!/gemhome/gems/a-2$!, @installer.dir end - def test_default_gem - FileUtils.rm_f File.join(Gem.dir, 'specifications') - - @installer.wrappers = true - @installer.options[:install_as_default] = true - @installer.gem_dir = util_gem_dir @spec - @installer.generate_bin - - use_ui @ui do - @installer.install - end - - assert File.directory? util_inst_bindir - installed_exec = File.join util_inst_bindir, 'executable' - assert_path_exists installed_exec - - assert File.directory? File.join(Gem.dir, 'specifications') - assert File.directory? File.join(Gem.dir, 'specifications', 'default') - - default_spec = eval File.read File.join(Gem.dir, 'specifications', 'default', 'a-2.gemspec') - assert_equal Gem::Version.new("2"), default_spec.version - assert_equal ['bin/executable'], default_spec.files - end - def old_ruby_required spec = quick_spec 'old_ruby_required', '1' do |s| s.required_ruby_version = '= 1.4.6' diff --git a/test/rubygems/test_gem_name_tuple.rb b/test/rubygems/test_gem_name_tuple.rb index 170a9c2ae0..62b4801f71 100644 --- a/test/rubygems/test_gem_name_tuple.rb +++ b/test/rubygems/test_gem_name_tuple.rb @@ -2,21 +2,6 @@ require 'rubygems/test_case' require 'rubygems/name_tuple' class TestGemNameTuple < Gem::TestCase - - def test_full_name - n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby" - assert_equal "a-0", n.full_name - - n = Gem::NameTuple.new "a", Gem::Version.new(0), nil - assert_equal "a-0", n.full_name - - n = Gem::NameTuple.new "a", Gem::Version.new(0), "" - assert_equal "a-0", n.full_name - - n = Gem::NameTuple.new "a", Gem::Version.new(0), "other" - assert_equal "a-0-other", n.full_name - end - def test_platform_normalization n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby" assert_equal "ruby", n.platform @@ -27,11 +12,4 @@ class TestGemNameTuple < Gem::TestCase n = Gem::NameTuple.new "a", Gem::Version.new(0), "" assert_equal "ruby", n.platform end - - def test_spec_name - n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby" - assert_equal "a-0.gemspec", n.spec_name - end - end - diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index af5319a150..c77fc47ada 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -87,19 +87,16 @@ class TestGemPackage < Gem::Package::TarTestCase metadata_sha512 = Digest::SHA512.hexdigest s.string expected = { + 'SHA1' => { + 'metadata.gz' => metadata_sha1, + 'data.tar.gz' => Digest::SHA1.hexdigest(tar), + }, 'SHA512' => { 'metadata.gz' => metadata_sha512, 'data.tar.gz' => Digest::SHA512.hexdigest(tar), } } - if defined?(OpenSSL::Digest) then - expected['SHA1'] = { - 'metadata.gz' => metadata_sha1, - 'data.tar.gz' => Digest::SHA1.hexdigest(tar), - } - end - assert_equal expected, YAML.load(checksums) end @@ -163,57 +160,12 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_auto_signed - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - FileUtils.mkdir_p File.join(Gem.user_home, '.gem') private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem' Gem::Security.write PRIVATE_KEY, private_key_path public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' - FileUtils.cp PUBLIC_CERT_PATH, public_cert_path - - spec = Gem::Specification.new 'build', '1' - spec.summary = 'build' - spec.authors = 'build' - spec.files = ['lib/code.rb'] - - FileUtils.mkdir 'lib' - - open 'lib/code.rb', 'w' do |io| - io.write '# lib/code.rb' - end - - package = Gem::Package.new spec.file_name - package.spec = spec - - package.build - - assert_equal Gem::VERSION, spec.rubygems_version - assert_path_exists spec.file_name - - reader = Gem::Package.new spec.file_name - assert reader.verify - - assert_equal [PUBLIC_CERT.to_pem], reader.spec.cert_chain - - assert_equal %w[metadata.gz metadata.gz.sig - data.tar.gz data.tar.gz.sig - checksums.yaml.gz checksums.yaml.gz.sig], - reader.files - - assert_equal %w[lib/code.rb], reader.contents - end - - def test_build_auto_signed_encrypted_key - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - - FileUtils.mkdir_p File.join(Gem.user_home, '.gem') - - private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem' - FileUtils.cp ENCRYPTED_PRIVATE_KEY_PATH, private_key_path - - public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' Gem::Security.write PUBLIC_CERT, public_cert_path spec = Gem::Specification.new 'build', '1' @@ -262,8 +214,6 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_signed - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - spec = Gem::Specification.new 'build', '1' spec.summary = 'build' spec.authors = 'build' @@ -298,43 +248,6 @@ class TestGemPackage < Gem::Package::TarTestCase assert_equal %w[lib/code.rb], reader.contents end - def test_build_signed_encryped_key - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - - spec = Gem::Specification.new 'build', '1' - spec.summary = 'build' - spec.authors = 'build' - spec.files = ['lib/code.rb'] - spec.cert_chain = [PUBLIC_CERT.to_pem] - spec.signing_key = ENCRYPTED_PRIVATE_KEY - - FileUtils.mkdir 'lib' - - open 'lib/code.rb', 'w' do |io| - io.write '# lib/code.rb' - end - - package = Gem::Package.new spec.file_name - package.spec = spec - - package.build - - assert_equal Gem::VERSION, spec.rubygems_version - assert_path_exists spec.file_name - - reader = Gem::Package.new spec.file_name - assert reader.verify - - assert_equal spec, reader.spec - - assert_equal %w[metadata.gz metadata.gz.sig - data.tar.gz data.tar.gz.sig - checksums.yaml.gz checksums.yaml.gz.sig], - reader.files - - assert_equal %w[lib/code.rb], reader.contents - end - def test_contents package = Gem::Package.new @gem @@ -396,19 +309,6 @@ class TestGemPackage < Gem::Package::TarTestCase "#{@destination} is not allowed", e.message) end - def test_extract_tar_gz_dot_slash - package = Gem::Package.new @gem - - tgz_io = util_tar_gz do |tar| - tar.add_file './dot_slash.rb', 0644 do |io| io.write 'hi' end - end - - package.extract_tar_gz tgz_io, @destination - - extracted = File.join @destination, 'dot_slash.rb' - assert_path_exists extracted - end - def test_install_location package = Gem::Package.new @gem @@ -544,7 +444,7 @@ class TestGemPackage < Gem::Package::TarTestCase io.write metadata_gz end - digest = Digest::SHA1.new + digest = OpenSSL::Digest::SHA1.new digest << metadata_gz checksums = { @@ -576,8 +476,7 @@ class TestGemPackage < Gem::Package::TarTestCase def test_verify_corrupt Tempfile.open 'corrupt' do |io| data = Gem.gzip 'a' * 10 - io.write \ - tar_file_header('metadata.gz', "\000x", 0644, data.length, Time.now) + io.write tar_file_header('metadata.gz', "\000x", 0644, data.length) io.write data io.rewind @@ -616,8 +515,6 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - package = Gem::Package.new @gem package.security_policy = Gem::Security::HighSecurity @@ -633,8 +530,6 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy_low_security - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @spec.cert_chain = [PUBLIC_CERT.to_pem] @spec.signing_key = PRIVATE_KEY @@ -653,8 +548,6 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy_checksum_missing - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @spec.cert_chain = [PUBLIC_CERT.to_pem] @spec.signing_key = PRIVATE_KEY @@ -710,21 +603,6 @@ class TestGemPackage < Gem::Package::TarTestCase e.message end - # end #verify tests - - def test_verify_entry - entry = Object.new - def entry.full_name() raise ArgumentError, 'whatever' end - - package = Gem::Package.new @gem - - e = assert_raises Gem::Package::FormatError do - package.verify_entry entry - end - - assert_equal "package is corrupt, exception while verifying: whatever (ArgumentError) in #{@gem}", e.message - end - def test_spec package = Gem::Package.new @gem diff --git a/test/rubygems/test_gem_package_old.rb b/test/rubygems/test_gem_package_old.rb index 6236dbbaf2..05f7ae3dec 100644 --- a/test/rubygems/test_gem_package_old.rb +++ b/test/rubygems/test_gem_package_old.rb @@ -21,8 +21,6 @@ class TestGemPackageOld < Gem::TestCase end def test_contents_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @package.security_policy = Gem::Security::AlmostNoSecurity assert_raises Gem::Security::Exception do @@ -42,8 +40,6 @@ class TestGemPackageOld < Gem::TestCase end def test_extract_files_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @package.security_policy = Gem::Security::AlmostNoSecurity assert_raises Gem::Security::Exception do @@ -56,8 +52,6 @@ class TestGemPackageOld < Gem::TestCase end def test_spec_security_policy - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - @package.security_policy = Gem::Security::AlmostNoSecurity assert_raises Gem::Security::Exception do @@ -66,8 +60,6 @@ class TestGemPackageOld < Gem::TestCase end def test_verify - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - assert @package.verify @package.security_policy = Gem::Security::NoSecurity diff --git a/test/rubygems/test_gem_package_tar_reader.rb b/test/rubygems/test_gem_package_tar_reader.rb index 5e0474c253..d1af22d3be 100644 --- a/test/rubygems/test_gem_package_tar_reader.rb +++ b/test/rubygems/test_gem_package_tar_reader.rb @@ -4,8 +4,8 @@ require 'rubygems/package' class TestGemPackageTarReader < Gem::Package::TarTestCase def test_each_entry - tar = tar_dir_header "foo", "bar", 0, Time.now - tar << tar_file_header("bar", "baz", 0, 0, Time.now) + tar = tar_dir_header "foo", "bar", 0 + tar << tar_file_header("bar", "baz", 0, 0) io = TempIO.new tar @@ -25,9 +25,8 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase def test_rewind content = ('a'..'z').to_a.join(" ") - str = - tar_file_header("lib/foo", "", 010644, content.size, Time.now) + - content + "\0" * (512 - content.size) + str = tar_file_header("lib/foo", "", 010644, content.size) + content + + "\0" * (512 - content.size) str << "\0" * 1024 Gem::Package::TarReader.new(TempIO.new(str)) do |tar_reader| @@ -44,8 +43,8 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase end def test_seek - tar = tar_dir_header "foo", "bar", 0, Time.now - tar << tar_file_header("bar", "baz", 0, 0, Time.now) + tar = tar_dir_header "foo", "bar", 0 + tar << tar_file_header("bar", "baz", 0, 0) io = TempIO.new tar @@ -61,8 +60,8 @@ class TestGemPackageTarReader < Gem::Package::TarTestCase end def test_seek_missing - tar = tar_dir_header "foo", "bar", 0, Time.now - tar << tar_file_header("bar", "baz", 0, 0, Time.now) + tar = tar_dir_header "foo", "bar", 0 + tar << tar_file_header("bar", "baz", 0, 0) io = TempIO.new tar diff --git a/test/rubygems/test_gem_package_tar_reader_entry.rb b/test/rubygems/test_gem_package_tar_reader_entry.rb index 3c1bf7291a..92da220fa6 100644 --- a/test/rubygems/test_gem_package_tar_reader_entry.rb +++ b/test/rubygems/test_gem_package_tar_reader_entry.rb @@ -9,7 +9,7 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase @contents = ('a'..'z').to_a.join * 100 @tar = '' - @tar << tar_file_header("lib/foo", "", 0, @contents.size, Time.now) + @tar << tar_file_header("lib/foo", "", 0, @contents.size) @tar << @contents @tar << "\0" * (512 - (@tar.size % 512)) diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb index 2505d7ced1..40c6982929 100644 --- a/test/rubygems/test_gem_package_tar_writer.rb +++ b/test/rubygems/test_gem_package_tar_writer.rb @@ -1,6 +1,5 @@ require 'rubygems/package/tar_test_case' require 'rubygems/package/tar_writer' -require 'minitest/mock' class TestGemPackageTarWriter < Gem::Package::TarTestCase @@ -19,130 +18,112 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase end def test_add_file - Time.stub :now, Time.at(1458518157) do - @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end + @tar_writer.add_file 'x', 0644 do |f| f.write 'a' * 10 end - assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), + assert_headers_equal(tar_file_header('x', '', 0644, 10), @io.string[0, 512]) - end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] assert_equal 1024, @io.pos end def test_add_file_digest - digest_algorithms = Digest::SHA1, Digest::SHA512 + digest_algorithms = OpenSSL::Digest::SHA1, OpenSSL::Digest::SHA512 - Time.stub :now, Time.at(1458518157) do - digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io| - io.write 'a' * 10 - end + digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io| + io.write 'a' * 10 + end - assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a', - digests['SHA1'].hexdigest - assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \ - '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \ - '4993d6b40a4e4d8424196afc347e97640d68de61' \ - 'e1cf14b0', - digests['SHA512'].hexdigest + assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a', + digests['SHA1'].hexdigest + assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \ + '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \ + '4993d6b40a4e4d8424196afc347e97640d68de61' \ + 'e1cf14b0', + digests['SHA512'].hexdigest - assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), + assert_headers_equal(tar_file_header('x', '', 0644, 10), @io.string[0, 512]) - end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] assert_equal 1024, @io.pos end def test_add_file_digest_multiple - digest_algorithms = [Digest::SHA1, Digest::SHA512] + digest_algorithms = [OpenSSL::Digest::SHA1, OpenSSL::Digest::SHA512] - Time.stub :now, Time.at(1458518157) do - digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io| - io.write 'a' * 10 - end + digests = @tar_writer.add_file_digest 'x', 0644, digest_algorithms do |io| + io.write 'a' * 10 + end - assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a', - digests['SHA1'].hexdigest - assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \ - '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \ - '4993d6b40a4e4d8424196afc347e97640d68de61' \ - 'e1cf14b0', - digests['SHA512'].hexdigest + assert_equal '3495ff69d34671d1e15b33a63c1379fdedd3a32a', + digests['SHA1'].hexdigest + assert_equal '4714870aff6c97ca09d135834fdb58a6389a50c1' \ + '1fef8ec4afef466fb60a23ac6b7a9c92658f14df' \ + '4993d6b40a4e4d8424196afc347e97640d68de61' \ + 'e1cf14b0', + digests['SHA512'].hexdigest - assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), - @io.string[0, 512]) - end + assert_headers_equal(tar_file_header('x', '', 0644, 10), + @io.string[0, 512]) assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] assert_equal 1024, @io.pos end def test_add_file_signer - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT] - Time.stub :now, Time.at(1458518157) do - @tar_writer.add_file_signed 'x', 0644, signer do |io| - io.write 'a' * 10 - end - - assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), - @io.string[0, 512]) - - - assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] + @tar_writer.add_file_signed 'x', 0644, signer do |io| + io.write 'a' * 10 + end - digest = signer.digest_algorithm.new - digest.update 'a' * 10 + assert_headers_equal(tar_file_header('x', '', 0644, 10), + @io.string[0, 512]) + assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] - signature = signer.sign digest.digest + digest = signer.digest_algorithm.new + digest.update 'a' * 10 - assert_headers_equal(tar_file_header('x.sig', '', 0444, signature.length, - Time.now), - @io.string[1024, 512]) - assert_equal "#{signature}#{"\0" * (512 - signature.length)}", - @io.string[1536, 512] + signature = signer.sign digest.digest - assert_equal 2048, @io.pos - end + assert_headers_equal(tar_file_header('x.sig', '', 0444, signature.length), + @io.string[1024, 512]) + assert_equal "#{signature}#{"\0" * (512 - signature.length)}", + @io.string[1536, 512] + assert_equal 2048, @io.pos end def test_add_file_signer_empty signer = Gem::Security::Signer.new nil, nil - Time.stub :now, Time.at(1458518157) do - - @tar_writer.add_file_signed 'x', 0644, signer do |io| - io.write 'a' * 10 - end + @tar_writer.add_file_signed 'x', 0644, signer do |io| + io.write 'a' * 10 + end - assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), + assert_headers_equal(tar_file_header('x', '', 0644, 10), @io.string[0, 512]) - end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] + digest = signer.digest_algorithm.new + digest.update 'a' * 10 + assert_equal 1024, @io.pos end def test_add_file_simple - Time.stub :now, Time.at(1458518157) do - @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end + @tar_writer.add_file_simple 'x', 0644, 10 do |io| io.write "a" * 10 end - assert_headers_equal(tar_file_header('x', '', 0644, 10, Time.now), + assert_headers_equal(tar_file_header('x', '', 0644, 10), @io.string[0, 512]) - end assert_equal "aaaaaaaaaa#{"\0" * 502}", @io.string[512, 512] assert_equal 1024, @io.pos end def test_add_file_simple_padding - Time.stub :now, Time.at(1458518157) do - @tar_writer.add_file_simple 'x', 0, 100 + @tar_writer.add_file_simple 'x', 0, 100 - assert_headers_equal tar_file_header('x', '', 0, 100, Time.now), + assert_headers_equal tar_file_header('x', '', 0, 100), @io.string[0, 512] - end assert_equal "\0" * 512, @io.string[512, 512] end @@ -201,14 +182,11 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase end def test_mkdir - Time.stub :now, Time.at(1458518157) do - @tar_writer.mkdir 'foo', 0644 + @tar_writer.mkdir 'foo', 0644 - assert_headers_equal tar_dir_header('foo', '', 0644, Time.now), - @io.string[0, 512] - - assert_equal 512, @io.pos - end + assert_headers_equal tar_dir_header('foo', '', 0644), + @io.string[0, 512] + assert_equal 512, @io.pos end def test_split_name diff --git a/test/rubygems/test_gem_path_support.rb b/test/rubygems/test_gem_path_support.rb index 879cc98b5f..bffc66f7dc 100644 --- a/test/rubygems/test_gem_path_support.rb +++ b/test/rubygems/test_gem_path_support.rb @@ -64,21 +64,4 @@ class TestGemPathSupport < Gem::TestCase def util_path ENV["GEM_PATH"].split(File::PATH_SEPARATOR) end - - def test_initialize_spec - ENV["GEM_SPEC_CACHE"] = nil - - ps = Gem::PathSupport.new - assert_equal Gem.default_spec_cache_dir, ps.spec_cache_dir - - ENV["GEM_SPEC_CACHE"] = 'bar' - - ps = Gem::PathSupport.new - assert_equal ENV["GEM_SPEC_CACHE"], ps.spec_cache_dir - - ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache' - - ps = Gem::PathSupport.new "GEM_SPEC_CACHE" => "foo" - assert_equal "foo", ps.spec_cache_dir - end end diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index 5966710dad..1112a013f5 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -186,24 +186,6 @@ class TestGemPlatform < Gem::TestCase assert((x86_darwin8 === Gem::Platform.local), 'universal =~ x86') end - def test_equals3_cpu_arm - arm = Gem::Platform.new 'arm-linux' - armv5 = Gem::Platform.new 'armv5-linux' - armv7 = Gem::Platform.new 'armv7-linux' - - util_set_arch 'armv5-linux' - assert((arm === Gem::Platform.local), 'arm === armv5') - assert((armv5 === Gem::Platform.local), 'armv5 === armv5') - refute((armv7 === Gem::Platform.local), 'armv7 === armv5') - refute((Gem::Platform.local === arm), 'armv5 === arm') - - util_set_arch 'armv7-linux' - assert((arm === Gem::Platform.local), 'arm === armv7') - refute((armv5 === Gem::Platform.local), 'armv5 === armv7') - assert((armv7 === Gem::Platform.local), 'armv7 === armv7') - refute((Gem::Platform.local === arm), 'armv7 === arm') - end - def test_equals3_version util_set_arch 'i686-darwin8' diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index fe6da708b6..d3cc388db4 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -1,13 +1,7 @@ require 'rubygems/test_case' - +require 'ostruct' require 'webrick' -begin - require 'webrick/https' -rescue LoadError => e - raise unless (e.respond_to?(:path) && e.path == 'openssl') || - e.message =~ / -- openssl$/ -end - +require 'webrick/https' require 'rubygems/remote_fetcher' require 'rubygems/package' require 'minitest/mock' @@ -134,7 +128,19 @@ gems: refute_nil fetcher assert_kind_of Gem::RemoteFetcher, fetcher - assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy).to_s + assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri).to_s + end + + def test_self_fetcher_with_proxy_URI + proxy_uri = URI.parse 'http://proxy.example.com' + Gem.configuration[:http_proxy] = proxy_uri + Gem::RemoteFetcher.fetcher = nil + + fetcher = Gem::RemoteFetcher.fetcher + refute_nil fetcher + + assert_kind_of Gem::RemoteFetcher, fetcher + assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy_uri) end def test_fetch_size_bad_uri @@ -149,7 +155,7 @@ gems: def test_fetch_size_socket_error fetcher = Gem::RemoteFetcher.new nil - def fetcher.request(uri, request_class, last_modified = nil) + def fetcher.connection_for(uri) raise SocketError, "tarded" end @@ -408,6 +414,70 @@ gems: assert_equal @a2.file_name, File.basename(gem) end + def test_explicit_proxy + use_ui @ui do + fetcher = Gem::RemoteFetcher.new @proxy_uri + assert_equal PROXY_DATA.size, fetcher.fetch_size(@server_uri) + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + end + + def test_explicit_proxy_with_user_auth + use_ui @ui do + uri = URI.parse @proxy_uri + uri.user, uri.password = 'foo', 'bar' + fetcher = Gem::RemoteFetcher.new uri.to_s + proxy = fetcher.instance_variable_get("@proxy_uri") + assert_equal 'foo', proxy.user + assert_equal 'bar', proxy.password + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + + use_ui @ui do + uri = URI.parse @proxy_uri + uri.user, uri.password = 'domain%5Cuser', 'bar' + fetcher = Gem::RemoteFetcher.new uri.to_s + proxy = fetcher.instance_variable_get("@proxy_uri") + assert_equal 'domain\user', fetcher.unescape(proxy.user) + assert_equal 'bar', proxy.password + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + + use_ui @ui do + uri = URI.parse @proxy_uri + uri.user, uri.password = 'user', 'my%20pass' + fetcher = Gem::RemoteFetcher.new uri.to_s + proxy = fetcher.instance_variable_get("@proxy_uri") + assert_equal 'user', proxy.user + assert_equal 'my pass', fetcher.unescape(proxy.password) + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + end + + def test_explicit_proxy_with_user_auth_in_env + use_ui @ui do + ENV['http_proxy'] = @proxy_uri + ENV['http_proxy_user'] = 'foo' + ENV['http_proxy_pass'] = 'bar' + fetcher = Gem::RemoteFetcher.new nil + proxy = fetcher.instance_variable_get("@proxy_uri") + assert_equal 'foo', proxy.user + assert_equal 'bar', proxy.password + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + + use_ui @ui do + ENV['http_proxy'] = @proxy_uri + ENV['http_proxy_user'] = 'foo\user' + ENV['http_proxy_pass'] = 'my bar' + fetcher = Gem::RemoteFetcher.new nil + proxy = fetcher.instance_variable_get("@proxy_uri") + assert_equal 'foo\user', fetcher.unescape(proxy.user) + assert_equal 'my bar', fetcher.unescape(proxy.password) + assert_data_from_proxy fetcher.fetch_path(@server_uri) + end + end + def test_fetch_path_gzip fetcher = Gem::RemoteFetcher.new nil @@ -490,6 +560,22 @@ gems: assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0)) end + def test_get_proxy_from_env_auto_normalizes + fetcher = Gem::RemoteFetcher.new(nil) + ENV['HTTP_PROXY'] = 'fakeurl:12345' + + assert_equal('http://fakeurl:12345', fetcher.get_proxy_from_env.to_s) + end + + def test_get_proxy_from_env_empty + ENV['HTTP_PROXY'] = '' + ENV.delete 'http_proxy' + + fetcher = Gem::RemoteFetcher.new nil + + assert_equal nil, fetcher.send(:get_proxy_from_env) + end + def test_implicit_no_proxy use_ui @ui do ENV['http_proxy'] = 'http://fakeurl:12345' @@ -525,7 +611,9 @@ gems: fetcher = Gem::RemoteFetcher.new nil url = 'http://gems.example.com/redirect' - def fetcher.request(uri, request_class, last_modified = nil) + conn = Object.new + def conn.started?() true end + def conn.request(req) url = 'http://gems.example.com/redirect' unless defined? @requested then @requested = true @@ -539,6 +627,9 @@ gems: end end + conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn } + fetcher.instance_variable_set :@connections, conn + data = fetcher.fetch_http URI.parse(url) assert_equal 'real_path', data @@ -548,13 +639,18 @@ gems: fetcher = Gem::RemoteFetcher.new nil url = 'http://gems.example.com/redirect' - def fetcher.request(uri, request_class, last_modified = nil) + conn = Object.new + def conn.started?() true end + def conn.request(req) url = 'http://gems.example.com/redirect' res = Net::HTTPMovedPermanently.new nil, 301, nil res.add_field 'Location', url res end + conn = { "#{Thread.current.object_id}:gems.example.com:80" => conn } + fetcher.instance_variable_set :@connections, conn + e = assert_raises Gem::RemoteFetcher::FetchError do fetcher.fetch_http URI.parse(url) end @@ -562,6 +658,14 @@ gems: assert_equal "too many redirects (#{url})", e.message end + def test_normalize_uri + assert_equal 'FILE://example/', @fetcher.normalize_uri('FILE://example/') + assert_equal 'FTP://example/', @fetcher.normalize_uri('FTP://example/') + assert_equal 'HTTP://example/', @fetcher.normalize_uri('HTTP://example/') + assert_equal 'HTTPS://example/', @fetcher.normalize_uri('HTTPS://example/') + assert_equal 'http://example/', @fetcher.normalize_uri('example/') + end + def test_observe_no_proxy_env_single_host use_ui @ui do ENV["http_proxy"] = @proxy_uri @@ -580,15 +684,115 @@ gems: end end - def test_request_block - fetcher = Gem::RemoteFetcher.new nil + def test_request + uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" + util_stub_connection_for :body => :junk, :code => 200 - assert_throws :block_called do - fetcher.request URI('http://example'), Net::HTTP::Get do |req| - assert_kind_of Net::HTTPGenericRequest, req - throw :block_called - end - end + response = @fetcher.request uri, Net::HTTP::Get + + assert_equal 200, response.code + assert_equal :junk, response.body + end + + def test_request_head + uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" + util_stub_connection_for :body => '', :code => 200 + response = @fetcher.request uri, Net::HTTP::Head + + assert_equal 200, response.code + assert_equal '', response.body + end + + def test_request_unmodified + uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}" + conn = util_stub_connection_for :body => '', :code => 304 + + t = Time.now + response = @fetcher.request uri, Net::HTTP::Head, t + + assert_equal 304, response.code + assert_equal '', response.body + + assert_equal t.rfc2822, conn.payload['if-modified-since'] + end + + def test_user_agent + ua = @fetcher.user_agent + + assert_match %r%^RubyGems/\S+ \S+ Ruby/\S+ \(.*?\)%, ua + assert_match %r%RubyGems/#{Regexp.escape Gem::VERSION}%, ua + assert_match %r% #{Regexp.escape Gem::Platform.local.to_s} %, ua + assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}%, ua + assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE} %, ua + end + + def test_user_agent_engine + util_save_version + + Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE) + Object.send :const_set, :RUBY_ENGINE, 'vroom' + + ua = @fetcher.user_agent + + assert_match %r%\) vroom%, ua + ensure + util_restore_version + end + + def test_user_agent_engine_ruby + util_save_version + + Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE) + Object.send :const_set, :RUBY_ENGINE, 'ruby' + + ua = @fetcher.user_agent + + assert_match %r%\)%, ua + ensure + util_restore_version + end + + def test_user_agent_patchlevel + util_save_version + + Object.send :remove_const, :RUBY_PATCHLEVEL + Object.send :const_set, :RUBY_PATCHLEVEL, 5 + + ua = @fetcher.user_agent + + assert_match %r% patchlevel 5\)%, ua + ensure + util_restore_version + end + + def test_user_agent_revision + util_save_version + + Object.send :remove_const, :RUBY_PATCHLEVEL + Object.send :const_set, :RUBY_PATCHLEVEL, -1 + Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + Object.send :const_set, :RUBY_REVISION, 6 + + ua = @fetcher.user_agent + + assert_match %r% revision 6\)%, ua + assert_match %r%Ruby/#{Regexp.escape RUBY_VERSION}dev%, ua + ensure + util_restore_version + end + + def test_user_agent_revision_missing + util_save_version + + Object.send :remove_const, :RUBY_PATCHLEVEL + Object.send :const_set, :RUBY_PATCHLEVEL, -1 + Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + + ua = @fetcher.user_agent + + assert_match %r%\(#{Regexp.escape RUBY_RELEASE_DATE}\)%, ua + ensure + util_restore_version end def test_yaml_error_on_size @@ -607,42 +811,6 @@ gems: end end - def test_ssl_client_cert_auth_connection - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - - ssl_server = self.class.start_ssl_server({ - :SSLVerifyClient => - OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT}) - - temp_ca_cert = File.join(DIR, 'ca_cert.pem') - temp_client_cert = File.join(DIR, 'client.pem') - - with_configured_fetcher( - ":ssl_ca_cert: #{temp_ca_cert}\n" + - ":ssl_client_cert: #{temp_client_cert}\n") do |fetcher| - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end - end - - def test_do_not_allow_invalid_client_cert_auth_connection - skip 'openssl is missing' unless defined?(OpenSSL::SSL) - - ssl_server = self.class.start_ssl_server({ - :SSLVerifyClient => - OpenSSL::SSL::VERIFY_PEER|OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT}) - - temp_ca_cert = File.join(DIR, 'ca_cert.pem') - temp_client_cert = File.join(DIR, 'invalid_client.pem') - - with_configured_fetcher( - ":ssl_ca_cert: #{temp_ca_cert}\n" + - ":ssl_client_cert: #{temp_client_cert}\n") do |fetcher| - assert_raises Gem::RemoteFetcher::FetchError do - fetcher.fetch_path("https://localhost:#{ssl_server.config[:Port]}/yaml") - end - end - end - def test_do_not_allow_insecure_ssl_connection_by_default ssl_server = self.class.start_ssl_server with_configured_fetcher do |fetcher| @@ -682,6 +850,18 @@ gems: Gem.configuration = nil end + def util_stub_connection_for hash + def @fetcher.connection= conn + @conn = conn + end + + def @fetcher.connection_for uri + @conn + end + + @fetcher.connection = Conn.new OpenStruct.new(hash) + end + def assert_error(exception_class=Exception) got_exception = false @@ -702,6 +882,20 @@ gems: assert_match(/0\.4\.2/, data, "Data is not from proxy") end + class Conn + attr_accessor :payload + + def initialize(response) + @response = response + self.payload = nil + end + + def request(req) + self.payload = req + @response + end + end + class NilLog < WEBrick::Log def log(level, data) #Do nothing end @@ -719,11 +913,9 @@ gems: end DIR = File.expand_path(File.dirname(__FILE__)) + DH_PARAM = OpenSSL::PKey::DH.new(128) def start_ssl_server(config = {}) - raise MiniTest::Skip, 'openssl not installed' unless - defined?(OpenSSL::SSL) - null_logger = NilLog.new server = WEBrick::HTTPServer.new({ :Port => 0, @@ -742,7 +934,7 @@ gems: server.mount_proc("/insecure_redirect") { |req, res| res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, req.query['to']) } - server.ssl_context.tmp_dh_callback = proc { OpenSSL::PKey::DH.new 128 } + server.ssl_context.tmp_dh_callback = proc { DH_PARAM } t = Thread.new do begin server.start @@ -761,6 +953,8 @@ gems: server end + + private def start_server(port, data) @@ -821,5 +1015,24 @@ gems: assert_equal "/home/skillet", @fetcher.correct_for_windows_path(path) end + def util_save_version + @orig_RUBY_ENGINE = RUBY_ENGINE if defined? RUBY_ENGINE + @orig_RUBY_PATCHLEVEL = RUBY_PATCHLEVEL + @orig_RUBY_REVISION = RUBY_REVISION if defined? RUBY_REVISION + end + + def util_restore_version + Object.send :remove_const, :RUBY_ENGINE if defined?(RUBY_ENGINE) + Object.send :const_set, :RUBY_ENGINE, @orig_RUBY_ENGINE if + defined?(@orig_RUBY_ENGINE) + + Object.send :remove_const, :RUBY_PATCHLEVEL + Object.send :const_set, :RUBY_PATCHLEVEL, @orig_RUBY_PATCHLEVEL + + Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION) + Object.send :const_set, :RUBY_REVISION, @orig_RUBY_REVISION if + defined?(@orig_RUBY_REVISION) + end + end diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb index b8747b79c3..737881d7bc 100644 --- a/test/rubygems/test_gem_security.rb +++ b/test/rubygems/test_gem_security.rb @@ -2,10 +2,6 @@ require 'rubygems/test_case' require 'rubygems/security' require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9" -unless defined?(OpenSSL::SSL) then - warn 'Skipping Gem::Security tests. openssl not found.' -end - class TestGemSecurity < Gem::TestCase CHILD_KEY = load_key 'child' @@ -99,7 +95,7 @@ class TestGemSecurity < Gem::TestCase end def test_class_create_key - key = @SEC.create_key 1024 + key = @SEC.create_key 256 assert_kind_of OpenSSL::PKey::RSA, key end @@ -250,57 +246,5 @@ class TestGemSecurity < Gem::TestCase assert_equal expected, trust_dir.dir end - def test_class_write - key = @SEC.create_key 1024 - - path = File.join @tempdir, 'test-private_key.pem' - - @SEC.write key, path - - assert_path_exists path - - key_from_file = File.read path - - assert_equal key.to_pem, key_from_file - end - - def test_class_write_encrypted - key = @SEC.create_key 1024 - - path = File.join @tempdir, 'test-private_encrypted_key.pem' - - passphrase = 'It should be long.' - - @SEC.write key, path, 0600, passphrase - - assert_path_exists path - - key_from_file = OpenSSL::PKey::RSA.new File.read(path), passphrase - - assert_equal key.to_pem, key_from_file.to_pem - end - - def test_class_write_encrypted_cipher - key = @SEC.create_key 1024 - - path = File.join @tempdir, 'test-private_encrypted__with_non_default_cipher_key.pem' - - passphrase = 'It should be long.' - - cipher = OpenSSL::Cipher.new 'AES-192-CBC' - - @SEC.write key, path, 0600, passphrase, cipher - - assert_path_exists path - - key_file_contents = File.read(path) - - assert key_file_contents.split("\n")[2].match(cipher.name) - - key_from_file = OpenSSL::PKey::RSA.new key_file_contents, passphrase - - assert_equal key.to_pem, key_from_file.to_pem - end - -end if defined?(OpenSSL::SSL) +end diff --git a/test/rubygems/test_gem_security_policy.rb b/test/rubygems/test_gem_security_policy.rb index a2115e709a..1ce93fbd95 100644 --- a/test/rubygems/test_gem_security_policy.rb +++ b/test/rubygems/test_gem_security_policy.rb @@ -2,10 +2,6 @@ require 'rubygems/test_case' -unless defined?(OpenSSL::SSL) then - warn 'Skipping Gem::Security::Policy tests. openssl not found.' -end - class TestGemSecurityPolicy < Gem::TestCase ALTERNATE_KEY = load_key 'alternate' @@ -15,7 +11,6 @@ class TestGemSecurityPolicy < Gem::TestCase INVALIDCHILD_KEY = load_key 'invalidchild' ALTERNATE_CERT = load_cert 'alternate' - CA_CERT = load_cert 'ca' CHILD_CERT = load_cert 'child' EXPIRED_CERT = load_cert 'expired' FUTURE_CERT = load_cert 'future' @@ -290,11 +285,6 @@ class TestGemSecurityPolicy < Gem::TestCase "(root of signing cert #{CHILD_CERT.subject})", e.message end - def test_subject - assert_equal 'email:nobody@example', @no.subject(PUBLIC_CERT) - assert_equal '/C=JP/O=JIN.GR.JP/OU=RRR/CN=CA', @no.subject(CA_CERT) - end - def test_verify Gem::Security.trust_dir.trust_cert PUBLIC_CERT @@ -335,33 +325,6 @@ class TestGemSecurityPolicy < Gem::TestCase assert_equal 'missing digest for 0', e.message end - def test_verify_no_signatures - Gem::Security.trust_dir.trust_cert PUBLIC_CERT - - digests, = dummy_signatures - - use_ui @ui do - @no.verify [PUBLIC_CERT], nil, digests, {}, 'some_gem' - end - - assert_match "WARNING: some_gem is not signed\n", @ui.error - - assert_raises Gem::Security::Exception do - @almost_no.verify [PUBLIC_CERT], nil, digests, {} - end - end - - def test_verify_no_signatures_no_digests - Gem::Security.trust_dir.trust_cert PUBLIC_CERT - - use_ui @ui do - @no.verify [PUBLIC_CERT], nil, {}, {}, 'some_gem' - end - - assert_empty @ui.output - assert_empty @ui.error - end - def test_verify_not_enough_signatures Gem::Security.trust_dir.trust_cert PUBLIC_CERT @@ -378,21 +341,6 @@ class TestGemSecurityPolicy < Gem::TestCase assert_equal 'missing digest for 1', e.message end - def test_verify_no_trust - digests, signatures = dummy_signatures - - use_ui @ui do - @low.verify [PUBLIC_CERT], nil, digests, signatures, 'some_gem' - end - - assert_equal "WARNING: email:nobody@example is not trusted for some_gem\n", - @ui.error - - assert_raises Gem::Security::Exception do - @medium.verify [PUBLIC_CERT], nil, digests, signatures - end - end - def test_verify_wrong_digest_type Gem::Security.trust_dir.trust_cert PUBLIC_CERT @@ -536,5 +484,5 @@ class TestGemSecurityPolicy < Gem::TestCase return digests, signatures end -end if defined?(OpenSSL::SSL) +end diff --git a/test/rubygems/test_gem_security_signer.rb b/test/rubygems/test_gem_security_signer.rb index f077a46413..59c5089fec 100644 --- a/test/rubygems/test_gem_security_signer.rb +++ b/test/rubygems/test_gem_security_signer.rb @@ -1,9 +1,5 @@ require 'rubygems/test_case' -unless defined?(OpenSSL::SSL) then - warn 'Skipping Gem::Security::Signer tests. openssl not found.' -end - class TestGemSecuritySigner < Gem::TestCase ALTERNATE_KEY = load_key 'alternate' @@ -76,20 +72,6 @@ class TestGemSecuritySigner < Gem::TestCase assert_equal PRIVATE_KEY.to_s, signer.key.to_s end - def test_initialize_encrypted_key_path - key_file = ENCRYPTED_PRIVATE_KEY_PATH - - signer = Gem::Security::Signer.new key_file, nil, PRIVATE_KEY_PASSPHRASE - - assert_equal ENCRYPTED_PRIVATE_KEY.to_s, signer.key.to_s - end - - def test_extract_name - signer = Gem::Security::Signer.new nil, nil - - assert_equal 'child@example', signer.extract_name(CHILD_CERT) - end - def test_load_cert_chain Gem::Security.trust_dir.trust_cert PUBLIC_CERT @@ -204,5 +186,5 @@ c7NM7KZZjj7G++SXjYTEI1PHSA7aFQ/i/+qSUvx+Pg== end end -end if defined?(OpenSSL::SSL) +end diff --git a/test/rubygems/test_gem_security_trust_dir.rb b/test/rubygems/test_gem_security_trust_dir.rb index 7b0d450bd6..56c2feb44c 100644 --- a/test/rubygems/test_gem_security_trust_dir.rb +++ b/test/rubygems/test_gem_security_trust_dir.rb @@ -1,9 +1,5 @@ require 'rubygems/test_case' -unless defined?(OpenSSL::SSL) then - warn 'Skipping Gem::Security::TrustDir tests. openssl not found.' -end - class TestGemSecurityTrustDir < Gem::TestCase CHILD_CERT = load_cert 'child' @@ -94,5 +90,5 @@ class TestGemSecurityTrustDir < Gem::TestCase assert_equal mask, File.stat(@dest_dir).mode unless win_platform? end -end if defined?(OpenSSL::SSL) +end diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb index cb43121ddd..2629f180a9 100644 --- a/test/rubygems/test_gem_source.rb +++ b/test/rubygems/test_gem_source.rb @@ -63,7 +63,7 @@ class TestGemSource < Gem::TestCase def test_cache_dir_escapes_windows_paths uri = URI.parse("file:///C:/WINDOWS/Temp/gem_repo") - root = Gem.spec_cache_dir + root = File.join Gem.user_home, '.gem', 'specs' cache_dir = @source.cache_dir(uri).gsub(root, '') assert cache_dir !~ /:/, "#{cache_dir} should not contain a :" end @@ -123,7 +123,7 @@ class TestGemSource < Gem::TestCase expected = @released assert_equal expected, @source.load_specs(:released) - cache_dir = File.join Gem.spec_cache_dir, 'gems.example.com%80' + cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80' assert File.exist?(cache_dir), "#{cache_dir} does not exist" cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}" @@ -138,7 +138,7 @@ class TestGemSource < Gem::TestCase @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] = ' ' * Marshal.dump(@latest_specs).length - cache_dir = File.join Gem.spec_cache_dir, 'gems.example.com%80' + cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80' FileUtils.mkdir_p cache_dir @@ -160,7 +160,7 @@ class TestGemSource < Gem::TestCase @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = util_gzip(Marshal.dump(@latest_specs)) - cache_dir = File.join Gem.spec_cache_dir, 'gems.example.com%80' + cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80' FileUtils.mkdir_p cache_dir @@ -184,28 +184,5 @@ class TestGemSource < Gem::TestCase end end - def test_spaceship - remote = @source - specific = Gem::Source::SpecificFile.new(@a1.cache_file) - installed = Gem::Source::Installed.new - local = Gem::Source::Local.new - - assert_equal( 0, remote. <=>(remote), 'remote <=> remote') - - assert_equal(-1, remote. <=>(specific), 'remote <=> specific') - assert_equal( 1, specific. <=>(remote), 'specific <=> remote') - - assert_equal(-1, remote. <=>(local), 'remote <=> local') - assert_equal( 1, local. <=>(remote), 'local <=> remote') - - assert_equal(-1, remote. <=>(installed), 'remote <=> installed') - assert_equal( 1, installed.<=>(remote), 'installed <=> remote') - - no_uri = @source.dup - no_uri.instance_variable_set :@uri, nil - - assert_equal(-1, remote. <=>(no_uri), 'remote <=> no_uri') - end - end diff --git a/test/rubygems/test_gem_source_local.rb b/test/rubygems/test_gem_source_local.rb index b3b444ccde..54ce3d51be 100644 --- a/test/rubygems/test_gem_source_local.rb +++ b/test/rubygems/test_gem_source_local.rb @@ -1,5 +1,5 @@ require 'rubygems/test_case' -require 'rubygems/source/local' +require 'rubygems/source_local' require 'fileutils' @@ -66,41 +66,18 @@ class TestGemSourceLocal < Gem::TestCase assert_equal s, @a end - def test_inspect - assert_equal '#<Gem::Source::Local specs: "NOT LOADED">', @sl.inspect - - @sl.load_specs :released - - inner = [@a, @ap, @b].map { |t| t.name_tuple }.inspect - - assert_equal "#<Gem::Source::Local specs: #{inner}>", @sl.inspect - end - def test_download path = @sl.download @a assert_equal File.expand_path(@a.file_name), path end - def test_spaceship - a1 = quick_gem 'a', '1' - util_build_gem a1 + def test_compare + uri = URI.parse "http://gems.example/foo" + s = Gem::Source.new uri - remote = Gem::Source.new @gem_repo - specific = Gem::Source::SpecificFile.new a1.cache_file - installed = Gem::Source::Installed.new - local = Gem::Source::Local.new - - assert_equal( 0, local. <=>(local), 'local <=> local') - - assert_equal(-1, remote. <=>(local), 'remote <=> local') - assert_equal( 1, local. <=>(remote), 'local <=> remote') - - assert_equal( 1, installed.<=>(local), 'installed <=> local') - assert_equal(-1, local. <=>(installed), 'local <=> installed') - - assert_equal(-1, specific. <=>(local), 'specific <=> local') - assert_equal( 1, local. <=>(specific), 'local <=> specific') + assert_equal(-1, (@sl <=> s)) + assert_equal 1, (s <=> @sl) + assert_equal 0, (@sl <=> @sl) end - end diff --git a/test/rubygems/test_gem_source_specific_file.rb b/test/rubygems/test_gem_source_specific_file.rb index 8ccbe50c91..7ffcf482dc 100644 --- a/test/rubygems/test_gem_source_specific_file.rb +++ b/test/rubygems/test_gem_source_specific_file.rb @@ -1,5 +1,5 @@ require 'rubygems/test_case' -require 'rubygems/source/specific_file' +require 'rubygems/source_specific_file' class TestGemSourceSpecificFile < Gem::TestCase def setup @@ -30,42 +30,4 @@ class TestGemSourceSpecificFile < Gem::TestCase def test_download assert_equal @a_gem, @sf.download(@a) end - - def test_spaceship - a1 = quick_gem 'a', '1' - util_build_gem a1 - - remote = Gem::Source.new @gem_repo - specific = Gem::Source::SpecificFile.new a1.cache_file - installed = Gem::Source::Installed.new - local = Gem::Source::Local.new - - assert_equal( 0, specific. <=>(specific), 'specific <=> specific') - - assert_equal(-1, remote. <=>(specific), 'remote <=> specific') - assert_equal( 1, specific. <=>(remote), 'specific <=> remote') - - assert_equal(-1, specific. <=>(local), 'specific <=> local') - assert_equal( 1, local. <=>(specific), 'local <=> specific') - - assert_equal(-1, specific. <=>(installed), 'specific <=> installed') - assert_equal( 1, installed.<=>(specific), 'installed <=> specific') - - a2 = quick_gem 'a', '2' - util_build_gem a2 - - b1 = quick_gem 'b', '1' - util_build_gem b1 - - a1_source = specific - a2_source = Gem::Source::SpecificFile.new a2.cache_file - b1_source = Gem::Source::SpecificFile.new b1.cache_file - - assert_nil a1_source.<=>(b1_source), 'a1_source <=> b1_source' - - assert_equal(-1, a1_source.<=>(a2_source), 'a1_source <=> a2_source') - assert_equal( 0, a1_source.<=>(a1_source), 'a1_source <=> a1_source') - assert_equal( 1, a2_source.<=>(a1_source), 'a2_source <=> a1_source') - end - end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 8be10a30b9..a821057705 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -168,7 +168,7 @@ class TestGemSpecFetcher < Gem::TestCase specs, _ = @sf.available_specs(:latest) assert_equal [@source], specs.keys - assert_equal @latest_specs, specs[@source] + assert_equal @latest_specs, specs[@source].sort end def test_available_specs_released @@ -176,7 +176,7 @@ class TestGemSpecFetcher < Gem::TestCase assert_equal [@source], specs.keys - assert_equal @released, specs[@source] + assert_equal @released, specs[@source].sort end def test_available_specs_complete @@ -184,9 +184,9 @@ class TestGemSpecFetcher < Gem::TestCase assert_equal [@source], specs.keys - expected = (@prerelease_specs + @released).sort + comp = @prerelease_specs + @released - assert_equal expected, specs[@source] + assert_equal comp.sort, specs[@source].sort end def test_available_specs_complete_handles_no_prerelease @@ -197,9 +197,12 @@ class TestGemSpecFetcher < Gem::TestCase assert_equal [@source], specs.keys - assert_equal @released, specs[@source] + comp = @released + + assert_equal comp.sort, specs[@source].sort end + def test_available_specs_cache specs, _ = @sf.available_specs(:latest) @@ -227,7 +230,7 @@ class TestGemSpecFetcher < Gem::TestCase def test_available_specs_prerelease specs, _ = @sf.available_specs(:prerelease) - assert_equal @prerelease_specs, specs[@source] + assert_equal @prerelease_specs, specs[@source].sort end def test_available_specs_with_bad_source diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index efda6f6f19..9b2ae82fe3 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -38,24 +38,6 @@ Gem::Specification.new do |s| end EOF - def make_spec_c1 - @c1 = quick_spec 'a', '1' do |s| - s.executable = 'exec' - s.extensions << 'ext/a/extconf.rb' - s.test_file = 'test/suite.rb' - s.requirements << 'A working computer' - s.rubyforge_project = 'example' - s.license = 'MIT' - - s.add_dependency 'rake', '> 0.4' - s.add_dependency 'jabber4r', '> 0.0.0' - s.add_dependency 'pqa', ['> 0.4', '<= 0.6'] - - s.mark_version - s.files = %w[lib/code.rb] - end - end - def setup super @@ -67,6 +49,10 @@ end s.rubyforge_project = 'example' s.license = 'MIT' + s.add_dependency 'rake', '> 0.4' + s.add_dependency 'jabber4r', '> 0.0.0' + s.add_dependency 'pqa', ['> 0.4', '<= 0.6'] + s.mark_version s.files = %w[lib/code.rb] end @@ -80,379 +66,6 @@ end load 'rubygems/syck_hack.rb' end - def test_self_activate - foo = util_spec 'foo', '1' - - assert_activate %w[foo-1], foo - 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" - - Gem::Specification.reset - install_specs a1, b1, b2, c1, c2 - - a1.activate - 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 - - a1.activate - 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_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, a2, b1, b2, c1, c2 - - a2.activate - 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_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, d1 - - a1.activate - 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 - - ## - # [A] depends on - # [C] = 1.0 depends on - # [B] = 2.0 - # [B] ~> 1.0 (satisfied by 1.0) - - def test_self_activate_checks_dependencies - a, _ = util_spec 'a', '1.0' - a.add_dependency 'c', '= 1.0' - a.add_dependency 'b', '~> 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 - - expected = "can't satisfy 'b (~> 1.0)', already activated 'b-2.0'" - assert_equal expected, e.message - 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_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 - - ## - # 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 - - 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" - - install_specs a1, b1, b2 - - a1.activate - save_loaded_features do - require "b/c" - end - - assert_equal %w(a-1 b-1), loaded_spec_names - end - - def test_self_activate_via_require_wtf - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0", "d" => "> 0" # this - b1 = new_spec "b", "1", { "c" => ">= 1" }, "lib/b.rb" - b2 = new_spec "b", "2", { "c" => ">= 2" }, "lib/b.rb" # this - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" # this - d1 = new_spec "d", "1", { "c" => "< 2" }, "lib/d.rb" - d2 = new_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this - - install_specs a1, b1, b2, c1, c2, d1, d2 - - a1.activate - - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)", "d (> 0)"], unresolved_names - - require "b" - - e = assert_raises Gem::LoadError do - require "d" - end - - assert_equal "unable to find a version of 'd' to activate", e.message - - assert_equal %w(a-1 b-2 c-2), loaded_spec_names - assert_equal ["d (> 0)"], unresolved_names - end - 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 - - a1.activate - assert_equal %w(a-1 b-1 c-1), loaded_spec_names - end - - def test_self_activate_loaded - foo = util_spec 'foo', '1' - - assert foo.activate - refute foo.activate - 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 - # TODO: move these to specification - - 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' - util_spec 'c', '1.0', 'b' => '~> 1.0' - - a.activate - - 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 - - def test_self_all_equals - a = new_spec "foo", "1", nil, "lib/foo.rb" - - Gem::Specification.all = [a] - - assert_equal a, Gem::Specification.find_inactive_by_path('foo') - end - def test_self_attribute_names expected_value = %w[ authors @@ -836,25 +449,6 @@ dependencies: [] assert_equal %w[a], Gem::Specification.outdated end - def test_self_outdated_and_latest_remotes - util_clear_gems - util_setup_fake_fetcher true - - a4 = quick_gem @a1.name, '4' - util_build_gem a4 - b3 = quick_gem @b2.name, '3' - util_build_gem b3 - util_setup_spec_fetcher @a1, @a2, @a3a, a4, @b2, b3 - - Gem::Specification.remove_spec @a1 - Gem::Specification.remove_spec @a2 - Gem::Specification.remove_spec a4 - Gem::Specification.remove_spec b3 - - assert_equal [[@a3a, a4.version], [@b2, b3.version]], - Gem::Specification.outdated_and_latest_version.to_a - end - DATA_PATH = File.expand_path "../data", __FILE__ def test_handles_private_null_type @@ -1428,60 +1022,19 @@ dependencies: [] assert_equal %w[lib], @a1.require_paths end - def test_require_already_activated - save_loaded_features do - a1 = new_spec "a", "1", nil, "lib/d.rb" - - install_specs a1 # , a2, b1, b2, c1, c2 - - a1.activate - assert_equal %w(a-1), loaded_spec_names - assert_equal [], unresolved_names - - assert require "d" - - assert_equal %w(a-1), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_require_already_activated_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, a2, b1, b2, c1, c2 - - a1.activate - c1.activate - assert_equal %w(a-1 c-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - assert require "d" - - assert_equal %w(a-1 c-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - end - end - def test_requirements assert_equal ['A working computer'], @a1.requirements end def test_runtime_dependencies_legacy - make_spec_c1 # legacy gems don't have a type - @c1.runtime_dependencies.each do |dep| + @a1.runtime_dependencies.each do |dep| dep.instance_variable_set :@type, nil end expected = %w[rake jabber4r pqa] - assert_equal expected, @c1.runtime_dependencies.map { |d| d.name } + assert_equal expected, @a1.runtime_dependencies.map { |d| d.name } end def test_spaceship_name @@ -1535,13 +1088,11 @@ dependencies: [] @a2.add_runtime_dependency 'b', '1' @a2.dependencies.first.instance_variable_set :@type, nil @a2.required_rubygems_version = Gem::Requirement.new '> 0' - @a2.require_paths << "lib/a/ext" ruby_code = @a2.to_ruby expected = <<-SPEC # -*- encoding: utf-8 -*- -# stub: a 2 ruby lib\0lib/a/ext Gem::Specification.new do |s| s.name = "a" @@ -1554,7 +1105,7 @@ Gem::Specification.new do |s| s.email = "[email protected]" s.files = ["lib/code.rb"] s.homepage = "http://example.com" - s.require_paths = ["lib", "lib/a/ext"] + s.require_paths = ["lib"] s.rubygems_version = "#{Gem::VERSION}" s.summary = "this is a summary" @@ -1589,7 +1140,6 @@ end expected = <<-SPEC # -*- encoding: utf-8 -*- -# stub: a 2 ruby lib Gem::Specification.new do |s| s.name = "a" @@ -1629,17 +1179,14 @@ end end def test_to_ruby_fancy - make_spec_c1 - - @c1.platform = Gem::Platform.local - ruby_code = @c1.to_ruby + @a1.platform = Gem::Platform.local + ruby_code = @a1.to_ruby local = Gem::Platform.local expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]" expected = <<-SPEC # -*- encoding: utf-8 -*- -# stub: a 1 #{win_platform? ? "x86-mswin32-60" : "x86-darwin-8"} lib Gem::Specification.new do |s| s.name = "a" @@ -1687,7 +1234,7 @@ end same_spec = eval ruby_code - assert_equal @c1, same_spec + assert_equal @a1, same_spec end def test_to_ruby_legacy @@ -2339,7 +1886,6 @@ end def test_metadata_specs valid_ruby_spec = <<-EOF # -*- encoding: utf-8 -*- -# stub: m 1 ruby lib Gem::Specification.new do |s| s.name = "m" diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index 1739614c67..948318a5e3 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -5,7 +5,6 @@ class TestGemUninstaller < Gem::InstallerTestCase def setup super - common_installer_setup build_rake_in do use_ui ui do @@ -376,19 +375,6 @@ class TestGemUninstaller < Gem::InstallerTestCase assert_equal "Successfully uninstalled q-1.0", lines.shift end - def test_uninstall_doesnt_prompt_and_raises_when_abort_on_dependent_set - quick_gem 'r', '1' do |s| s.add_dependency 'q', '= 1' end - quick_gem 'q', '1' - - un = Gem::Uninstaller.new('q', :abort_on_dependent => true) - ui = Gem::MockGemUi.new("y\n") - - assert_raises Gem::DependencyRemovalException do - use_ui ui do - un.uninstall - end - end - end def test_uninstall_prompt_includes_dep_type quick_gem 'r', '1' do |s| diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index 2ba196e48d..da3b87dbca 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -122,15 +122,6 @@ class TestGemVersion < Gem::TestCase assert_equal "5.2.4", v("5.2.4").to_s end - def test_semver - assert_less_than "1.0.0-alpha", "1.0.0-alpha.1" - assert_less_than "1.0.0-alpha.1", "1.0.0-beta.2" - assert_less_than "1.0.0-beta.2", "1.0.0-beta.11" - assert_less_than "1.0.0-beta.11", "1.0.0-rc.1" - assert_less_than "1.0.0-rc1", "1.0.0" - assert_less_than "1.0.0-1", "1" - end - # Asserts that +version+ is a prerelease. def assert_prerelease version @@ -170,12 +161,6 @@ class TestGemVersion < Gem::TestCase assert second.eql?(first), "#{second} is eql? #{first}" end - def assert_less_than left, right - l = v(left) - r = v(right) - assert l < r, "#{left} not less than #{right}" - end - # Refute the assumption that +version+ is a prerelease. def refute_prerelease version diff --git a/test/rubygems/test_gem_version_option.rb b/test/rubygems/test_gem_version_option.rb index d6035ab800..cbe819c22e 100644 --- a/test/rubygems/test_gem_version_option.rb +++ b/test/rubygems/test_gem_version_option.rb @@ -80,69 +80,7 @@ class TestGemVersionOption < Gem::TestCase @cmd.handle_options %w[--version >1] - expected = { - :args => [], - :explicit_prerelease => false, - :prerelease => false, - :version => Gem::Requirement.new('> 1'), - } - - assert_equal expected, @cmd.options - end - - def test_version_option_compound - @cmd.add_version_option - - @cmd.handle_options ['--version', '< 1, > 0.9'] - - expected = { - :args => [], - :explicit_prerelease => false, - :prerelease => false, - :version => Gem::Requirement.new('< 1', '> 0.9'), - } - - assert_equal expected, @cmd.options - end - - def test_version_option_explicit_prerelease - @cmd.add_prerelease_option - @cmd.add_version_option - - @cmd.handle_options %w[--pre --version >1] - - expected = { - :args => [], - :explicit_prerelease => true, - :prerelease => true, - :version => Gem::Requirement.new('> 1'), - } - - assert_equal expected, @cmd.options - end - - def test_version_option_twice - @cmd.add_version_option - - @cmd.handle_options %w[--version >1.a] - - expected = { - :args => [], - :explicit_prerelease => false, - :prerelease => true, - :version => Gem::Requirement.new('> 1.a'), - } - - assert_equal expected, @cmd.options - - @cmd.handle_options %w[--version >1] - - expected = { - :args => [], - :explicit_prerelease => false, - :prerelease => false, - :version => Gem::Requirement.new('> 1'), - } + expected = { :version => Gem::Requirement.new('> 1'), :args => [] } assert_equal expected, @cmd.options end |