diff options
Diffstat (limited to 'test/rubygems/test_gem_resolver.rb')
-rw-r--r-- | test/rubygems/test_gem_resolver.rb | 156 |
1 files changed, 109 insertions, 47 deletions
diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb index 2271244729..4990d5d2dd 100644 --- a/test/rubygems/test_gem_resolver.rb +++ b/test/rubygems/test_gem_resolver.rb @@ -1,19 +1,14 @@ # frozen_string_literal: true + require_relative "helper" class TestGemResolver < Gem::TestCase - def setup - super - - @DR = Gem::Resolver - end - def make_dep(name, *req) Gem::Dependency.new(name, *req) end def set(*specs) - source = Gem::Source.new URI @gem_repo + source = Gem::Source.new Gem::URI @gem_repo specs = specs.map do |spec| Gem::Resolver::SpecSpecification.new nil, spec, source @@ -25,10 +20,10 @@ class TestGemResolver < Gem::TestCase def assert_resolves_to(expected, resolver) actual = resolver.resolve - exp = expected.sort_by {|s| s.full_name } - act = actual.map {|a| a.spec.spec }.sort_by {|s| s.full_name } + exp = expected.sort_by(&:full_name) + act = actual.map {|a| a.spec.spec }.sort_by(&:full_name) - msg = "Set of gems was not the same: #{exp.map {|x| x.full_name }.inspect} != #{act.map {|x| x.full_name }.inspect}" + msg = "Set of gems was not the same: #{exp.map(&:full_name).inspect} != #{act.map(&:full_name).inspect}" assert_equal exp, act, msg rescue Gem::DependencyResolutionError => e @@ -36,18 +31,18 @@ class TestGemResolver < Gem::TestCase end def test_self_compose_sets_best_set - best_set = @DR::BestSet.new + best_set = Gem::Resolver::BestSet.new - composed = @DR.compose_sets best_set + composed = Gem::Resolver.compose_sets best_set assert_equal best_set, composed end def test_self_compose_sets_multiple - index_set = @DR::IndexSet.new - vendor_set = @DR::VendorSet.new + index_set = Gem::Resolver::IndexSet.new + vendor_set = Gem::Resolver::VendorSet.new - composed = @DR.compose_sets index_set, vendor_set + composed = Gem::Resolver.compose_sets index_set, vendor_set assert_kind_of Gem::Resolver::ComposedSet, composed @@ -55,14 +50,14 @@ class TestGemResolver < Gem::TestCase end def test_self_compose_sets_nest - index_set = @DR::IndexSet.new - vendor_set = @DR::VendorSet.new + index_set = Gem::Resolver::IndexSet.new + vendor_set = Gem::Resolver::VendorSet.new - inner = @DR.compose_sets index_set, vendor_set + inner = Gem::Resolver.compose_sets index_set, vendor_set - current_set = @DR::CurrentSet.new + current_set = Gem::Resolver::CurrentSet.new - composed = @DR.compose_sets inner, current_set + composed = Gem::Resolver.compose_sets inner, current_set assert_kind_of Gem::Resolver::ComposedSet, composed @@ -70,23 +65,23 @@ class TestGemResolver < Gem::TestCase end def test_self_compose_sets_nil - index_set = @DR::IndexSet.new + index_set = Gem::Resolver::IndexSet.new - composed = @DR.compose_sets index_set, nil + composed = Gem::Resolver.compose_sets index_set, nil assert_same index_set, composed e = assert_raise ArgumentError do - @DR.compose_sets nil + Gem::Resolver.compose_sets nil end assert_equal "one set in the composition must be non-nil", e.message end def test_self_compose_sets_single - index_set = @DR::IndexSet.new + index_set = Gem::Resolver::IndexSet.new - composed = @DR.compose_sets index_set + composed = Gem::Resolver.compose_sets index_set assert_same index_set, composed end @@ -104,7 +99,7 @@ class TestGemResolver < Gem::TestCase res.requests a1, act, reqs - assert_equal ["b (= 2)"], reqs.map {|req| req.to_s } + assert_equal ["b (= 2)"], reqs.map(&:to_s) end def test_requests_development @@ -126,7 +121,7 @@ class TestGemResolver < Gem::TestCase res.requests spec, act, reqs - assert_equal ["b (= 2)"], reqs.map {|req| req.to_s } + assert_equal ["b (= 2)"], reqs.map(&:to_s) assert spec.instance_variable_defined? :@called end @@ -207,8 +202,8 @@ class TestGemResolver < Gem::TestCase s.add_development_dependency "b" end - b_spec = util_spec "b", 1 do - |s| s.add_development_dependency "c" + b_spec = util_spec "b", 1 do |s| + s.add_development_dependency "c" end c_spec = util_spec "c", 1 @@ -322,16 +317,15 @@ class TestGemResolver < Gem::TestCase def test_picks_best_platform is = Gem::Resolver::IndexSpecification unknown = Gem::Platform.new "unknown" - a2_p1 = a3_p2 = nil spec_fetcher do |fetcher| fetcher.spec "a", 2 - a2_p1 = fetcher.spec "a", 2 do |s| + fetcher.spec "a", 2 do |s| s.platform = Gem::Platform.local end - a3_p2 = fetcher.spec "a", 3 do |s| + fetcher.spec "a", 3 do |s| s.platform = unknown end end @@ -357,6 +351,74 @@ class TestGemResolver < Gem::TestCase assert_resolves_to [a2_p1.spec], res end + def test_does_not_pick_musl_variants_on_non_musl_linux + util_set_arch "aarch64-linux" do + is = Gem::Resolver::IndexSpecification + + linux_musl = Gem::Platform.new("aarch64-linux-musl") + + spec_fetcher do |fetcher| + fetcher.spec "libv8-node", "15.14.0.1" do |s| + s.platform = Gem::Platform.local + end + + fetcher.spec "libv8-node", "15.14.0.1" do |s| + s.platform = linux_musl + end + end + + v15 = v("15.14.0.1") + source = Gem::Source.new @gem_repo + + s = set + + v15_linux = is.new s, "libv8-node", v15, source, Gem::Platform.local.to_s + v15_linux_musl = is.new s, "libv8-node", v15, source, linux_musl.to_s + + s.add v15_linux + s.add v15_linux_musl + + ad = make_dep "libv8-node", "= 15.14.0.1" + + res = Gem::Resolver.new([ad], s) + + assert_resolves_to [v15_linux.spec], res + end + end + + def test_pick_generic_linux_variants_on_musl_linux + util_set_arch "aarch64-linux-musl" do + is = Gem::Resolver::IndexSpecification + + linux = Gem::Platform.new("aarch64-linux") + + spec_fetcher do |fetcher| + fetcher.spec "libv8-node", "15.14.0.1" do |s| + s.platform = linux + end + + fetcher.spec "libv8-node", "15.14.0.1" + end + + v15 = v("15.14.0.1") + source = Gem::Source.new @gem_repo + + s = set + + v15_ruby = is.new s, "libv8-node", v15, source, Gem::Platform::RUBY + v15_linux = is.new s, "libv8-node", v15, source, linux.to_s + + s.add v15_linux + s.add v15_ruby + + ad = make_dep "libv8-node", "= 15.14.0.1" + + res = Gem::Resolver.new([ad], s) + + assert_resolves_to [v15_linux.spec], res + end + end + def test_only_returns_spec_once a1 = util_spec "a", "1", "c" => "= 1" b1 = util_spec "b", "1", "c" => "= 1" @@ -509,7 +571,7 @@ class TestGemResolver < Gem::TestCase def test_raises_and_reports_an_implicit_request_properly a1 = util_spec "a", "1" do |s| - s.add_runtime_dependency "b", "= 2" + s.add_dependency "b", "= 2" end ad = make_dep "a", "= 1" @@ -711,29 +773,29 @@ class TestGemResolver < Gem::TestCase end def test_sorts_by_source_then_version - sourceA = Gem::Source.new "http://example.com/a" - sourceB = Gem::Source.new "http://example.com/b" - sourceC = Gem::Source.new "http://example.com/c" + source_a = Gem::Source.new "http://example.com/a" + source_b = Gem::Source.new "http://example.com/b" + source_c = Gem::Source.new "http://example.com/c" - spec_A_1 = util_spec "some-dep", "0.0.1" - spec_A_2 = util_spec "some-dep", "1.0.0" - spec_B_1 = util_spec "some-dep", "0.0.1" - spec_B_2 = util_spec "some-dep", "0.0.2" - spec_C_1 = util_spec "some-dep", "0.1.0" + spec_a_1 = util_spec "some-dep", "0.0.1" + spec_a_2 = util_spec "some-dep", "1.0.0" + spec_b_1 = util_spec "some-dep", "0.0.1" + spec_b_2 = util_spec "some-dep", "0.0.2" + spec_c_1 = util_spec "some-dep", "0.1.0" set = StaticSet.new [ - Gem::Resolver::SpecSpecification.new(nil, spec_B_1, sourceB), - Gem::Resolver::SpecSpecification.new(nil, spec_B_2, sourceB), - Gem::Resolver::SpecSpecification.new(nil, spec_C_1, sourceC), - Gem::Resolver::SpecSpecification.new(nil, spec_A_2, sourceA), - Gem::Resolver::SpecSpecification.new(nil, spec_A_1, sourceA), + Gem::Resolver::SpecSpecification.new(nil, spec_b_1, source_b), + Gem::Resolver::SpecSpecification.new(nil, spec_b_2, source_b), + Gem::Resolver::SpecSpecification.new(nil, spec_c_1, source_c), + Gem::Resolver::SpecSpecification.new(nil, spec_a_2, source_a), + Gem::Resolver::SpecSpecification.new(nil, spec_a_1, source_a), ] dependency = make_dep "some-dep", "> 0" resolver = Gem::Resolver.new [dependency], set - assert_resolves_to [spec_B_2], resolver + assert_resolves_to [spec_b_2], resolver end def test_select_local_platforms |