2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative "helper"
|
2013-09-09 20:52:14 -04:00
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
class TestGemResolverInstallerSet < Gem::TestCase
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_add_always_install
|
|
|
|
spec_fetcher do |fetcher|
|
2015-07-01 17:50:14 -04:00
|
|
|
fetcher.download "a", 1
|
|
|
|
fetcher.download "a", 2
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
util_gem "a", 1
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
set.add_always_install dep("a")
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal %w[a-2], set.always_install.map {|s| s.full_name }
|
2014-09-13 23:30:02 -04:00
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::UnsatisfiableDependencyError do
|
2014-09-13 23:30:02 -04:00
|
|
|
set.add_always_install dep("b")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal dep("b"), e.dependency.dependency
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_always_install_errors
|
2018-05-30 09:01:35 -04:00
|
|
|
@stub_fetcher = Gem::FakeFetcher.new
|
|
|
|
Gem::RemoteFetcher.fetcher = @stub_fetcher
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::UnsatisfiableDependencyError do
|
2014-09-13 23:30:02 -04:00
|
|
|
set.add_always_install dep "a"
|
|
|
|
end
|
|
|
|
|
|
|
|
refute_empty e.errors
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_always_install_platform
|
|
|
|
spec_fetcher do |fetcher|
|
2015-07-01 17:50:14 -04:00
|
|
|
fetcher.download "a", 1
|
|
|
|
fetcher.download "a", 2 do |s|
|
2014-09-13 23:30:02 -04:00
|
|
|
s.platform = Gem::Platform.new "x86-freebsd-9"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
set.add_always_install dep("a")
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal %w[a-1], set.always_install.map {|s| s.full_name }
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
2022-08-01 04:54:21 -04:00
|
|
|
def test_add_always_install_index_spec_platform
|
2022-08-04 04:57:15 -04:00
|
|
|
_, a_1_local_gem = util_gem "a", 1 do |s|
|
2022-08-01 04:54:21 -04:00
|
|
|
s.platform = Gem::Platform.local
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.mv a_1_local_gem, @tempdir
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
set.add_always_install dep("a")
|
|
|
|
|
|
|
|
assert_equal [Gem::Platform.local], set.always_install.map {|s| s.platform }
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_add_always_install_prerelease
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.gem "a", 1
|
|
|
|
fetcher.gem "a", "3.a"
|
|
|
|
end
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
set.add_always_install dep("a")
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal %w[a-1], set.always_install.map {|s| s.full_name }
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
2021-08-19 05:47:25 -04:00
|
|
|
def test_add_always_install_prerelease_github_problem
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.gem "a", 1
|
|
|
|
end
|
|
|
|
|
2022-04-28 04:15:43 -04:00
|
|
|
# Github has an issue in which it will generate a misleading prerelease output in its RubyGems server API and
|
2021-08-19 05:47:25 -04:00
|
|
|
# returns a 0 version for the gem while it doesn't exist.
|
|
|
|
@fetcher.data["#{@gem_repo}prerelease_specs.#{Gem.marshal_version}.gz"] = util_gzip(Marshal.dump([
|
|
|
|
Gem::NameTuple.new("a", Gem::Version.new(0), "ruby"),
|
|
|
|
]))
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
set.add_always_install dep("a")
|
|
|
|
|
|
|
|
assert_equal %w[a-1], set.always_install.map {|s| s.full_name }
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_add_always_install_prerelease_only
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.gem "a", "3.a"
|
|
|
|
end
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::UnsatisfiableDependencyError do
|
2014-09-13 23:30:02 -04:00
|
|
|
set.add_always_install dep("a")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_local
|
|
|
|
a_1, a_1_gem = util_gem "a", 1
|
|
|
|
|
|
|
|
a_1_source = Gem::Source::SpecificFile.new a_1_gem
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
set.add_local File.basename(a_1_gem), a_1, a_1_source
|
|
|
|
|
|
|
|
assert set.local? File.basename(a_1_gem)
|
|
|
|
|
|
|
|
FileUtils.rm a_1_gem
|
|
|
|
util_clear_gems
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep("a"), nil
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal %w[a-1], set.find_all(req).map {|spec| spec.full_name }
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
def test_consider_local_eh
|
|
|
|
set = Gem::Resolver::InstallerSet.new :remote
|
|
|
|
|
|
|
|
refute set.consider_local?
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
assert set.consider_local?
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :local
|
|
|
|
|
|
|
|
assert set.consider_local?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_consider_remote_eh
|
|
|
|
set = Gem::Resolver::InstallerSet.new :remote
|
|
|
|
|
|
|
|
assert set.consider_remote?
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
assert set.consider_remote?
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :local
|
|
|
|
|
|
|
|
refute set.consider_remote?
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_errors
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
set.instance_variable_get(:@errors) << :a
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep("a"), nil
|
|
|
|
|
|
|
|
set.find_all req
|
|
|
|
|
|
|
|
assert_equal [:a, set.remote_set.errors.first], set.errors
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_find_all_always_install
|
|
|
|
spec_fetcher do |fetcher|
|
2015-07-01 17:50:14 -04:00
|
|
|
fetcher.download "a", 2
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
util_gem "a", 1
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
set.add_always_install dep "a"
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep("a"), nil
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal %w[a-2], set.find_all(req).map {|spec| spec.full_name }
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_find_all_prerelease
|
|
|
|
spec_fetcher do |fetcher|
|
2015-07-01 17:50:14 -04:00
|
|
|
fetcher.download "a", "1"
|
|
|
|
fetcher.download "a", "1.a"
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep("a"), nil
|
|
|
|
|
2020-06-10 13:46:05 -04:00
|
|
|
assert_equal %w[a-1], set.find_all(req).map {|spec| spec.full_name }
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep("a", ">= 0.a"), nil
|
|
|
|
|
|
|
|
assert_equal %w[a-1 a-1.a],
|
2020-06-10 13:46:05 -04:00
|
|
|
set.find_all(req).map {|spec| spec.full_name }.sort
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
|
|
|
|
2013-09-09 20:52:14 -04:00
|
|
|
def test_load_spec
|
2013-11-11 19:16:41 -05:00
|
|
|
specs = spec_fetcher do |fetcher|
|
2013-11-10 12:51:40 -05:00
|
|
|
fetcher.spec "a", 2
|
2019-02-14 07:59:03 -05:00
|
|
|
fetcher.spec "a", 2 do |s|
|
|
|
|
s.platform = Gem::Platform.local
|
|
|
|
end
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
2013-09-09 20:52:14 -04:00
|
|
|
|
|
|
|
source = Gem::Source.new @gem_repo
|
|
|
|
version = v 2
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
set = Gem::Resolver::InstallerSet.new :remote
|
2013-09-09 20:52:14 -04:00
|
|
|
|
|
|
|
spec = set.load_spec "a", version, Gem::Platform.local, source
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
assert_equal specs["a-2-#{Gem::Platform.local}"].full_name, spec.full_name
|
2013-09-09 20:52:14 -04:00
|
|
|
end
|
|
|
|
|
2014-12-06 19:53:01 -05:00
|
|
|
def test_prefetch
|
|
|
|
set = Gem::Resolver::InstallerSet.new :remote
|
|
|
|
def (set.remote_set).prefetch(_)
|
|
|
|
raise "called"
|
|
|
|
end
|
2022-05-20 04:15:15 -04:00
|
|
|
assert_raise(RuntimeError) { set.prefetch(nil) }
|
2014-12-06 19:53:01 -05:00
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :local
|
|
|
|
def (set.remote_set).prefetch(_)
|
|
|
|
raise "called"
|
|
|
|
end
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_nil set.prefetch(nil)
|
2014-12-06 19:53:01 -05:00
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_prerelease_equals
|
|
|
|
set = Gem::Resolver::InstallerSet.new :remote
|
|
|
|
|
|
|
|
refute set.prerelease
|
|
|
|
refute set.remote_set.prerelease
|
|
|
|
|
|
|
|
set.prerelease = true
|
|
|
|
|
|
|
|
assert set.prerelease
|
|
|
|
assert set.remote_set.prerelease
|
|
|
|
end
|
|
|
|
|
2014-02-03 19:48:31 -05:00
|
|
|
def test_remote_equals_both
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
set.remote = true
|
|
|
|
|
|
|
|
assert set.consider_local?
|
|
|
|
assert set.consider_remote?
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :both
|
|
|
|
set.remote = false
|
|
|
|
|
|
|
|
assert set.consider_local?
|
|
|
|
refute set.consider_remote?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remote_equals_local
|
|
|
|
set = Gem::Resolver::InstallerSet.new :local
|
|
|
|
set.remote = true
|
|
|
|
|
|
|
|
assert set.consider_local?
|
|
|
|
assert set.consider_remote?
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :local
|
|
|
|
set.remote = false
|
|
|
|
|
|
|
|
assert set.consider_local?
|
|
|
|
refute set.consider_remote?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remote_equals_remote
|
|
|
|
set = Gem::Resolver::InstallerSet.new :remote
|
|
|
|
set.remote = true
|
|
|
|
|
|
|
|
refute set.consider_local?
|
|
|
|
assert set.consider_remote?
|
|
|
|
|
|
|
|
set = Gem::Resolver::InstallerSet.new :remote
|
|
|
|
set.remote = false
|
|
|
|
|
|
|
|
refute set.consider_local?
|
|
|
|
refute set.consider_remote?
|
|
|
|
end
|
2013-09-09 20:52:14 -04:00
|
|
|
end
|