summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-30 23:27:52 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-30 23:27:52 +0000
commit73fc703f7cbb2e6dfd50897d26b37fe8e76064e3 (patch)
tree0296426c8ac01331f2d33dde54fd9f1e183ea974 /test
parent6727297dfecddaef6b1166a7f442db2a22929c65 (diff)
* lib/rubygems: Update to RubyGems master 66e5c39. Notable changes:
Implement gem.deps.rb (Gemfile) .lock support Fixed `gem uninstall` for a relative directory in GEM_HOME. * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem_request_set.rb74
-rw-r--r--test/rubygems/test_gem_request_set_lockfile.rb26
-rw-r--r--test/rubygems/test_gem_resolver_git_set.rb28
-rw-r--r--test/rubygems/test_gem_resolver_git_specification.rb34
-rw-r--r--test/rubygems/test_gem_resolver_lock_set.rb7
-rw-r--r--test/rubygems/test_gem_source_git.rb39
-rw-r--r--test/rubygems/test_gem_source_lock.rb107
-rw-r--r--test/rubygems/test_gem_specification.rb14
-rw-r--r--test/rubygems/test_gem_validator.rb9
9 files changed, 334 insertions, 4 deletions
diff --git a/test/rubygems/test_gem_request_set.rb b/test/rubygems/test_gem_request_set.rb
index 6719be372c..324d0cd7a8 100644
--- a/test/rubygems/test_gem_request_set.rb
+++ b/test/rubygems/test_gem_request_set.rb
@@ -45,16 +45,88 @@ class TestGemRequestSet < Gem::TestCase
rs = Gem::RequestSet.new
installed = []
+ open 'gem.deps.rb', 'w' do |io|
+ io.puts 'gem "a"'
+ io.flush
+
+ result = rs.install_from_gemdeps :gemdeps => io.path do |req, installer|
+ installed << req.full_name
+ end
+
+ assert_kind_of Array, result # what is supposed to be in here?
+ end
+
+ assert_includes installed, 'a-2'
+ assert_path_exists File.join @gemhome, 'gems', 'a-2'
+ assert_path_exists 'gem.deps.rb.lock'
+ end
+
+ def test_install_from_gemdeps_install_dir
+ spec_fetcher do |fetcher|
+ fetcher.gem 'a', 2
+ end
+
+ util_clear_gems
+ refute_path_exists File.join Gem.dir, 'gems', 'a-2'
+
+ rs = Gem::RequestSet.new
+ installed = []
+
Tempfile.open 'gem.deps.rb' do |io|
io.puts 'gem "a"'
io.flush
- rs.install_from_gemdeps :gemdeps => io.path do |req, installer|
+ options = {
+ :gemdeps => io.path,
+ :install_dir => "#{@gemhome}2",
+ }
+
+ rs.install_from_gemdeps options do |req, installer|
installed << req.full_name
end
end
assert_includes installed, 'a-2'
+ refute_path_exists File.join Gem.dir, 'gems', 'a-2'
+ end
+
+ def test_install_from_gemdeps_lockfile
+ spec_fetcher do |fetcher|
+ fetcher.gem 'a', 1
+ fetcher.gem 'a', 2
+ fetcher.gem 'b', 1, 'a' => '>= 0'
+ end
+
+ rs = Gem::RequestSet.new
+ installed = []
+
+ open 'gem.deps.rb.lock', 'w' do |io|
+ io.puts <<-LOCKFILE
+GEM
+ remote: #{@gem_repo}
+ specs:
+ a (1)
+ b (1)
+ a
+
+PLATFORMS
+ #{Gem::Platform::RUBY}
+
+DEPENDENCIES
+ b
+ LOCKFILE
+ end
+
+ open 'gem.deps.rb', 'w' do |io|
+ io.puts 'gem "b"'
+ end
+
+ rs.install_from_gemdeps :gemdeps => 'gem.deps.rb' do |req, installer|
+ installed << req.full_name
+ end
+
+ assert_includes installed, 'b-1'
+ assert_includes installed, 'a-1'
end
def test_load_gemdeps
diff --git a/test/rubygems/test_gem_request_set_lockfile.rb b/test/rubygems/test_gem_request_set_lockfile.rb
index fcd4ecfaf7..18c44144fa 100644
--- a/test/rubygems/test_gem_request_set_lockfile.rb
+++ b/test/rubygems/test_gem_request_set_lockfile.rb
@@ -104,6 +104,16 @@ DEPENDENCIES
assert_equal %w[a-2], lockfile_set.specs.map { |tuple| tuple.full_name }
end
+ def test_parse_missing
+ @lockfile.parse
+
+ lockfile_set = @set.sets.find do |set|
+ Gem::Resolver::LockSet === set
+ end
+
+ refute lockfile_set
+ end
+
def test_peek
@lockfile.instance_variable_set :@tokens, [:token]
@@ -211,6 +221,12 @@ DEPENDENCIES
e.message
end
+ def test_tokenize_missing
+ tokens = @lockfile.tokenize
+
+ assert_empty tokens
+ end
+
def test_to_s_gem
spec_fetcher do |fetcher|
fetcher.spec 'a', 2
@@ -400,5 +416,15 @@ DEPENDENCIES
assert_equal :token, @lockfile.get
end
+ def test_write
+ @lockfile.write
+
+ gem_deps_lock_file = "#{@gem_deps_file}.lock"
+
+ assert_path_exists gem_deps_lock_file
+
+ refute_empty File.read gem_deps_lock_file
+ end
+
end
diff --git a/test/rubygems/test_gem_resolver_git_set.rb b/test/rubygems/test_gem_resolver_git_set.rb
index 1ca12a7251..b1a8d838bb 100644
--- a/test/rubygems/test_gem_resolver_git_set.rb
+++ b/test/rubygems/test_gem_resolver_git_set.rb
@@ -52,6 +52,14 @@ class TestGemResolverGitSet < Gem::TestCase
assert_equal [@set.specs['a']], found
end
+ def test_root_dir
+ assert_equal Gem.dir, @set.root_dir
+
+ @set.root_dir = "#{@gemhome}2"
+
+ assert_equal "#{@gemhome}2", @set.root_dir
+ end
+
def test_prefetch
name, _, repository, = git_gem
@@ -98,5 +106,25 @@ class TestGemResolverGitSet < Gem::TestCase
refute_empty @set.specs, 'the git source does not filter'
end
+ def test_prefetch_root_dir
+ name, _, repository, = git_gem
+
+ @set.add_git_gem name, repository, 'master', false
+
+ dependency = dep name
+ req = Gem::Resolver::ActivationRequest.new dependency, nil
+ @reqs.add req
+
+ @set.root_dir = "#{@gemhome}2"
+
+ @set.prefetch @reqs
+
+ refute_empty @set.specs
+
+ spec = @set.specs.values.first
+
+ assert_equal "#{@gemhome}2", spec.source.root_dir
+ end
+
end
diff --git a/test/rubygems/test_gem_resolver_git_specification.rb b/test/rubygems/test_gem_resolver_git_specification.rb
index d724106f08..b0163bc782 100644
--- a/test/rubygems/test_gem_resolver_git_specification.rb
+++ b/test/rubygems/test_gem_resolver_git_specification.rb
@@ -46,5 +46,39 @@ class TestGemResolverGitSpecification < Gem::TestCase
assert called
end
+ # functional test for Gem::Ext::Builder
+
+ def test_install_extension
+ name, _, repository, = git_gem 'a', 1 do |s|
+ s.extensions << 'ext/extconf.rb'
+ end
+
+ Dir.chdir 'git/a' do
+ FileUtils.mkdir_p 'ext/lib'
+
+ open 'ext/extconf.rb', 'w' do |io|
+ io.puts 'require "mkmf"'
+ io.puts 'create_makefile "a"'
+ end
+
+ FileUtils.touch 'ext/lib/b.rb'
+
+ system @git, 'add', 'ext/extconf.rb'
+ system @git, 'add', 'ext/lib/b.rb'
+
+ system @git, 'commit', '--quiet', '-m', 'Add extension files'
+ end
+
+ source = Gem::Source::Git.new name, repository, 'master', true
+
+ spec = source.specs.first
+
+ git_spec = Gem::Resolver::GitSpecification.new @set, spec, source
+
+ git_spec.install({})
+
+ assert_path_exists File.join git_spec.spec.extension_install_dir, 'b.rb'
+ end
+
end
diff --git a/test/rubygems/test_gem_resolver_lock_set.rb b/test/rubygems/test_gem_resolver_lock_set.rb
index 71b28efd4f..6d904fbaee 100644
--- a/test/rubygems/test_gem_resolver_lock_set.rb
+++ b/test/rubygems/test_gem_resolver_lock_set.rb
@@ -5,7 +5,8 @@ class TestGemResolverLockSet < Gem::TestCase
def setup
super
- @source = Gem::Source.new @gem_repo
+ @source = Gem::Source.new @gem_repo
+ @lock_source = Gem::Source::Lock.new @source
@set = Gem::Resolver::LockSet.new @source
end
@@ -21,7 +22,7 @@ class TestGemResolverLockSet < Gem::TestCase
assert_equal 'a', spec.name
assert_equal v(2), spec.version
assert_equal Gem::Platform::RUBY, spec.platform
- assert_equal @source, spec.source
+ assert_equal @lock_source, spec.source
end
def test_find_all
@@ -41,7 +42,7 @@ class TestGemResolverLockSet < Gem::TestCase
version = v(2)
@set.add 'a', version, Gem::Platform::RUBY
- loaded = @set.load_spec 'a', version, Gem::Platform::RUBY, @source
+ loaded = @set.load_spec 'a', version, Gem::Platform::RUBY, nil
assert_kind_of Gem::Specification, loaded
diff --git a/test/rubygems/test_gem_source_git.rb b/test/rubygems/test_gem_source_git.rb
index 838ae562a7..fc89de474a 100644
--- a/test/rubygems/test_gem_source_git.rb
+++ b/test/rubygems/test_gem_source_git.rb
@@ -13,6 +13,14 @@ class TestGemSourceGit < Gem::TestCase
@source = Gem::Source::Git.new @name, @repository, 'master', false
end
+ def test_base_dir
+ assert_equal File.join(Gem.dir, 'bundler'), @source.base_dir
+
+ @source.root_dir = "#{@gemhome}2"
+
+ assert_equal File.join("#{@gemhome}2", 'bundler'), @source.base_dir
+ end
+
def test_checkout
@source.checkout
@@ -96,6 +104,13 @@ class TestGemSourceGit < Gem::TestCase
File.join Gem.dir, 'cache', 'bundler', 'git', "a-#{@hash}"
assert_equal expected, @source.repo_cache_dir
+
+ @source.root_dir = "#{@gemhome}2"
+
+ expected =
+ File.join "#{@gemhome}2", 'cache', 'bundler', 'git', "a-#{@hash}"
+
+ assert_equal expected, @source.repo_cache_dir
end
def test_rev_parse
@@ -118,6 +133,14 @@ class TestGemSourceGit < Gem::TestCase
refute_equal master_head, source.rev_parse
end
+ def test_root_dir
+ assert_equal Gem.dir, @source.root_dir
+
+ @source.root_dir = "#{@gemhome}2"
+
+ assert_equal "#{@gemhome}2", @source.root_dir
+ end
+
def test_spaceship
git = Gem::Source::Git.new 'a', 'git/a', 'master', false
remote = Gem::Source.new @gem_repo
@@ -165,11 +188,27 @@ class TestGemSourceGit < Gem::TestCase
a_spec = specs.shift
+ base_dir = File.dirname File.dirname source.install_dir
+
assert_equal source.install_dir, a_spec.full_gem_path
+ assert_equal File.join(source.install_dir, 'a.gemspec'), a_spec.loaded_from
+ assert_equal base_dir, a_spec.base_dir
+
+ extension_install_dir =
+ File.join Gem.dir, 'bundler', 'extensions',
+ Gem::Platform.local.to_s, Gem.extension_api_version,
+ "a-#{source.dir_shortref}"
+
+ assert_equal extension_install_dir, a_spec.extension_install_dir
b_spec = specs.shift
assert_equal File.join(source.install_dir, 'b'), b_spec.full_gem_path
+ assert_equal File.join(source.install_dir, 'b', 'b.gemspec'),
+ b_spec.loaded_from
+ assert_equal base_dir, b_spec.base_dir
+
+ assert_equal extension_install_dir, b_spec.extension_install_dir
end
def test_uri_hash
diff --git a/test/rubygems/test_gem_source_lock.rb b/test/rubygems/test_gem_source_lock.rb
new file mode 100644
index 0000000000..d114dccbb7
--- /dev/null
+++ b/test/rubygems/test_gem_source_lock.rb
@@ -0,0 +1,107 @@
+require 'rubygems/test_case'
+
+class TestGemSourceLock < Gem::TestCase
+
+ def test_fetch_spec
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ end
+
+ name_tuple = Gem::NameTuple.new 'a', v(1), 'ruby'
+
+ remote = Gem::Source.new @gem_repo
+ lock = Gem::Source::Lock.new remote
+
+ spec = lock.fetch_spec name_tuple
+
+ assert_equal 'a-1', spec.full_name
+ end
+
+ def test_equals2
+ git = Gem::Source::Git.new 'a', 'git/a', 'master', false
+ g_lock = Gem::Source::Lock.new git
+
+ installed = Gem::Source::Installed.new
+ i_lock = Gem::Source::Lock.new installed
+
+ assert_equal g_lock, g_lock
+ refute_equal g_lock, i_lock
+ refute_equal g_lock, Object.new
+ end
+
+ def test_spaceship
+ git = Gem::Source::Git.new 'a', 'git/a', 'master', false
+ g_lock = Gem::Source::Lock.new git
+
+ installed = Gem::Source::Installed.new
+ i_lock = Gem::Source::Lock.new installed
+
+ vendor = Gem::Source::Vendor.new 'vendor/a'
+ v_lock = Gem::Source::Lock.new vendor
+
+ assert_equal( 0, g_lock.<=>(g_lock), 'g_lock <=> g_lock')
+ assert_equal( 0, i_lock.<=>(i_lock), 'i_lock <=> i_lock')
+ assert_equal( 0, v_lock.<=>(v_lock), 'v_lock <=> v_lock')
+
+ assert_equal(-1, g_lock.<=>(i_lock), 'g_lock <=> i_lock')
+ assert_equal( 1, i_lock.<=>(g_lock), 'i_lock <=> g_lock')
+
+ assert_equal(-1, g_lock.<=>(v_lock), 'g_lock <=> v_lock')
+ assert_equal( 1, v_lock.<=>(g_lock), 'v_lock <=> g_lock')
+
+ assert_equal(-1, i_lock.<=>(v_lock), 'i_lock <=> v_lock')
+ assert_equal( 1, v_lock.<=>(i_lock), 'i_lock <=> v_lock')
+ end
+
+ def test_spaceship_git
+ git = Gem::Source::Git.new 'a', 'git/a', 'master', false
+ lock = Gem::Source::Lock.new git
+
+ assert_equal( 1, lock.<=>(git), 'lock <=> git')
+ assert_equal(-1, git .<=>(lock), 'git <=> lock')
+ end
+
+ def test_spaceship_installed
+ installed = Gem::Source::Installed.new
+ lock = Gem::Source::Lock.new installed
+
+ assert_equal( 1, lock. <=>(installed), 'lock <=> installed')
+ assert_equal(-1, installed.<=>(lock), 'installed <=> lock')
+ end
+
+ def test_spaceship_local
+ local = Gem::Source::Local.new
+ lock = Gem::Source::Lock.new local # nonsense
+
+ assert_equal( 1, lock. <=>(local), 'lock <=> local')
+ assert_equal(-1, local.<=>(lock), 'local <=> lock')
+ end
+
+ def test_spaceship_remote
+ remote = Gem::Source.new @gem_repo
+ lock = Gem::Source::Lock.new remote
+
+ assert_equal( 1, lock. <=>(remote), 'lock <=> remote')
+ assert_equal(-1, remote.<=>(lock), 'remote <=> lock')
+ end
+
+ def test_spaceship_specific_file
+ _, gem = util_gem 'a', 1
+
+ specific = Gem::Source::SpecificFile.new gem
+ lock = Gem::Source::Lock.new specific # nonsense
+
+ assert_equal( 1, lock .<=>(specific), 'lock <=> specific')
+ assert_equal(-1, specific.<=>(lock), 'specific <=> lock')
+ end
+
+ def test_spaceship_vendor
+ vendor = Gem::Source::Vendor.new 'vendor/a'
+ lock = Gem::Source::Lock.new vendor
+
+ assert_equal( 1, lock. <=>(vendor), 'lock <=> vendor')
+ assert_equal(-1, vendor.<=>(lock), 'vendor <=> lock')
+ end
+
+end
+
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index b63721270e..76cb12ca58 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -716,6 +716,20 @@ dependencies: []
assert_equal @a2, spec
end
+ def test_self_load_relative
+ open 'a-2.gemspec', 'w' do |io|
+ io.write @a2.to_ruby_for_cache
+ end
+
+ spec = Gem::Specification.load 'a-2.gemspec'
+
+ @a2.files.clear
+
+ assert_equal @a2, spec
+
+ assert_equal File.join(@tempdir, 'a-2.gemspec'), spec.loaded_from
+ end
+
def test_self_load_tainted
full_path = @a2.spec_file
write_file full_path do |io|
diff --git a/test/rubygems/test_gem_validator.rb b/test/rubygems/test_gem_validator.rb
index ab2a9b82a7..4af8b524e1 100644
--- a/test/rubygems/test_gem_validator.rb
+++ b/test/rubygems/test_gem_validator.rb
@@ -32,5 +32,14 @@ class TestGemValidator < Gem::TestCase
assert_equal expected, alien
end
+
+ def test_alien_default
+ new_default_spec 'c', 1, nil, 'lib/c.rb'
+
+ alien = @validator.alien 'c'
+
+ assert_empty alien
+ end
+
end