diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-07 08:39:39 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-07 08:39:39 +0000 |
commit | eb807d42eca121df22f72b95465bba52a4e7fefa (patch) | |
tree | 35b722bc6c94d3b9c5f8f80d41e889c591a80450 /test/rubygems/test_gem.rb | |
parent | c414d861c109ff546e2bc8c7264859907d6e0f76 (diff) | |
download | ruby-eb807d42eca121df22f72b95465bba52a4e7fefa.tar.gz |
* gc.c (rb_gc_set_params): allow GC parameter configuration by
environment variables. based on a patch from funny-falcon at
https://gist.github.com/856296, but honors safe level.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem.rb')
-rw-r--r-- | test/rubygems/test_gem.rb | 422 |
1 files changed, 38 insertions, 384 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 98d37a807e..06f25d4775 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -26,352 +26,6 @@ class TestGem < Gem::TestCase util_remove_interrupt_command end - def assert_activate expected, *specs - specs.each do |spec| - case spec - when Array - Gem.activate(*spec) - when String - Gem.activate spec - else - Gem.activate spec.name - end - end - - loaded = Gem.loaded_specs.values.map(&:full_name) - - assert_equal expected.sort, loaded.sort if expected - end - - def test_self_activate - foo = util_spec 'foo', '1' - - assert_activate %w[foo-1], foo - end - - def loaded_spec_names - Gem.loaded_specs.values.map(&:full_name).sort - end - - def unresolved_names - Gem.unresolved_deps.values.map(&:to_s).sort - end - - def test_self_activate_via_require - a1 = new_spec "a", "1", "b" => "= 1" - b1 = new_spec "b", "1", nil, "lib/b/c.rb" - b2 = new_spec "b", "2", nil, "lib/b/c.rb" - - Gem.activate "a", "= 1" - require "b/c" - - assert_equal %w(a-1 b-1), loaded_spec_names - end - - def test_self_activate_deep_unambiguous - a1 = new_spec "a", "1", "b" => "= 1" - b1 = new_spec "b", "1", "c" => "= 1" - b2 = new_spec "b", "2", "c" => "= 2" - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1 b-1 c-1), loaded_spec_names - end - - def save_loaded_features - old_loaded_features = $LOADED_FEATURES.dup - yield - ensure - $LOADED_FEATURES.replace old_loaded_features - end - - def test_self_activate_ambiguous_direct - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec("b", "1", { "c" => ">= 1" }, "lib/d.rb") - b2 = new_spec("b", "2", { "c" => ">= 2" }, "lib/d.rb") - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 b-2 c-2), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_self_activate_ambiguous_indirect - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1", nil, "lib/d.rb" - c2 = new_spec "c", "2", nil, "lib/d.rb" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 b-2 c-2), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_self_activate_ambiguous_unrelated - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1" - c2 = new_spec "c", "2" - d1 = new_spec "d", "1", nil, "lib/d.rb" - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 1" - assert_equal %w(a-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-1 d-1), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - end - end - - def test_self_activate_ambiguous_indirect_conflict - save_loaded_features do - a1 = new_spec "a", "1", "b" => "> 0" - a2 = new_spec "a", "2", "b" => "> 0" - b1 = new_spec "b", "1", "c" => ">= 1" - b2 = new_spec "b", "2", "c" => ">= 2" - c1 = new_spec "c", "1", nil, "lib/d.rb" - c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2 - - install_specs a1, b1, b2, c1, c2 - - Gem.activate "a", "= 2" - assert_equal %w(a-2), loaded_spec_names - assert_equal ["b (> 0)"], unresolved_names - - require "d" - - assert_equal %w(a-2 b-1 c-1), loaded_spec_names - assert_equal [], unresolved_names - end - end - - def test_require_missing - save_loaded_features do - assert_raises ::LoadError do - require "q" - end - end - end - - def test_self_activate_loaded - util_spec 'foo', '1' - - assert Gem.activate 'foo' - refute Gem.activate 'foo' - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] depends on nothing - - def test_self_activate_unrelated - a = util_spec 'a', '1.0', 'b' => '>= 1.0' - util_spec 'b', '1.0' - c = util_spec 'c', '1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 2.0) - # [C] = 1.0 depends on - # [B] ~> 1.0 - # - # and should resolve using b-1.0 - - def test_self_activate_over - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1' - util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '~> 1.0' - - Gem.activate "a" - - assert_equal %w[a-1.0 c-1.0], loaded_spec_names - assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.1) - # [C] = 1.0 depends on - # [B] = 1.0 - # - # and should resolve using b-1.0 - # - # TODO: this is not under, but over... under would require depth - # first resolve through a dependency that is later pruned. - - def test_self_activate_under - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - ## - # [A1] depends on - # [B] > 0 (satisfied by 2.0) - # [B1] depends on - # [C] > 0 (satisfied by 1.0) - # [B2] depends on nothing! - # [C1] depends on nothing - - def test_self_activate_dropped - a1, = util_spec 'a', '1', 'b' => nil - util_spec 'b', '1', 'c' => nil - util_spec 'b', '2' - util_spec 'c', '1' - - assert_activate %w[b-2 a-1], a1, "b" - end - - ## - # [A] depends on - # [B] >= 1.0 (satisfied by 1.1) depends on - # [Z] - # [C] >= 1.0 depends on - # [B] = 1.0 - # - # and should backtrack to resolve using b-1.0, pruning Z from the - # resolve. - - def test_self_activate_raggi_the_edgecase_generator - a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '>= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '1.1', 'z' => '>= 1.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 1.0' - - assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b" - end - - def test_self_activate_conflict - util_spec 'b', '1.0' - util_spec 'b', '2.0' - - gem "b", "= 1.0" - - assert_raises Gem::LoadError do - gem "b", "= 2.0" - end - end - - ## - # [A] depends on - # [B] ~> 1.0 (satisfied by 1.0) - # [C] = 1.0 depends on - # [B] = 2.0 - - def test_self_activate_divergent - a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0' - util_spec 'b', '1.0' - util_spec 'b', '2.0' - c, _ = util_spec 'c', '1.0', 'b' => '= 2.0' - - e = assert_raises Gem::LoadError do - assert_activate nil, a, c, "b" - end - - assert_match(/Unable to activate c-1.0,/, e.message) - assert_match(/because b-1.0 conflicts with b .= 2.0/, e.message) - end - - ## - # DOC - - def test_self_activate_platform_alternate - @x1_m = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @x1_o = util_spec 'x', '1' do |s| - s.platform = Gem::Platform.new %w[cpu other_platform 1] - end - - @w1 = util_spec 'w', '1', 'x' => nil - - util_set_arch 'cpu-my_platform1' - - assert_activate %w[x-1-cpu-my_platform-1 w-1], @w1, @x1_m - end - - ## - # DOC - - def test_self_activate_platform_bump - @y1 = util_spec 'y', '1' - - @y1_1_p = util_spec 'y', '1.1' do |s| - s.platform = Gem::Platform.new %w[cpu my_platform 1] - end - - @z1 = util_spec 'z', '1', 'y' => nil - - assert_activate %w[y-1 z-1], @z1, @y1 - end - - ## - # [C] depends on - # [A] = 1.a - # [B] = 1.0 depends on - # [A] >= 0 (satisfied by 1.a) - - def test_self_activate_prerelease - @c1_pre = util_spec 'c', '1.a', "a" => "1.a", "b" => "1" - @a1_pre = util_spec 'a', '1.a' - @b1 = util_spec 'b', '1' do |s| - s.add_dependency 'a' - s.add_development_dependency 'aa' - end - - assert_activate %w[a-1.a b-1 c-1.a], @c1_pre, @a1_pre, @b1 - end - - ## - # DOC - - def test_self_activate_old_required - e1, = util_spec 'e', '1', 'd' => '= 1' - @d1 = util_spec 'd', '1' - @d2 = util_spec 'd', '2' - - assert_activate %w[d-1 e-1], e1, "d" - end - def test_self_all_load_paths util_make_gems @@ -417,7 +71,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_nonexistent_binfile - quick_spec 'a', '2' do |s| + quick_gem 'a', '2' do |s| s.executables = ['exec'] end assert_raises(Gem::GemNotFoundException) do @@ -426,7 +80,7 @@ class TestGem < Gem::TestCase end def test_self_bin_path_no_bin_file - quick_spec 'a', '1' + quick_gem 'a', '1' assert_raises(Gem::Exception) do Gem.bin_path('a', nil, '1') end @@ -440,7 +94,7 @@ class TestGem < Gem::TestCase def test_self_bin_path_bin_file_gone_in_latest util_exec_gem - quick_spec 'a', '10' do |s| + quick_gem 'a', '10' do |s| s.executables = [] s.default_executable = nil end @@ -496,7 +150,7 @@ class TestGem < Gem::TestCase fp.puts 'blah' end - foo = quick_spec 'foo' do |s| s.files = %w[data/foo.txt] end + foo = quick_gem 'foo' do |s| s.files = %w[data/foo.txt] end install_gem foo end @@ -558,7 +212,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories @gemhome - assert File.directory?(Gem.cache_dir(@gemhome)) + assert File.directory?(File.join(@gemhome, "cache")) end def test_self_ensure_gem_directories_missing_parents @@ -570,7 +224,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - assert File.directory?(Gem.cache_dir(gemdir)) + assert File.directory?("#{gemdir}/cache") end unless win_platform? then # only for FS that support write protection @@ -584,7 +238,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?(Gem.cache_dir(gemdir)) + refute File.exist?("#{gemdir}/cache") ensure FileUtils.chmod 0600, gemdir end @@ -601,7 +255,7 @@ class TestGem < Gem::TestCase Gem.ensure_gem_subdirectories gemdir - refute File.exist?(Gem.cache_dir(gemdir)) + refute File.exist?("#{gemdir}/cache") ensure FileUtils.chmod 0600, parent end @@ -622,8 +276,8 @@ class TestGem < Gem::TestCase def test_self_find_files discover_path = File.join 'lib', 'sff', 'discover.rb' - cwd = File.expand_path("test/rubygems", @@project_dir) - $LOAD_PATH.unshift cwd + cwd = File.expand_path '..', __FILE__ + $LOAD_PATH.unshift cwd.dup foo1 = quick_gem 'sff', '1' do |s| s.files << discover_path @@ -647,7 +301,7 @@ class TestGem < Gem::TestCase Gem.searcher = nil expected = [ - File.expand_path('test/rubygems/sff/discover.rb', @@project_dir), + File.expand_path('../sff/discover.rb', __FILE__), File.join(foo2.full_gem_path, discover_path), File.join(foo1.full_gem_path, discover_path), ] @@ -673,7 +327,7 @@ class TestGem < Gem::TestCase end def test_self_loaded_specs - foo = quick_spec 'foo' + foo = quick_gem 'foo' install_gem foo Gem.source_index = nil @@ -776,12 +430,22 @@ class TestGem < Gem::TestCase end def test_self_prefix - assert_equal @@project_dir, Gem.prefix + file_name = File.expand_path __FILE__ + + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + assert_equal prefix, Gem.prefix end def test_self_prefix_libdir orig_libdir = Gem::ConfigMap[:libdir] - Gem::ConfigMap[:libdir] = @@project_dir + + file_name = File.expand_path __FILE__ + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + Gem::ConfigMap[:libdir] = prefix assert_nil Gem.prefix ensure @@ -790,7 +454,12 @@ class TestGem < Gem::TestCase def test_self_prefix_sitelibdir orig_sitelibdir = Gem::ConfigMap[:sitelibdir] - Gem::ConfigMap[:sitelibdir] = @@project_dir + + file_name = File.expand_path __FILE__ + prefix = File.dirname File.dirname(file_name) + prefix = File.dirname prefix if File.basename(prefix) == 'test' + + Gem::ConfigMap[:sitelibdir] = prefix assert_nil Gem.prefix ensure @@ -954,20 +623,6 @@ class TestGem < Gem::TestCase end end - def test_self_cache_dir - util_ensure_gem_dirs - - assert_equal File.join(@gemhome, 'cache'), Gem.cache_dir - assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache'), Gem.cache_dir(Gem.user_dir) - end - - def test_self_cache_gem - util_ensure_gem_dirs - - assert_equal File.join(@gemhome, 'cache', 'test.gem'), Gem.cache_gem('test.gem') - assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, Gem::ConfigMap[:ruby_version], 'cache', 'test.gem'), Gem.cache_gem('test.gem', Gem.user_dir) - end - if Gem.win_platform? then def test_self_user_home_userprofile skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION @@ -1019,10 +674,10 @@ class TestGem < Gem::TestCase Dir.chdir @tempdir do FileUtils.mkdir_p 'lib' File.open plugin_path, "w" do |fp| - fp.puts "class TestGem; TEST_SPEC_PLUGIN_LOAD = :loaded; end" + fp.puts "TestGem::TEST_SPEC_PLUGIN_LOAD = :loaded" end - foo = quick_spec 'foo', '1' do |s| + foo = quick_gem 'foo', '1' do |s| s.files << plugin_path end @@ -1030,7 +685,6 @@ class TestGem < Gem::TestCase end Gem.source_index = nil - Gem.searcher = nil gem 'foo' @@ -1041,24 +695,23 @@ class TestGem < Gem::TestCase def test_load_env_plugins with_plugin('load') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil + assert_equal :loaded, TEST_PLUGIN_LOAD util_remove_interrupt_command # Should attempt to cause a StandardError with_plugin('standarderror') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_STANDARDERROR rescue nil + assert_equal :loaded, TEST_PLUGIN_STANDARDERROR util_remove_interrupt_command # Should attempt to cause an Exception with_plugin('exception') { Gem.load_env_plugins } - assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil + assert_equal :loaded, TEST_PLUGIN_EXCEPTION end def with_plugin(path) - test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}", - @@project_dir) + test_plugin_path = File.expand_path "../plugin/#{path}", __FILE__ # A single test plugin should get loaded once only, in order to preserve # sane test semantics. @@ -1080,7 +733,7 @@ class TestGem < Gem::TestCase end def util_exec_gem - spec, _ = quick_spec 'a', '4' do |s| + spec, _ = quick_gem 'a', '4' do |s| s.default_executable = 'exec' s.executables = ['exec', 'abin'] end @@ -1124,5 +777,6 @@ class TestGem < Gem::TestCase Gem::Commands.send :remove_const, :InterruptCommand if Gem::Commands.const_defined? :InterruptCommand end + end |