2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-05-31 23:45:05 -04:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
require 'rubygems'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
class TestGemPathSupport < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
ENV["GEM_HOME"] = @tempdir
|
|
|
|
ENV["GEM_PATH"] = [@tempdir, "something"].join(File::PATH_SEPARATOR)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
2016-03-03 19:29:40 -05:00
|
|
|
ps = Gem::PathSupport.new ENV
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
assert_equal ENV["GEM_HOME"], ps.home
|
|
|
|
|
|
|
|
expected = util_path
|
|
|
|
assert_equal expected, ps.path, "defaults to GEM_PATH"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_home
|
2016-03-03 19:29:40 -05:00
|
|
|
ps = Gem::PathSupport.new ENV.to_hash.merge("GEM_HOME" => "#{@tempdir}/foo")
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal File.join(@tempdir, "foo"), ps.home
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
expected = util_path + [File.join(@tempdir, 'foo')]
|
|
|
|
assert_equal expected, ps.path
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
if File::ALT_SEPARATOR
|
2011-07-26 21:40:07 -04:00
|
|
|
def test_initialize_home_normalize
|
|
|
|
alternate = @tempdir.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
|
|
|
|
ps = Gem::PathSupport.new "GEM_HOME" => alternate
|
|
|
|
|
|
|
|
assert_equal @tempdir, ps.home, "normalize values"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_initialize_path
|
2019-06-01 05:45:11 -04:00
|
|
|
Gem.stub(:path_separator, File::PATH_SEPARATOR) do
|
|
|
|
ps = Gem::PathSupport.new ENV.to_hash.merge("GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
assert_equal ENV["GEM_HOME"], ps.home
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
expected = [
|
|
|
|
File.join(@tempdir, 'foo'),
|
|
|
|
File.join(@tempdir, 'bar'),
|
|
|
|
ENV["GEM_HOME"],
|
|
|
|
]
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
assert_equal expected, ps.path
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
def test_initialize_regexp_path_separator
|
|
|
|
Gem.stub(:path_separator, /#{File::PATH_SEPARATOR}/) do
|
|
|
|
path = %W[#{@tempdir}/foo
|
|
|
|
#{File::PATH_SEPARATOR}
|
|
|
|
#{@tempdir}/bar
|
|
|
|
#{File::PATH_SEPARATOR}].join
|
|
|
|
ps = Gem::PathSupport.new "GEM_PATH" => path, "GEM_HOME" => ENV["GEM_HOME"]
|
|
|
|
|
|
|
|
assert_equal ENV["GEM_HOME"], ps.home
|
|
|
|
|
|
|
|
expected = [
|
2018-10-21 20:27:02 -04:00
|
|
|
File.join(@tempdir, 'foo'),
|
|
|
|
File.join(@tempdir, 'bar'),
|
|
|
|
] + Gem.default_path << ENV["GEM_HOME"]
|
2016-03-03 19:29:40 -05:00
|
|
|
|
|
|
|
assert_equal expected, ps.path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_path_with_defaults
|
|
|
|
path = %W[#{@tempdir}/foo
|
|
|
|
#{File::PATH_SEPARATOR}
|
|
|
|
#{@tempdir}/bar
|
|
|
|
#{File::PATH_SEPARATOR}].join
|
|
|
|
ps = Gem::PathSupport.new "GEM_PATH" => path, "GEM_HOME" => ENV["GEM_HOME"]
|
|
|
|
|
|
|
|
assert_equal ENV["GEM_HOME"], ps.home
|
|
|
|
|
|
|
|
expected = [
|
2018-10-21 20:27:02 -04:00
|
|
|
File.join(@tempdir, 'foo'),
|
|
|
|
File.join(@tempdir, 'bar'),
|
|
|
|
] + Gem.default_path << ENV["GEM_HOME"]
|
2016-03-03 19:29:40 -05:00
|
|
|
|
|
|
|
assert_equal expected, ps.path
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_initialize_home_path
|
2019-06-01 05:45:11 -04:00
|
|
|
Gem.stub(:path_separator, File::PATH_SEPARATOR) do
|
|
|
|
ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
|
|
|
|
"GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
assert_equal File.join(@tempdir, "foo"), ps.home
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')]
|
|
|
|
assert_equal expected, ps.path
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def util_path
|
|
|
|
ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
|
|
|
|
end
|
2013-09-14 04:59:02 -04:00
|
|
|
|
|
|
|
def test_initialize_spec
|
|
|
|
ENV["GEM_SPEC_CACHE"] = nil
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
ps = Gem::PathSupport.new ENV
|
2013-09-14 04:59:02 -04:00
|
|
|
assert_equal Gem.default_spec_cache_dir, ps.spec_cache_dir
|
|
|
|
|
|
|
|
ENV["GEM_SPEC_CACHE"] = 'bar'
|
|
|
|
|
2016-03-03 19:29:40 -05:00
|
|
|
ps = Gem::PathSupport.new ENV
|
2013-09-14 04:59:02 -04:00
|
|
|
assert_equal ENV["GEM_SPEC_CACHE"], ps.spec_cache_dir
|
|
|
|
|
|
|
|
ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache'
|
|
|
|
|
|
|
|
ps = Gem::PathSupport.new "GEM_SPEC_CACHE" => "foo"
|
|
|
|
assert_equal "foo", ps.spec_cache_dir
|
|
|
|
end
|
2018-08-27 06:05:04 -04:00
|
|
|
|
|
|
|
def test_gem_paths_do_not_contain_symlinks
|
|
|
|
dir = "#{@tempdir}/realgemdir"
|
|
|
|
symlink = "#{@tempdir}/symdir"
|
|
|
|
Dir.mkdir dir
|
|
|
|
begin
|
|
|
|
File.symlink(dir, symlink)
|
|
|
|
rescue NotImplementedError, SystemCallError
|
|
|
|
skip 'symlinks not supported'
|
|
|
|
end
|
|
|
|
not_existing = "#{@tempdir}/does_not_exist"
|
|
|
|
path = "#{symlink}#{File::PATH_SEPARATOR}#{not_existing}"
|
|
|
|
|
|
|
|
ps = Gem::PathSupport.new "GEM_PATH" => path, "GEM_HOME" => symlink
|
|
|
|
assert_equal dir, ps.home
|
|
|
|
assert_equal [dir, not_existing], ps.path
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|