2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2013-10-17 21:57:00 -04:00
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
class TestGemResolverVendorSet < Gem::TestCase
|
2013-10-17 21:57:00 -04:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
@set = Gem::Resolver::VendorSet.new
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_vendor_gem
|
|
|
|
name, version, directory = vendor_gem
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
added = @set.add_vendor_gem name, directory
|
2013-10-17 21:57:00 -04:00
|
|
|
|
|
|
|
spec = @set.load_spec name, version, Gem::Platform::RUBY, nil
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
assert_equal spec, added
|
|
|
|
|
2013-10-17 21:57:00 -04:00
|
|
|
assert_equal "#{name}-#{version}", spec.full_name
|
2013-11-25 14:14:49 -05:00
|
|
|
|
|
|
|
assert_equal File.expand_path(directory), spec.full_gem_path
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
|
2013-10-19 20:31:12 -04:00
|
|
|
def test_add_vendor_gem_missing
|
2013-11-10 12:51:40 -05:00
|
|
|
name, _, directory = vendor_gem
|
2013-10-19 20:31:12 -04:00
|
|
|
|
|
|
|
FileUtils.rm_r directory
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::GemNotFoundException do
|
2013-10-19 20:31:12 -04:00
|
|
|
@set.add_vendor_gem name, directory
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "unable to find #{directory}/#{name}.gemspec for gem #{name}",
|
|
|
|
e.message
|
|
|
|
end
|
|
|
|
|
2013-10-17 21:57:00 -04:00
|
|
|
def test_find_all
|
|
|
|
name, version, directory = vendor_gem
|
|
|
|
|
|
|
|
@set.add_vendor_gem name, directory
|
|
|
|
|
|
|
|
dependency = dep 'a', '~> 1'
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
req = Gem::Resolver::DependencyRequest.new dependency, nil
|
2013-10-17 21:57:00 -04:00
|
|
|
|
|
|
|
found = @set.find_all req
|
|
|
|
|
|
|
|
spec = @set.load_spec name, version, Gem::Platform::RUBY, nil
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
source = Gem::Source::Vendor.new directory
|
|
|
|
|
2013-10-17 21:57:00 -04:00
|
|
|
expected = [
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Resolver::VendorSpecification.new(@set, spec, source),
|
2013-10-17 21:57:00 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
assert_equal expected, found
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_find_all_prerelease
|
|
|
|
name, _, directory = vendor_gem 'a', '1.a'
|
|
|
|
|
|
|
|
@set.add_vendor_gem name, directory
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep('a'), nil
|
|
|
|
|
|
|
|
assert_empty @set.find_all req
|
|
|
|
|
|
|
|
req = Gem::Resolver::DependencyRequest.new dep('a', '>= 0.a'), nil
|
|
|
|
|
|
|
|
refute_empty @set.find_all req
|
|
|
|
end
|
|
|
|
|
2013-10-17 21:57:00 -04:00
|
|
|
def test_load_spec
|
2013-11-10 12:51:40 -05:00
|
|
|
error = Object.const_defined?(:KeyError) ? KeyError : IndexError
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise error do
|
2013-12-08 14:32:07 -05:00
|
|
|
@set.load_spec 'b', v(1), Gem::Platform::RUBY, nil
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|