2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-11-10 12:51:40 -05:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems/request_set'
|
|
|
|
require 'rubygems/request_set/lockfile'
|
|
|
|
|
|
|
|
class TestGemRequestSetLockfile < Gem::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
|
|
|
|
|
|
|
|
util_set_arch 'i686-darwin8.10.1'
|
|
|
|
|
|
|
|
@set = Gem::RequestSet.new
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
@git_set = Gem::Resolver::GitSet.new
|
2013-11-18 19:34:13 -05:00
|
|
|
@vendor_set = Gem::Resolver::VendorSet.new
|
2013-11-10 12:51:40 -05:00
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
@set.instance_variable_set :@git_set, @git_set
|
2013-11-10 12:51:40 -05:00
|
|
|
@set.instance_variable_set :@vendor_set, @vendor_set
|
|
|
|
|
|
|
|
@gem_deps_file = 'gem.deps.rb'
|
2015-02-27 08:00:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def lockfile
|
|
|
|
Gem::RequestSet::Lockfile.build @set, @gem_deps_file
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def write_lockfile(lockfile)
|
2013-11-10 12:51:40 -05:00
|
|
|
@lock_file = File.expand_path "#{@gem_deps_file}.lock"
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open @lock_file, 'w' do |io|
|
2013-11-10 12:51:40 -05:00
|
|
|
io.write lockfile
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_add_DEPENDENCIES
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2 do |s|
|
|
|
|
s.add_development_dependency 'b'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
@set.resolve
|
|
|
|
|
|
|
|
out = []
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
lockfile.add_DEPENDENCIES out
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
'DEPENDENCIES',
|
|
|
|
' a',
|
|
|
|
nil
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, out
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_DEPENDENCIES_from_gem_deps
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2 do |s|
|
|
|
|
s.add_development_dependency 'b'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
dependencies = { 'a' => Gem::Requirement.new('~> 2.0') }
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
@set.resolve
|
|
|
|
@lockfile =
|
|
|
|
Gem::RequestSet::Lockfile.new @set, @gem_deps_file, dependencies
|
|
|
|
|
|
|
|
out = []
|
|
|
|
|
|
|
|
@lockfile.add_DEPENDENCIES out
|
|
|
|
|
|
|
|
expected = [
|
|
|
|
'DEPENDENCIES',
|
|
|
|
' a (~> 2.0)',
|
|
|
|
nil
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, out
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_GEM
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2 do |s|
|
|
|
|
s.add_dependency 'b'
|
|
|
|
s.add_development_dependency 'c'
|
|
|
|
end
|
|
|
|
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
|
|
|
|
fetcher.spec 'bundler', 1
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
@set.gem 'bundler'
|
|
|
|
@set.resolve
|
|
|
|
|
|
|
|
out = []
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
lockfile.add_GEM out, lockfile.spec_groups
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
'GEM',
|
|
|
|
' remote: http://gems.example.com/',
|
|
|
|
' specs:',
|
|
|
|
' a (2)',
|
|
|
|
' b',
|
|
|
|
' b (2)',
|
|
|
|
nil
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, out
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_PLATFORMS
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2 do |s|
|
|
|
|
s.add_dependency 'b'
|
|
|
|
end
|
|
|
|
|
|
|
|
fetcher.spec 'b', 2 do |s|
|
|
|
|
s.platform = Gem::Platform::CURRENT
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
@set.resolve
|
|
|
|
|
|
|
|
out = []
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
lockfile.add_PLATFORMS out
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
expected = [
|
|
|
|
'PLATFORMS',
|
|
|
|
' ruby',
|
|
|
|
' x86-darwin-8',
|
|
|
|
nil
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, out
|
|
|
|
end
|
|
|
|
|
2014-10-01 04:30:21 -04:00
|
|
|
def test_relative_path_from
|
2015-02-27 08:00:45 -05:00
|
|
|
path = lockfile.relative_path_from '/foo', '/foo/bar'
|
2014-10-01 04:30:21 -04:00
|
|
|
|
2014-11-04 07:05:26 -05:00
|
|
|
assert_equal File.expand_path('/foo'), path
|
2014-10-01 04:30:21 -04:00
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
path = lockfile.relative_path_from '/foo', '/foo'
|
2014-10-01 04:30:21 -04:00
|
|
|
|
|
|
|
assert_equal '.', path
|
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def test_to_s_gem
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
GEM
|
|
|
|
remote: #{@gem_repo}
|
|
|
|
specs:
|
|
|
|
a (2)
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform::RUBY}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a
|
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s_gem_dependency
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2, 'c' => '>= 0', 'b' => '>= 0'
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
fetcher.spec 'c', 2
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
GEM
|
|
|
|
remote: #{@gem_repo}
|
|
|
|
specs:
|
|
|
|
a (2)
|
|
|
|
b
|
|
|
|
c
|
|
|
|
b (2)
|
|
|
|
c (2)
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform::RUBY}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a
|
2013-12-07 20:22:39 -05:00
|
|
|
b
|
|
|
|
c
|
2013-11-10 12:51:40 -05:00
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s_gem_dependency_non_default
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2, 'b' => '>= 1'
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'b'
|
|
|
|
@set.gem 'a'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
GEM
|
|
|
|
remote: #{@gem_repo}
|
|
|
|
specs:
|
|
|
|
a (2)
|
|
|
|
b (>= 1)
|
|
|
|
b (2)
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform::RUBY}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a
|
|
|
|
b
|
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s_gem_dependency_requirement
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2, 'b' => '>= 0'
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'a', '>= 1'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
GEM
|
|
|
|
remote: #{@gem_repo}
|
|
|
|
specs:
|
|
|
|
a (2)
|
|
|
|
b
|
|
|
|
b (2)
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform::RUBY}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a (>= 1)
|
2013-12-07 20:22:39 -05:00
|
|
|
b
|
2013-11-10 12:51:40 -05:00
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s_gem_path
|
|
|
|
name, version, directory = vendor_gem
|
|
|
|
|
|
|
|
@vendor_set.add_vendor_gem name, directory
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
PATH
|
|
|
|
remote: #{directory}
|
|
|
|
specs:
|
|
|
|
#{name} (#{version})
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform::RUBY}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a!
|
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s_gem_path_absolute
|
|
|
|
name, version, directory = vendor_gem
|
|
|
|
|
|
|
|
@vendor_set.add_vendor_gem name, File.expand_path(directory)
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
PATH
|
|
|
|
remote: #{directory}
|
|
|
|
specs:
|
|
|
|
#{name} (#{version})
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform::RUBY}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a!
|
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s_gem_platform
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 2 do |spec|
|
|
|
|
spec.platform = Gem::Platform.local
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
GEM
|
|
|
|
remote: #{@gem_repo}
|
|
|
|
specs:
|
|
|
|
a (2-#{Gem::Platform.local})
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform.local}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a
|
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
def test_to_s_gem_source
|
|
|
|
spec_fetcher do |fetcher|
|
2015-07-01 17:50:14 -04:00
|
|
|
fetcher.download 'a', 2
|
2013-12-07 20:22:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
spec_fetcher 'http://other.example/' do |fetcher|
|
2015-07-01 17:50:14 -04:00
|
|
|
fetcher.download 'b', 2
|
2013-12-07 20:22:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
Gem.sources << 'http://other.example/'
|
|
|
|
|
|
|
|
@set.gem 'a'
|
|
|
|
@set.gem 'b'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
GEM
|
|
|
|
remote: #{@gem_repo}
|
|
|
|
specs:
|
|
|
|
a (2)
|
|
|
|
|
|
|
|
GEM
|
|
|
|
remote: http://other.example/
|
|
|
|
specs:
|
|
|
|
b (2)
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
#{Gem::Platform::RUBY}
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a
|
|
|
|
b
|
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-12-07 20:22:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s_git
|
|
|
|
_, _, repository, = git_gem
|
|
|
|
|
|
|
|
head = nil
|
|
|
|
|
|
|
|
Dir.chdir repository do
|
|
|
|
FileUtils.mkdir 'b'
|
|
|
|
|
|
|
|
Dir.chdir 'b' do
|
|
|
|
b = Gem::Specification.new 'b', 1 do |s|
|
|
|
|
s.add_dependency 'a', '~> 1.0'
|
|
|
|
s.add_dependency 'c', '~> 1.0'
|
|
|
|
end
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open 'b.gemspec', 'w' do |io|
|
2013-12-07 20:22:39 -05:00
|
|
|
io.write b.to_ruby
|
|
|
|
end
|
|
|
|
|
|
|
|
system @git, 'add', 'b.gemspec'
|
|
|
|
system @git, 'commit', '--quiet', '-m', 'add b/b.gemspec'
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mkdir 'c'
|
|
|
|
|
|
|
|
Dir.chdir 'c' do
|
|
|
|
c = Gem::Specification.new 'c', 1
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open 'c.gemspec', 'w' do |io|
|
2013-12-07 20:22:39 -05:00
|
|
|
io.write c.to_ruby
|
|
|
|
end
|
|
|
|
|
|
|
|
system @git, 'add', 'c.gemspec'
|
|
|
|
system @git, 'commit', '--quiet', '-m', 'add c/c.gemspec'
|
|
|
|
end
|
|
|
|
|
|
|
|
head = `#{@git} rev-parse HEAD`.strip
|
|
|
|
end
|
|
|
|
|
|
|
|
@git_set.add_git_gem 'a', repository, 'HEAD', true
|
|
|
|
@git_set.add_git_gem 'b', repository, 'HEAD', true
|
|
|
|
@git_set.add_git_gem 'c', repository, 'HEAD', true
|
|
|
|
|
|
|
|
@set.gem 'b'
|
|
|
|
|
|
|
|
expected = <<-LOCKFILE
|
|
|
|
GIT
|
|
|
|
remote: #{repository}
|
|
|
|
revision: #{head}
|
|
|
|
specs:
|
|
|
|
a (1)
|
|
|
|
b (1)
|
|
|
|
a (~> 1.0)
|
|
|
|
c (~> 1.0)
|
|
|
|
c (1)
|
|
|
|
|
|
|
|
PLATFORMS
|
|
|
|
ruby
|
|
|
|
|
|
|
|
DEPENDENCIES
|
|
|
|
a!
|
|
|
|
b!
|
|
|
|
c!
|
|
|
|
LOCKFILE
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
assert_equal expected, lockfile.to_s
|
2013-12-07 20:22:39 -05:00
|
|
|
end
|
|
|
|
|
2013-11-30 18:27:52 -05:00
|
|
|
def test_write
|
2015-02-27 08:00:45 -05:00
|
|
|
lockfile.write
|
2013-11-30 18:27:52 -05:00
|
|
|
|
|
|
|
gem_deps_lock_file = "#{@gem_deps_file}.lock"
|
|
|
|
|
|
|
|
assert_path_exists gem_deps_lock_file
|
|
|
|
|
|
|
|
refute_empty File.read gem_deps_lock_file
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_write_error
|
|
|
|
@set.gem 'nonexistent'
|
|
|
|
|
|
|
|
gem_deps_lock_file = "#{@gem_deps_file}.lock"
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open gem_deps_lock_file, 'w' do |io|
|
2014-09-13 23:30:02 -04:00
|
|
|
io.write 'hello'
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises Gem::UnsatisfiableDependencyError do
|
2015-02-27 08:00:45 -05:00
|
|
|
lockfile.write
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_path_exists gem_deps_lock_file
|
|
|
|
|
|
|
|
assert_equal 'hello', File.read(gem_deps_lock_file)
|
|
|
|
end
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|